Skip to content

Commit fcace85

Browse files
OpenAI integration update (#4612)
Update our OpenAI integration to support new APIs (`/responses`) and be OTel and Sentry AI Agents insights module compatible. Contains: - #4563 - #4564 - #4628 --------- Co-authored-by: Ivana Kellyer <[email protected]>
1 parent 19ed1bb commit fcace85

File tree

6 files changed

+943
-228
lines changed

6 files changed

+943
-228
lines changed

sentry_sdk/ai/monitoring.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def sync_wrapped(*args, **kwargs):
4040
for k, v in kwargs.pop("sentry_data", {}).items():
4141
span.set_data(k, v)
4242
if curr_pipeline:
43-
span.set_data(SPANDATA.AI_PIPELINE_NAME, curr_pipeline)
43+
span.set_data(SPANDATA.GEN_AI_PIPELINE_NAME, curr_pipeline)
4444
return f(*args, **kwargs)
4545
else:
4646
_ai_pipeline_name.set(description)
@@ -69,7 +69,7 @@ async def async_wrapped(*args, **kwargs):
6969
for k, v in kwargs.pop("sentry_data", {}).items():
7070
span.set_data(k, v)
7171
if curr_pipeline:
72-
span.set_data(SPANDATA.AI_PIPELINE_NAME, curr_pipeline)
72+
span.set_data(SPANDATA.GEN_AI_PIPELINE_NAME, curr_pipeline)
7373
return await f(*args, **kwargs)
7474
else:
7575
_ai_pipeline_name.set(description)
@@ -108,7 +108,7 @@ def record_token_usage(
108108
# TODO: move pipeline name elsewhere
109109
ai_pipeline_name = get_ai_pipeline_name()
110110
if ai_pipeline_name:
111-
span.set_data(SPANDATA.AI_PIPELINE_NAME, ai_pipeline_name)
111+
span.set_data(SPANDATA.GEN_AI_PIPELINE_NAME, ai_pipeline_name)
112112

113113
if input_tokens is not None:
114114
span.set_data(SPANDATA.GEN_AI_USAGE_INPUT_TOKENS, input_tokens)

sentry_sdk/consts.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ class SPANDATA:
169169
AI_PIPELINE_NAME = "ai.pipeline.name"
170170
"""
171171
Name of the AI pipeline or chain being executed.
172+
DEPRECATED: Use GEN_AI_PIPELINE_NAME instead.
172173
Example: "qa-pipeline"
173174
"""
174175

@@ -229,6 +230,7 @@ class SPANDATA:
229230
AI_STREAMING = "ai.streaming"
230231
"""
231232
Whether or not the AI model call's response was streamed back asynchronously
233+
DEPRECATED: Use GEN_AI_RESPONSE_STREAMING instead.
232234
Example: true
233235
"""
234236

@@ -372,6 +374,24 @@ class SPANDATA:
372374
Example: "chat"
373375
"""
374376

377+
GEN_AI_PIPELINE_NAME = "gen_ai.pipeline.name"
378+
"""
379+
Name of the AI pipeline or chain being executed.
380+
Example: "qa-pipeline"
381+
"""
382+
383+
GEN_AI_RESPONSE_MODEL = "gen_ai.response.model"
384+
"""
385+
Exact model identifier used to generate the response
386+
Example: gpt-4o-mini-2024-07-18
387+
"""
388+
389+
GEN_AI_RESPONSE_STREAMING = "gen_ai.response.streaming"
390+
"""
391+
Whether or not the AI model call's response was streamed back asynchronously
392+
Example: true
393+
"""
394+
375395
GEN_AI_RESPONSE_TEXT = "gen_ai.response.text"
376396
"""
377397
The model's response text messages.
@@ -411,7 +431,7 @@ class SPANDATA:
411431
GEN_AI_REQUEST_MODEL = "gen_ai.request.model"
412432
"""
413433
The model identifier being used for the request.
414-
Example: "gpt-4-turbo-preview"
434+
Example: "gpt-4-turbo"
415435
"""
416436

417437
GEN_AI_REQUEST_PRESENCE_PENALTY = "gen_ai.request.presence_penalty"
@@ -649,9 +669,11 @@ class OP:
649669
FUNCTION_AWS = "function.aws"
650670
FUNCTION_GCP = "function.gcp"
651671
GEN_AI_CHAT = "gen_ai.chat"
672+
GEN_AI_EMBEDDINGS = "gen_ai.embeddings"
652673
GEN_AI_EXECUTE_TOOL = "gen_ai.execute_tool"
653674
GEN_AI_HANDOFF = "gen_ai.handoff"
654675
GEN_AI_INVOKE_AGENT = "gen_ai.invoke_agent"
676+
GEN_AI_RESPONSES = "gen_ai.responses"
655677
GRAPHQL_EXECUTE = "graphql.execute"
656678
GRAPHQL_MUTATION = "graphql.mutation"
657679
GRAPHQL_PARSE = "graphql.parse"
@@ -674,8 +696,6 @@ class OP:
674696
MIDDLEWARE_STARLITE = "middleware.starlite"
675697
MIDDLEWARE_STARLITE_RECEIVE = "middleware.starlite.receive"
676698
MIDDLEWARE_STARLITE_SEND = "middleware.starlite.send"
677-
OPENAI_CHAT_COMPLETIONS_CREATE = "ai.chat_completions.create.openai"
678-
OPENAI_EMBEDDINGS_CREATE = "ai.embeddings.create.openai"
679699
HUGGINGFACE_HUB_CHAT_COMPLETIONS_CREATE = (
680700
"ai.chat_completions.create.huggingface_hub"
681701
)

0 commit comments

Comments
 (0)