Skip to content

Add semantic convention message attributes to LLM integrations#1705

Merged
dmontagu merged 1 commit intomainfrom
david/semconvs-message
Feb 11, 2026
Merged

Add semantic convention message attributes to LLM integrations#1705
dmontagu merged 1 commit intomainfrom
david/semconvs-message

Conversation

@dmontagu
Copy link
Copy Markdown
Contributor

@dmontagu dmontagu commented Feb 11, 2026

Summary

Supersedes #1666. Clean branch with identical final code, no merge artifacts.

Credit to @brightsparc for the bulk of the implementation.

  • Add gen_ai.input.messages, gen_ai.output.messages, and gen_ai.system_instructions attributes following OpenTelemetry semantic conventions for OpenAI and Anthropic integrations
  • Add version parameter to instrument_openai() and instrument_anthropic() controlling attribute format (1, 'latest', or [1, 'latest'])
  • Convert chat completions, responses API, and text completions to semconv message format with typed parts (text, tool_call, blob, etc.)
  • Default test fixtures to version=[1, 'latest'] for coverage of both code paths
  • Add dedicated version_latest and version_v1_only tests to verify attribute gating works correctly

Test plan

  • All 45 OpenAI/Anthropic/Bedrock tests pass
  • pyright clean (0 errors)
  • Pre-commit hooks pass (ruff, ruff-format, pyright)

Add `gen_ai.input.messages`, `gen_ai.output.messages`, and
`gen_ai.system_instructions` attributes following OpenTelemetry
semantic conventions for OpenAI and Anthropic integrations.

- Add `version` parameter to `instrument_openai()` and
  `instrument_anthropic()` controlling attribute format:
  - `version=1` (default): existing request_data/response_data
  - `version='latest'`: semconv-only attributes
  - `version=[1, 'latest']`: both formats
- Convert chat completions, responses API, and completions to semconv
  message format with proper part types (text, tool_call, blob, etc.)
- Default test fixtures to version=[1, 'latest'] for coverage of both
  code paths
- Add dedicated version_latest and version_v1_only tests to verify
  attribute gating
@cloudflare-workers-and-pages
Copy link
Copy Markdown

Deploying logfire-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 4ab16f8
Status: ✅  Deploy successful!
Preview URL: https://1cf9255a.logfire-docs.pages.dev
Branch Preview URL: https://david-semconvs-message.logfire-docs.pages.dev

View logs

@dmontagu dmontagu enabled auto-merge (squash) February 11, 2026 20:55
@alexmojaki alexmojaki requested review from alexmojaki and Copilot and removed request for alexmojaki February 11, 2026 20:55
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

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

Devin Review found 1 potential issue.

View 7 additional findings in Devin Review.

Open in Devin Review

@dmontagu dmontagu merged commit 8064972 into main Feb 11, 2026
20 checks passed
@dmontagu dmontagu deleted the david/semconvs-message branch February 11, 2026 20:59
Copy link
Copy Markdown
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

Adds OpenTelemetry GenAI semantic convention message attributes to Logfire’s OpenAI and Anthropic (incl. Bedrock) integrations, with a new version knob to control whether spans emit the legacy request_data/response_data format, the semconv format, or both.

Changes:

  • Add version parameter to instrument_openai() / instrument_anthropic() and thread it through endpoint config + response handling.
  • Implement semconv message conversion for OpenAI Chat Completions / Responses API / Completions and Anthropic Messages, including typed “parts”.
  • Update integration tests (and add a VCR cassette) to assert gen_ai.input.messages, gen_ai.output.messages, and gen_ai.system_instructions.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
logfire/_internal/main.py Adds version parameter and passes normalized versions to provider instrumentation via partial().
logfire/_internal/integrations/llm_providers/semconv.py Defines semconv attribute constants, message/part TypedDicts, and normalize_versions().
logfire/_internal/integrations/llm_providers/openai.py Gates attribute emission by version and converts OpenAI request/response payloads into semconv message structures.
logfire/_internal/integrations/llm_providers/anthropic.py Gates attribute emission by version and converts Anthropic messages + responses into semconv message structures.
logfire-api/logfire_api/_internal/main.pyi Updates public type stubs to include the new version parameter.
tests/otel_integrations/test_openai.py Updates existing assertions to include semconv message attributes; adds version_latest / version_v1_only tests and an audio-input test.
tests/otel_integrations/test_anthropic.py Updates assertions for semconv message attributes; adds version_latest / version_v1_only tests.
tests/otel_integrations/test_anthropic_bedrock.py Updates Bedrock Anthropic tests to assert semconv message attributes.
tests/otel_integrations/cassettes/test_openai/test_chat_completions_with_audio_input.yaml New VCR cassette for audio input chat completions coverage.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

dmontagu added a commit that referenced this pull request Feb 12, 2026
- Validate inputs in normalize_versions() (reject invalid versions, empty lists)
- Fix docstrings for instrument_openai/instrument_anthropic to accurately describe
  version='latest' behavior (minimal request_data still emitted)
- Fix test docstrings to match actual behavior
- Remove duplicate io import in test_openai.py
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