Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion scripts/populate_tox/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,11 @@
# affected interpreters.
"py3.10,py3.11": ["filelock>=4.0.3"],
},
"include": "<=1.96", # https://github.com/BerriAI/litellm/issues/36384
"python": {
# litellm 1.97.0-1.100.x is broken on Python 3.10
# (https://github.com/BerriAI/litellm/issues/36384)
">=1.97,<1.101": ">=3.11",
},
},
"litestar": {
"package": "litestar",
Expand Down
13 changes: 13 additions & 0 deletions scripts/populate_tox/package_dependencies.jsonl

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions scripts/populate_tox/releases.jsonl

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions sentry_sdk/integrations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ def iter_default_integrations(

_INTEGRATION_DEACTIVATES = {
"langchain": {"openai", "anthropic", "google_genai"},
"litellm": {"openai"},
"openai_agents": {"openai"},
"pydantic_ai": {"openai", "anthropic"},
}
Expand Down
10 changes: 9 additions & 1 deletion sentry_sdk/integrations/litellm.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ async def _async_success_callback(

def _failure_callback(
kwargs: "Dict[str, Any]",
exception: Exception,
completion_response: "Any",
start_time: "datetime",
end_time: "datetime",
) -> None:
Expand All @@ -320,6 +320,14 @@ def _failure_callback(
if span is None:
return

# LiteLLM calls failure callbacks with the same arguments as success
# callbacks, so the second argument is the (empty) response. The exception
# itself is in kwargs.
exception = kwargs.get("exception")
if not isinstance(exception, BaseException):
span.__exit__(None, None, None)
return

try:
# Capture the exception
event, hint = event_from_exception(
Expand Down
25 changes: 14 additions & 11 deletions tests/integrations/litellm/test_litellm.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def test_nonstreaming_chat_completion(

sentry_sdk.flush()
spans = [item.payload for item in items if item.type == "span"]
assert spans[2]["name"] == "litellm test"
assert spans[1]["name"] == "litellm test"
chat_spans = list(
x
for x in spans
Expand Down Expand Up @@ -417,7 +417,7 @@ async def test_async_nonstreaming_chat_completion(

sentry_sdk.flush()
spans = [item.payload for item in items if item.type == "span"]
assert spans[2]["name"] == "litellm test"
assert spans[1]["name"] == "litellm test"
chat_spans = list(
x
for x in spans
Expand Down Expand Up @@ -1539,6 +1539,7 @@ def test_exception_handling(
# Find the error event
error_events = [e for e in events if e.get("level") == "error"]
assert len(error_events) == 1
assert error_events[0]["exception"]["values"][-1]["mechanism"]["type"] == "litellm"


@pytest.mark.parametrize("span_streaming", [True, False])
Expand Down Expand Up @@ -1605,6 +1606,7 @@ async def test_async_exception_handling(
# Find the error event
error_events = [e for e in events if e.get("level") == "error"]
assert len(error_events) == 1
assert error_events[0]["exception"]["values"][-1]["mechanism"]["type"] == "litellm"


@pytest.mark.parametrize("span_streaming", [True, False])
Expand Down Expand Up @@ -1664,9 +1666,10 @@ def test_span_origin(

sentry_sdk.flush()
spans = [item.payload for item in items]
assert spans[2]["is_segment"] is True
assert spans[2]["attributes"]["sentry.origin"] == "manual"
assert spans[1]["attributes"]["sentry.origin"] == "auto.ai.litellm"
assert len(spans) == 2
assert spans[1]["is_segment"] is True
assert spans[1]["attributes"]["sentry.origin"] == "manual"
assert spans[0]["attributes"]["sentry.origin"] == "auto.ai.litellm"
elif stream_gen_ai_spans:
items = capture_items("transaction", "span")

Expand Down Expand Up @@ -1784,7 +1787,7 @@ def test_multiple_providers(
return_value=anthropic_model_response,
), sentry_sdk.traces.start_span(name="test claude-3-opus-20240229"):
litellm.completion(
model="claude-3-opus-20240229",
model="anthropic/claude-3-opus-20240229",
messages=messages,
client=anthropic_client,
api_key="test-key",
Expand Down Expand Up @@ -1852,7 +1855,7 @@ def test_multiple_providers(
return_value=anthropic_model_response,
), start_transaction(name="test claude-3-opus-20240229"):
litellm.completion(
model="claude-3-opus-20240229",
model="anthropic/claude-3-opus-20240229",
messages=messages,
client=anthropic_client,
api_key="test-key",
Expand Down Expand Up @@ -1921,7 +1924,7 @@ def test_multiple_providers(
return_value=anthropic_model_response,
), start_transaction(name="test claude-3-opus-20240229"):
litellm.completion(
model="claude-3-opus-20240229",
model="anthropic/claude-3-opus-20240229",
messages=messages,
client=anthropic_client,
api_key="test-key",
Expand Down Expand Up @@ -2033,7 +2036,7 @@ async def test_async_multiple_providers(
return_value=anthropic_model_response,
), sentry_sdk.traces.start_span(name="test claude-3-opus-20240229"):
await litellm.acompletion(
model="claude-3-opus-20240229",
model="anthropic/claude-3-opus-20240229",
messages=messages,
client=anthropic_client,
api_key="test-key",
Expand Down Expand Up @@ -2104,7 +2107,7 @@ async def test_async_multiple_providers(
return_value=anthropic_model_response,
), start_transaction(name="test claude-3-opus-20240229"):
await litellm.acompletion(
model="claude-3-opus-20240229",
model="anthropic/claude-3-opus-20240229",
messages=messages,
client=anthropic_client,
api_key="test-key",
Expand Down Expand Up @@ -2176,7 +2179,7 @@ async def test_async_multiple_providers(
return_value=anthropic_model_response,
), start_transaction(name="test claude-3-opus-20240229"):
await litellm.acompletion(
model="claude-3-opus-20240229",
model="anthropic/claude-3-opus-20240229",
messages=messages,
client=anthropic_client,
api_key="test-key",
Expand Down
Loading
Loading