Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
a7758b5
fix(litellm): Avoid double span exits when streaming
alexander-alderman-webb Apr 1, 2026
3f761e9
simplify
alexander-alderman-webb Apr 1, 2026
1f94674
test cleanup
alexander-alderman-webb Apr 1, 2026
c31472c
docs
alexander-alderman-webb Apr 1, 2026
50d0b1f
use underscore
alexander-alderman-webb Apr 2, 2026
edd8a90
test(litellm): Replace mocks with httpx types in nonstreaming tests
alexander-alderman-webb Apr 2, 2026
ec3d128
add fixture
alexander-alderman-webb Apr 2, 2026
a4b9b3a
more mocks
alexander-alderman-webb Apr 7, 2026
9ae99be
update tox
alexander-alderman-webb Apr 7, 2026
99105ca
feat(litellm): Add async callbacks
alexander-alderman-webb Apr 10, 2026
079ff1b
tox files
alexander-alderman-webb Apr 10, 2026
c5b92c8
test(litellm): Remove mocks with httpx types in embedding tests
alexander-alderman-webb Apr 10, 2026
ad16c7f
test(litellm): Replace mocks with httpx types in rate-limit test
alexander-alderman-webb Apr 10, 2026
017f854
add more tests and merge
alexander-alderman-webb Apr 10, 2026
d48c85f
add aembedding
alexander-alderman-webb Apr 10, 2026
ecb9526
fix tests
alexander-alderman-webb Apr 10, 2026
6f3c247
cleanup
alexander-alderman-webb Apr 10, 2026
dda374f
Merge branch 'webb/litellm/remove-mocks' into webb/litellm/embedding-…
alexander-alderman-webb Apr 10, 2026
b622a07
Merge branch 'webb/litellm/embedding-tests' into webb/litellm/error-mock
alexander-alderman-webb Apr 10, 2026
598d6b5
undo merge
alexander-alderman-webb Apr 10, 2026
a7dfb23
.
alexander-alderman-webb Apr 10, 2026
79efa22
merge
alexander-alderman-webb Apr 10, 2026
a8689cd
remove fixture
alexander-alderman-webb Apr 10, 2026
99de614
Merge branch 'webb/litellm/embedding-tests' into webb/litellm/rate-li…
alexander-alderman-webb Apr 10, 2026
c8d86a8
add fixture
alexander-alderman-webb Apr 10, 2026
ecd3718
Merge branch 'master' into webb/litellm/close-spans
alexander-alderman-webb Apr 10, 2026
0536025
re-run tox
alexander-alderman-webb Apr 10, 2026
62c32cb
Merge branch 'master' into webb/litellm/close-spans
alexander-alderman-webb Apr 10, 2026
f352bba
Merge branch 'webb/litellm/close-spans' into webb/litellm/remove-mocks
alexander-alderman-webb Apr 10, 2026
d9cf8b0
Merge branch 'webb/litellm/remove-mocks' into webb/litellm/embedding-…
alexander-alderman-webb Apr 10, 2026
4226d2c
Merge branch 'webb/litellm/embedding-tests' into webb/litellm/rate-li…
alexander-alderman-webb Apr 10, 2026
c5063a0
merge
alexander-alderman-webb Apr 10, 2026
54925ab
patch completions client instead of embeddings
alexander-alderman-webb Apr 10, 2026
a2b3585
make request headers consistent
alexander-alderman-webb Apr 10, 2026
179f14b
Merge branch 'webb/litellm/embedding-tests' into webb/litellm/rate-li…
alexander-alderman-webb Apr 10, 2026
6eb17c9
reset all executor references
alexander-alderman-webb Apr 10, 2026
1b28574
merge
alexander-alderman-webb Apr 10, 2026
ce5ce74
delete span when finished
alexander-alderman-webb Apr 13, 2026
8435f36
safe exit pattern
alexander-alderman-webb Apr 13, 2026
392eb17
Merge branch 'webb/litellm/close-spans' into webb/litellm/remove-mocks
alexander-alderman-webb Apr 13, 2026
6d52689
Merge branch 'webb/litellm/remove-mocks' into webb/litellm/embedding-…
alexander-alderman-webb Apr 13, 2026
9eac0f8
Merge branch 'webb/litellm/embedding-tests' into webb/litellm/rate-li…
alexander-alderman-webb Apr 13, 2026
0b745c9
merge
alexander-alderman-webb Apr 13, 2026
5dc9bbe
update tox.ini again
alexander-alderman-webb Apr 13, 2026
0882066
Merge branch 'master' into webb/litellm/close-spans
alexander-alderman-webb Apr 13, 2026
ee4d55c
tox run
alexander-alderman-webb Apr 13, 2026
d9b9700
Merge branch 'webb/litellm/remove-mocks' into webb/litellm/embedding-…
alexander-alderman-webb Apr 13, 2026
73e9bc1
Merge branch 'webb/litellm/embedding-tests' into webb/litellm/rate-li…
alexander-alderman-webb Apr 13, 2026
6b3cd18
tox run
alexander-alderman-webb Apr 13, 2026
6626a1b
merge master
alexander-alderman-webb Apr 13, 2026
f12b7d3
remove test
alexander-alderman-webb Apr 13, 2026
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
2 changes: 1 addition & 1 deletion scripts/populate_tox/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@
"litellm": {
"package": "litellm",
"deps": {
"*": ["anthropic", "google-genai"],
"*": ["anthropic", "google-genai", "pytest-asyncio"],
},
},
"litestar": {
Expand Down
30 changes: 28 additions & 2 deletions sentry_sdk/integrations/litellm.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
provider = "unknown"

call_type = kwargs.get("call_type", None)
if call_type == "embedding":
if call_type == "embedding" or call_type == "aembedding":
operation = "embeddings"
else:
operation = "chat"
Expand Down Expand Up @@ -160,6 +160,10 @@
set_data_normalized(span, attribute, value)


async def _async_input_callback(kwargs: "Dict[str, Any]") -> None:
return _input_callback(kwargs)

Check warning on line 164 in sentry_sdk/integrations/litellm.py

View check run for this annotation

@sentry/warden / warden: code-review

Duplicate span creation when both sync and async callbacks are registered

Both `_input_callback` and `_async_input_callback` are added to `litellm.input_callback` (lines 334-337 in setup_once), but `_async_input_callback` simply calls `_input_callback` directly. If litellm invokes both callbacks for the same request, `_input_callback` will execute twice, creating duplicate spans for the same operation. This could lead to incorrect tracing data and span leaks since `span.__enter__()` is called multiple times but may not have matching `__exit__()` calls.
Comment thread
alexander-alderman-webb marked this conversation as resolved.


def _success_callback(
kwargs: "Dict[str, Any]",
completion_response: "Any",
Expand Down Expand Up @@ -224,12 +228,30 @@
is_streaming = kwargs.get("stream")
# Callback is fired multiple times when streaming a response.
# Streaming flag checked at https://github.com/BerriAI/litellm/blob/33c3f13443eaf990ac8c6e3da78bddbc2b7d0e7a/litellm/litellm_core_utils/litellm_logging.py#L1603
if is_streaming is not True or "complete_streaming_response" in kwargs:
if (
is_streaming is not True
or "complete_streaming_response" in kwargs
or "async_complete_streaming_response" in kwargs
):
span = metadata.pop("_sentry_span", None)
if span is not None:
span.__exit__(None, None, None)


async def _async_success_callback(
kwargs: "Dict[str, Any]",
completion_response: "Any",
start_time: "datetime",
end_time: "datetime",
) -> None:
return _success_callback(
kwargs,
completion_response,
start_time,
end_time,
)

Check warning on line 252 in sentry_sdk/integrations/litellm.py

View check run for this annotation

@sentry/warden / warden: find-bugs

Missing async failure callback may cause async failures to not be captured

The PR adds `_async_input_callback` and `_async_success_callback` for async litellm operations but does not add a corresponding `_async_failure_callback`. If litellm invokes async callbacks for failure scenarios when using `acompletion()` or `aembedding()`, exceptions may not be properly captured and spans may not be closed. The existing tests `test_async_exception_handling` pass, suggesting the sync callback may still be called, but this creates an inconsistency in the callback registration pattern.


def _failure_callback(
kwargs: "Dict[str, Any]",
exception: Exception,
Expand Down Expand Up @@ -311,10 +333,14 @@
litellm.input_callback = input_callback or []
if _input_callback not in litellm.input_callback:
litellm.input_callback.append(_input_callback)
if _async_input_callback not in litellm.input_callback:
litellm.input_callback.append(_async_input_callback)

litellm.success_callback = success_callback or []
if _success_callback not in litellm.success_callback:
litellm.success_callback.append(_success_callback)
if _async_success_callback not in litellm.success_callback:
litellm.success_callback.append(_async_success_callback)
Comment thread
alexander-alderman-webb marked this conversation as resolved.
Comment thread
alexander-alderman-webb marked this conversation as resolved.

litellm.failure_callback = failure_callback or []
if _failure_callback not in litellm.failure_callback:
Expand Down
Loading
Loading