Skip to content

Conversation

@jimilp7
Copy link
Contributor

@jimilp7 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
@jimilp7 jimilp7 force-pushed the add-genai-semconv-attributes branch from 532d296 to c1dd023 Compare January 9, 2026 23:43
@codecov
Copy link

codecov bot commented Jan 9, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

# 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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this raw_json_data variable needed just to deal with pyright quirks?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pyright quirks, please advise

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.name attribute 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.

@alexmojaki
Copy link
Contributor

Add gen_ai.operation.name (just the attribute, not the span name change) here rather than in #1621

@jimilp7 jimilp7 force-pushed the add-genai-semconv-attributes branch from 7f6be64 to 130c1b6 Compare January 12, 2026 22:56
@jimilp7 jimilp7 force-pushed the add-genai-semconv-attributes branch from 130c1b6 to b34af6b Compare January 12, 2026 23:23
@jimilp7
Copy link
Contributor Author

jimilp7 commented Jan 12, 2026

@alexmojaki added gen_ai.operation.name

@jimilp7 jimilp7 requested a review from alexmojaki January 12, 2026 23:25
@alexmojaki
Copy link
Contributor

Thanks!

@alexmojaki alexmojaki merged commit 4f4bcbb into pydantic:main Jan 13, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants