🐛 Bug Report: LiteLLM instrumentation never ends the span when a call is interrupted (KeyboardInterrupt, asyncio cancellation)
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 80/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- python
- Ambito
- observability-sre
Direzione di ricerca
Inizia da _wrap_factory e _awrap_factory in opentelemetry/instrumentation/litellm/__init__.py, dove gli span vengono gestiti intorno alle chiamate di completion ed embedding. Riproduci l’interruzione con l’esempio KeyboardInterrupt fornito, quindi aggiungi o aggiorna i test della strumentazione LiteLLM del package per coprire le chiamate sincrone e asincrone interrotte. Done significa che gli span vengono terminati e le interruzioni vengono registrate senza modificare il comportamento dell’eccezione originale.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Which component is this bug for?
Traceloop SDK
📜 Description
Package: opentelemetry-instrumentation-litellm 0.62.4 (not in the component list, so I picked the closest option).
In the LiteLLM instrumentation, _wrap_factory and _awrap_factory (opentelemetry/instrumentation/litellm/__init__.py, lines 681 and 717 at 0.62.4) end the span only in except Exception (via _handle_exception) or after a successful return:
try:
response = wrapped(*args, **kwargs)
except Exception as error:
_handle_exception(span, metrics, error, model, kwargs)
raise
finally:
context_api.detach(token)
KeyboardInterrupt (Ctrl-C) and asyncio.CancelledError (a cancelled task, a timeout via asyncio.wait_for, a client disconnect in a web server) derive from BaseException, not Exception, so the span is never ended and never exported. This affects completion, acompletion, embedding and aembedding. Cancelling LLM calls is common in async servers, so these calls silently disappear from the traces; the open spans also stay referenced.
This is the same pattern as #4576 (other instrumentations), here in the LiteLLM package.
👟 Reproduction steps
pip install litellm opentelemetry-instrumentation-litellm opentelemetry-sdk httpx
import os
os.environ["LITELLM_LOCAL_MODEL_COST_MAP"] = "True"
import httpx, litellm, openai
from opentelemetry.sdk.trace import SpanProcessor, TracerProvider
from opentelemetry.instrumentation.litellm import LiteLLMInstrumentor
class Count(SpanProcessor):
started = ended = 0
def on_start(self, span, parent_context=None): Count.started += 1
def on_end(self, span): Count.ended += 1
provider = TracerProvider()
provider.add_span_processor(Count())
LiteLLMInstrumentor().instrument(tracer_provider=provider)
def respond(request): # local stand-in: the user presses Ctrl-C while waiting for the server
raise KeyboardInterrupt
client = openai.OpenAI(api_key="x", max_retries=0, http_client=httpx.Client(transport=httpx.MockTransport(respond)))
for call in (lambda: litellm.completion(model="openai/gpt-4o-mini", messages=[{"role": "user", "content": "hi"}],
client=client, api_key="x"),
lambda: litellm.embedding(model="openai/text-embedding-3-small", input=["hi"], client=client, api_key="x")):
Count.started = Count.ended = 0
try:
call()
except KeyboardInterrupt:
pass
print("spans started", Count.started, "ended", Count.ended)
👍 Expected behavior
The span ends in every case, with the interruption recorded (e.g. error.type = KeyboardInterrupt / CancelledError, status ERROR), e.g. by catching BaseException in the wrappers (re-raising it unchanged) or ending the span in finally.
👎 Actual Behavior with Screenshots
F plain call interrupted by KeyboardInterrupt
app got: KeyboardInterrupt
spans started 1, ended 0
G embedding interrupted by KeyboardInterrupt
app got: KeyboardInterrupt
spans started 1, ended 0
The OpenInference LiteLLM instrumentation ends the span in the same situation.
🤖 Python Version
3.12
📃 Provide any additional context for the Bug.
opentelemetry-instrumentation-litellm 0.62.4 (the latest release), litellm 1.104.2. The same applies to acompletion / aembedding cancelled with asyncio.CancelledError (same except Exception in _awrap_factory).
👀 Have you spent some time to check if this bug has been raised before?
- I checked and didn't find similar issue
Are you willing to submit PR?
None
- Lingua principale
- Python
- Stelle
- 7.5k
- Fork
- 1.2k
- Merge medio
- 2g 6h
- PR unite (30g)
- 2
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di traceloop/openllmetry
-
bug python
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
traceloop/openllmetry#4717 ·
I maintainer di solito rispondono entro 1 giorno
-
🐛 Bug Report: Incomplete cache token migration after #4243 breaks Bedrock and Groq instrumentationForse già presa @Quantum-Enigma-dot l’ha presa 21 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
traceloop/openllmetry#4665 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
🐛 Bug Report: OpenAI instrumentation drops gen_ai.usage.reasoning_tokens on streamed chat completionsForse già presa @jayfeng7 l’ha presa 23 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
traceloop/openllmetry#4660 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Bug Report: Failed dataset deletes still remove local rows and columnsForse già presa @inchang-ing l’ha presa 32 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
traceloop/openllmetry#4630 ·
I maintainer di solito rispondono entro 1 giorno
-
🐛 Bug Report: LiteLLM instrumentation does not record seed, stop, frequency_penalty, presence_penaltyForse già presa @shantam77 l’ha presa 38 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
traceloop/openllmetry#4598 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di traceloop/openllmetry
Issue simili
-
Internal ErrorApertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
frappe/frappe_docker#2071 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
The-Pocket/PocketFlow#161 ·
-
[Bug]: Webapp workspace fails to render in Safari — "Can't find variable: requestIdleCallback"Apertacomp/desktop P2 type/bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
NousResearch/hermes-agent#157702 ·
I maintainer di solito rispondono entro 1 giorno
-
scibench_physics / scibench_chemistry: a correct answer scores 0 when the unit has a power of tenForse già presa @BahaaMattar l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
EvolvingLMMs-Lab/lmms-eval#1699 ·
I maintainer di solito rispondono entro 1 giorno
-
project_inputs.html uses undefined file variable for dropdown IDs, lacks visual tag badges, and has empty delete labelsForse già presa @Rucha0901 l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
aboutcode-org/scancode.io#2354 ·
I maintainer di solito rispondono entro 1 giorno