Add semantic convention message attributes to LLM integrations#1705
Merged
Add semantic convention message attributes to LLM integrations#1705
Conversation
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
Deploying logfire-docs with
|
| 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 |
Contributor
There was a problem hiding this comment.
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
versionparameter toinstrument_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, andgen_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
3 tasks
dmontagu
added a commit
that referenced
this pull request
Feb 12, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Supersedes #1666. Clean branch with identical final code, no merge artifacts.
Credit to @brightsparc for the bulk of the implementation.
gen_ai.input.messages,gen_ai.output.messages, andgen_ai.system_instructionsattributes following OpenTelemetry semantic conventions for OpenAI and Anthropic integrationsversionparameter toinstrument_openai()andinstrument_anthropic()controlling attribute format (1,'latest', or[1, 'latest'])version=[1, 'latest']for coverage of both code pathsversion_latestandversion_v1_onlytests to verify attribute gating works correctlyTest plan