Add OTel GenAI semantic convention attributes to LLM instrumentations#1619
Conversation
jimilp7
commented
Jan 9, 2026
- Add SpanKind.CLIENT to LLM spans (was INTERNAL)
- Add gen_ai.provider.name attribute ('openai' or 'anthropic')
- Add gen_ai.request.* parameter attributes:
- max_tokens, temperature, top_p, top_k
- stop_sequences, seed, frequency_penalty, presence_penalty
- Add gen_ai.tool.definitions attribute when tools are provided
- Add semconv.py constants file for GenAI semantic conventions
- Update test snapshots for new attributes
- Add SpanKind.CLIENT to LLM spans (was INTERNAL)
- Add gen_ai.provider.name attribute ('openai' or 'anthropic')
- Add gen_ai.request.* parameter attributes:
- max_tokens, temperature, top_p, top_k
- stop_sequences, seed, frequency_penalty, presence_penalty
- Add gen_ai.tool.definitions attribute when tools are provided
- Add semconv.py constants file for GenAI semantic conventions
- Update test snapshots for new attributes
532d296 to
c1dd023
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
76292a5 to
50af26d
Compare
| # Ensure that `{request_data[model]!r}` doesn't raise an error, just a warning about `model` missing. | ||
| json_data = {} | ||
| raw_json_data = {} | ||
| json_data = cast('dict[str, Any]', raw_json_data) |
There was a problem hiding this comment.
is this raw_json_data variable needed just to deal with pyright quirks?
There was a problem hiding this comment.
pyright quirks, please advise
There was a problem hiding this comment.
Pull request overview
This PR adds OpenTelemetry GenAI semantic convention attributes to LLM instrumentations for OpenAI and Anthropic providers. The changes align the implementation with OTel semantic conventions for generative AI operations.
Changes:
- Changed span kind from INTERNAL to CLIENT for all LLM API calls
- Added
gen_ai.provider.nameattribute identifying the LLM provider ('openai' or 'anthropic') - Added request parameter extraction for max_tokens, temperature, top_p, top_k, stop_sequences, seed, frequency_penalty, and presence_penalty
- Added tool definitions tracking when tools/functions are provided to the LLM
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| logfire/_internal/integrations/llm_providers/semconv.py | New file defining GenAI semantic convention constant names |
| logfire/_internal/main.py | Added _span_kind parameter support to span creation methods and LogfireSpan class |
| logfire/_internal/integrations/llm_providers/llm_provider.py | Updated to use SpanKind.CLIENT for all LLM requests |
| logfire/_internal/integrations/llm_providers/openai.py | Added provider name and request parameter extraction for OpenAI endpoints |
| logfire/_internal/integrations/llm_providers/anthropic.py | Added provider name and request parameter extraction for Anthropic endpoints |
| tests/otel_integrations/test_openai.py | Updated test snapshots for new attributes and added parameter extraction tests |
| tests/otel_integrations/test_anthropic.py | Updated test snapshots for new attributes and added parameter extraction tests |
| tests/otel_integrations/test_anthropic_bedrock.py | Updated test snapshots for new attributes |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Add |
7f6be64 to
130c1b6
Compare
130c1b6 to
b34af6b
Compare
|
@alexmojaki added |
|
Thanks! |