Skip to content

Commit 5cee69e

Browse files
ref(openai): Separate output handling
1 parent 65e0022 commit 5cee69e

File tree

1 file changed

+64
-4
lines changed

1 file changed

+64
-4
lines changed

sentry_sdk/integrations/openai.py

Lines changed: 64 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ def _set_embeddings_input_data(
462462
_commmon_set_input_data(span, kwargs)
463463

464464

465-
def _set_output_data(
465+
def _common_set_output_data(
466466
span: "Span",
467467
response: "Any",
468468
kwargs: "dict[str, Any]",
@@ -706,11 +706,67 @@ def _new_chat_completion_common(f: "Any", *args: "Any", **kwargs: "Any") -> "Any
706706
start_time = time.perf_counter()
707707
response = yield f, args, kwargs
708708

709-
_set_output_data(span, response, kwargs, integration, start_time, finish_span=True)
709+
_set_completions_api_output_data(
710+
span, response, kwargs, integration, start_time, finish_span=True
711+
)
710712

711713
return response
712714

713715

716+
def _set_completions_api_output_data(
717+
span: "Span",
718+
response: "Any",
719+
kwargs: "dict[str, Any]",
720+
integration: "OpenAIIntegration",
721+
start_time: "Optional[float]" = None,
722+
finish_span: bool = True,
723+
) -> None:
724+
_common_set_output_data(
725+
span,
726+
response,
727+
kwargs,
728+
integration,
729+
start_time,
730+
finish_span,
731+
)
732+
733+
734+
def _set_responses_api_output_data(
735+
span: "Span",
736+
response: "Any",
737+
kwargs: "dict[str, Any]",
738+
integration: "OpenAIIntegration",
739+
start_time: "Optional[float]" = None,
740+
finish_span: bool = True,
741+
) -> None:
742+
_common_set_output_data(
743+
span,
744+
response,
745+
kwargs,
746+
integration,
747+
start_time,
748+
finish_span,
749+
)
750+
751+
752+
def _set_embeddings_output_data(
753+
span: "Span",
754+
response: "Any",
755+
kwargs: "dict[str, Any]",
756+
integration: "OpenAIIntegration",
757+
start_time: "Optional[float]" = None,
758+
finish_span: bool = True,
759+
) -> None:
760+
_common_set_output_data(
761+
span,
762+
response,
763+
kwargs,
764+
integration,
765+
start_time,
766+
finish_span,
767+
)
768+
769+
714770
def _wrap_chat_completion_create(f: "Callable[..., Any]") -> "Callable[..., Any]":
715771
def _execute_sync(f: "Any", *args: "Any", **kwargs: "Any") -> "Any":
716772
gen = _new_chat_completion_common(f, *args, **kwargs)
@@ -795,7 +851,9 @@ def _new_embeddings_create_common(f: "Any", *args: "Any", **kwargs: "Any") -> "A
795851

796852
response = yield f, args, kwargs
797853

798-
_set_output_data(span, response, kwargs, integration, finish_span=False)
854+
_set_embeddings_output_data(
855+
span, response, kwargs, integration, finish_span=False
856+
)
799857

800858
return response
801859

@@ -885,7 +943,9 @@ def _new_responses_create_common(f: "Any", *args: "Any", **kwargs: "Any") -> "An
885943
start_time = time.perf_counter()
886944
response = yield f, args, kwargs
887945

888-
_set_output_data(span, response, kwargs, integration, start_time, finish_span=True)
946+
_set_responses_api_output_data(
947+
span, response, kwargs, integration, start_time, finish_span=True
948+
)
889949

890950
return response
891951

0 commit comments

Comments
 (0)