-
Notifications
You must be signed in to change notification settings - Fork 943
feat(openai-agents) GenAI semconv compliance #3823
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
max-deygin-traceloop
wants to merge
8
commits into
max/tlp-1925-python-sdk-otel-semantic-convention
from
max/tlp-1928-openai-agents-insturmentation
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3f2418b
fix(semconv): migrating span attributes to OTel gen_ai convention (#3…
max-deygin-traceloop e662ed8
feat(openai-agents): use upstream gen_ai constants directly, rename L…
max-deygin-traceloop cad0974
fix: remove duplicate GEN_AI_OPERATION_NAME dict keys and migrate too…
max-deygin-traceloop 4658ad7
fix(openai-agents): migrate to GEN_AI_INPUT/OUTPUT_MESSAGES, fix brok…
max-deygin-traceloop 93c938e
fix(openai-agents): update recipe hierarchy test to use JSON array me…
max-deygin-traceloop 9cb9332
fix(openai-agents): migrate realtime flat format to JSON arrays, remo…
max-deygin-traceloop 9dba273
chore(openai-agents): update semconv dep to >=0.5.0,<0.6.0
max-deygin-traceloop af07493
fix(openai-agents): restore Speech/Transcription/SpeechGroup handlers…
max-deygin-traceloop File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
296 changes: 103 additions & 193 deletions
296
...metry-instrumentation-openai-agents/opentelemetry/instrumentation/openai_agents/_hooks.py
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
| so we need to patch the RealtimeSession class directly to add OpenTelemetry tracing. | ||
| """ | ||
|
|
||
| import json | ||
| import logging | ||
| import time | ||
| from typing import Dict, Any, Optional, List, Tuple | ||
|
|
@@ -258,7 +259,7 @@ def start_audio_span(self, item_id: str, content_index: int): | |
| kind=SpanKind.CLIENT, | ||
| context=parent_context, | ||
| attributes={ | ||
| SpanAttributes.LLM_REQUEST_TYPE: "realtime", | ||
| GenAIAttributes.GEN_AI_OPERATION_NAME: "realtime", | ||
| GenAIAttributes.GEN_AI_SYSTEM: "openai", | ||
| }, | ||
| ) | ||
|
|
@@ -351,8 +352,7 @@ def create_llm_span(self, completion_content: str): | |
| context=parent_context, | ||
| start_time=start_time, | ||
| attributes={ | ||
| SpanAttributes.LLM_REQUEST_TYPE: "realtime", | ||
| SpanAttributes.LLM_SYSTEM: "openai", | ||
| GenAIAttributes.GEN_AI_OPERATION_NAME: "realtime", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same |
||
| GenAIAttributes.GEN_AI_SYSTEM: "openai", | ||
| GenAIAttributes.GEN_AI_REQUEST_MODEL: model_name_str, | ||
| }, | ||
|
|
@@ -373,21 +373,14 @@ def create_llm_span(self, completion_content: str): | |
|
|
||
| if should_send_prompts(): | ||
| if prompt_content: | ||
| input_messages = [{"role": prompt_role or "user", "content": prompt_content}] | ||
| span.set_attribute( | ||
| f"{GenAIAttributes.GEN_AI_PROMPT}.0.role", prompt_role or "user" | ||
| ) | ||
| span.set_attribute( | ||
| f"{GenAIAttributes.GEN_AI_PROMPT}.0.content", prompt_content | ||
| GenAIAttributes.GEN_AI_INPUT_MESSAGES, json.dumps(input_messages) | ||
| ) | ||
|
|
||
| output_messages = [{"role": "assistant", "content": completion_content, "finish_reason": "stop"}] | ||
| span.set_attribute( | ||
| f"{GenAIAttributes.GEN_AI_COMPLETION}.0.role", "assistant" | ||
| ) | ||
| span.set_attribute( | ||
| f"{GenAIAttributes.GEN_AI_COMPLETION}.0.content", completion_content | ||
| ) | ||
| span.set_attribute( | ||
| f"{GenAIAttributes.GEN_AI_COMPLETION}.0.finish_reason", "stop" | ||
| GenAIAttributes.GEN_AI_OUTPUT_MESSAGES, json.dumps(output_messages) | ||
| ) | ||
|
|
||
| span.set_status(Status(StatusCode.OK)) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
packages/opentelemetry-instrumentation-openai-agents/tests/test_semconv_compliance.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # ruff: noqa: F401, F403 | ||
| """ | ||
| Semconv compliance tests re-used from opentelemetry-semantic-conventions-ai. | ||
|
|
||
| Ensures the installed semconv package has the expected constant values. | ||
| To add more compliance checks, update _testing.py in that package — not here. | ||
| """ | ||
| from opentelemetry.semconv_ai._testing import * |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@max-deygin-traceloop @OzBenSimhonTraceloop we need to set also GEN_AI_SYSTEM
here:
https://github.com/traceloop/openllmetry/pull/3808/changes#r2959993030