-
-
Notifications
You must be signed in to change notification settings - Fork 11.7k
feat(otel): emit the gen_ai.client.operation.exception event on failed LLM calls #32655
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
yucheng-berri
merged 4 commits into
litellm_internal_staging
from
litellm_otel_genai_operation_exception_event
Jul 10, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
b854ca9
feat(otel): emit the gen_ai.client.operation.exception event on faile…
yassin-berriai 0c42fda
fix(otel): always ride the semconv-required exception pair on the Gen…
yassin-berriai b2a475a
docs(otel): document the events plumbing module in the package README
yassin-berriai 2038e77
test(otel): cover the log exporter selection and logs endpoint normal…
yassin-berriai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| """GenAI client events: the ``gen_ai.client.operation.exception`` log event. | ||
|
|
||
| The GenAI semantic conventions define exception recording for client | ||
| operations as a log-based event (severity WARN) carrying the ``exception.*`` | ||
| attribute trio, correlated to the failed span through the trace/span ids — | ||
| not as a span attribute or span event. This module owns building and | ||
| emitting that event; the exporter pipeline it rides is built in | ||
| :mod:`litellm.integrations.otel.plumbing.providers`. | ||
| """ | ||
|
|
||
| from dataclasses import dataclass | ||
|
|
||
| from opentelemetry._events import Event, EventLogger | ||
| from opentelemetry._logs.severity import SeverityNumber | ||
| from opentelemetry.trace import SpanContext | ||
|
|
||
| from litellm.integrations.otel.model.semconv import ExceptionEvent, GenAIEvent | ||
|
|
||
|
|
||
| @dataclass(frozen=True, slots=True) | ||
| class GenAIEventRecorder: | ||
| event_logger: EventLogger | ||
|
|
||
| def record_operation_exception( | ||
| self, | ||
| span_context: SpanContext, | ||
| error_type: str, | ||
| message: str, | ||
| stack_trace: str | None, | ||
| timestamp_ns: int | None, | ||
| ) -> None: | ||
| # ``exception.type`` and ``exception.message`` are the semconv-required | ||
| # pair and always ride the event; only the recommended stacktrace is | ||
| # conditional on the payload carrying one. | ||
| stacktrace = ((ExceptionEvent.STACKTRACE, stack_trace),) if stack_trace else () | ||
| self.event_logger.emit( | ||
| Event( | ||
| name=GenAIEvent.OPERATION_EXCEPTION, | ||
| timestamp=timestamp_ns, | ||
| trace_id=span_context.trace_id, | ||
| span_id=span_context.span_id, | ||
| trace_flags=span_context.trace_flags, | ||
| severity_number=SeverityNumber.WARN, | ||
| attributes=dict( | ||
| ( | ||
| (ExceptionEvent.TYPE, error_type), | ||
| (ExceptionEvent.MESSAGE, message), | ||
| *stacktrace, | ||
| ) | ||
| ), | ||
| ) | ||
| ) | ||
|
greptile-apps[bot] marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.