Skip to content

Commit 1458c76

Browse files
committed
fix(litellm): store current span under litellm_params.metadata
1 parent 1f85e01 commit 1458c76

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

sentry_sdk/integrations/litellm.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ def _get_provider_from_model(model):
5656
return "unknown"
5757

5858

59+
def _get_metadata_dict(kwargs):
60+
# type: (Dict[str, Any]) -> Dict[str, Any]
61+
"""Get the metadata dictionary from the kwargs."""
62+
return kwargs.setdefault("litellm_params", {}).setdefault("metadata", {})
63+
64+
5965
def _input_callback(
6066
kwargs, # type: Dict[str, Any]
6167
):
@@ -84,7 +90,7 @@ def _input_callback(
8490
span.__enter__()
8591

8692
# Store span for later
87-
kwargs["_sentry_span"] = span
93+
_get_metadata_dict(kwargs)["_sentry_span"] = span
8894

8995
# Set basic data
9096
set_data_normalized(span, SPANDATA.GEN_AI_SYSTEM, "litellm")
@@ -134,7 +140,7 @@ def _success_callback(
134140
# type: (...) -> None
135141
"""Handle successful completion."""
136142

137-
span = kwargs.get("_sentry_span")
143+
span = _get_metadata_dict(kwargs).get("_sentry_span")
138144
if span is None:
139145
return
140146

@@ -198,7 +204,7 @@ def _failure_callback(
198204
):
199205
# type: (...) -> None
200206
"""Handle request failure."""
201-
span = kwargs.get("_sentry_span")
207+
span = _get_metadata_dict(kwargs).get("_sentry_span")
202208
if span is None:
203209
return
204210

@@ -240,6 +246,7 @@ class LiteLLMIntegration(Integration):
240246
# Initialize Sentry with the LiteLLM integration
241247
sentry_sdk.init(
242248
dsn="your-dsn",
249+
send_default_pii=True
243250
integrations=[
244251
sentry_sdk.integrations.LiteLLMIntegration(
245252
include_prompts=True # Set to False to exclude message content

0 commit comments

Comments
 (0)