Skip to content

Emit telemetry under the instrumentation's own scope - #632

Merged
lmolkova merged 10 commits into
open-telemetry:mainfrom
lmolkova:fix-instr-scope
Sep 12, 2026
Merged

lmolkova merged 10 commits into
open-telemetry:mainfrom
lmolkova:fix-instr-scope

Conversation

@lmolkova

@lmolkova lmolkova commented Sep 5, 2026 •

Copy link
Copy Markdown
Member

Fixes #620.

TelemetryHandler now takes instrumentation_scope_name/instrumentation_scope_version, and every instrumentation passes its own, so spans, metrics and logs carry the instrumentation's scope instead of opentelemetry.util.genai.handler.

get_telemetry_handler is deprecated - no need to have shared state.

Known gaps:

Replace the per-package instrumentation-scope tests with an autouse
fixture that checks every TelemetryHandler built by instrumentation code
during any test.
claude-agent-sdk, crewai and dspy declared older floors, so their oldest
envs resolved a util-genai without instrumentation_scope_name.

Assisted-by: Claude Opus 5
@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Sep 5, 2026 •

Copy link
Copy Markdown

Pull request dashboard status

Merged · refreshed 2026-09-12 19:06 UTC

Status above doesn't look right?
  • Anything look wrong? Report it with what you expected; it helps us improve the dashboard.

Comment thread util/opentelemetry-util-genai/.changelog/632.deprecated Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

TelemetryHandler currently coerces a missing scope version to "" and allows version-without-name, which can produce surprising/mismatched instrumentation scope metadata for emitted telemetry.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Updates opentelemetry-util-genai and all dependent instrumentations so emitted spans/metrics/logs use the instrumentation library’s scope (instead of opentelemetry.util.genai.handler), restoring correct attribution across the ecosystem.

Changes:

  • Extend TelemetryHandler with instrumentation_scope_name / instrumentation_scope_version, and deprecate get_telemetry_handler() (singleton cannot represent per-instrumentation scope).
  • Update instrumentations to construct TelemetryHandler with their own scope name/version.
  • Add a util-level scope test plus a shared autouse test fixture that fails tests if an instrumentation builds a mis-scoped handler; update docs and changelog fragments accordingly.
File summaries
File Description
util/opentelemetry-util-genai/src/opentelemetry/util/genai/handler.py Add per-instrumentation scope parameters to TelemetryHandler; mark get_telemetry_handler() deprecated.
util/opentelemetry-util-genai/tests/test_utils.py Stop using/resetting the get_telemetry_handler() singleton in tests; construct TelemetryHandler directly.
util/opentelemetry-util-genai/tests/test_utils_events.py Same as above for event-focused tests.
util/opentelemetry-util-genai/tests/test_handler_scope.py New test asserting scope name/version/schema_url propagate to spans, metrics, and logs, and that defaults remain the util scope.
util/opentelemetry-util-genai/.changelog/632.added Towncrier fragment documenting new handler scope parameters.
util/opentelemetry-util-genai/.changelog/632.deprecated Towncrier fragment documenting get_telemetry_handler() deprecation.
util/opentelemetry-test-util-genai/src/opentelemetry/test_util_genai/fixtures.py Add autouse fixture enforcing correct handler scope usage from instrumentation code under test.
instrumentation/opentelemetry-instrumentation-google-genai/src/opentelemetry/instrumentation/google_genai/instrumentor.py Pass instrumentation scope name/version into TelemetryHandler for google-genai.
instrumentation/opentelemetry-instrumentation-google-genai/.changelog/632.fixed Document scope attribution fix for google-genai.
instrumentation/opentelemetry-instrumentation-genai-smolagents/src/opentelemetry/instrumentation/genai/smolagents/init.py Pass instrumentation scope name/version into TelemetryHandler.
instrumentation/opentelemetry-instrumentation-genai-smolagents/.changelog/632.fixed Document scope attribution fix for smolagents.
instrumentation/opentelemetry-instrumentation-genai-qwen-agent/src/opentelemetry/instrumentation/genai/qwen_agent/init.py Pass instrumentation scope name/version into TelemetryHandler.
instrumentation/opentelemetry-instrumentation-genai-qwen-agent/.changelog/632.fixed Document scope attribution fix for qwen-agent.
instrumentation/opentelemetry-instrumentation-genai-portkey/src/opentelemetry/instrumentation/genai/portkey/init.py Pass instrumentation scope name/version into TelemetryHandler.
instrumentation/opentelemetry-instrumentation-genai-portkey/.changelog/632.fixed Document scope attribution fix for portkey.
instrumentation/opentelemetry-instrumentation-genai-openai/src/opentelemetry/instrumentation/genai/openai/init.py Pass instrumentation scope name/version into TelemetryHandler.
instrumentation/opentelemetry-instrumentation-genai-openai/.changelog/632.fixed Document scope attribution fix for openai.
instrumentation/opentelemetry-instrumentation-genai-openai-agents/src/opentelemetry/instrumentation/genai/openai_agents/init.py Pass instrumentation scope name/version into TelemetryHandler.
instrumentation/opentelemetry-instrumentation-genai-openai-agents/.changelog/632.fixed Document scope attribution fix for openai-agents.
instrumentation/opentelemetry-instrumentation-genai-llama-index/src/opentelemetry/instrumentation/genai/llama_index/init.py Pass instrumentation scope name/version into TelemetryHandler.
instrumentation/opentelemetry-instrumentation-genai-llama-index/.changelog/632.fixed Document scope attribution fix for llama-index.
instrumentation/opentelemetry-instrumentation-genai-langchain/src/opentelemetry/instrumentation/genai/langchain/init.py Replace get_telemetry_handler() usage with direct TelemetryHandler construction + scope args.
instrumentation/opentelemetry-instrumentation-genai-langchain/tests/test_completion_hook.py Update tests to patch/expect TelemetryHandler construction instead of get_telemetry_handler().
instrumentation/opentelemetry-instrumentation-genai-langchain/.changelog/632.fixed Document scope attribution fix for langchain.
instrumentation/opentelemetry-instrumentation-genai-dspy/src/opentelemetry/instrumentation/genai/dspy/init.py Pass instrumentation scope name/version into TelemetryHandler.
instrumentation/opentelemetry-instrumentation-genai-dspy/pyproject.toml Bump opentelemetry-util-genai dependency lower bound to a 1.2b0.dev line.
instrumentation/opentelemetry-instrumentation-genai-dspy/tests/requirements.oldest.txt Add editable util-genai install for oldest factor until a release is published.
instrumentation/opentelemetry-instrumentation-genai-dspy/.changelog/632.fixed Document scope attribution fix for dspy.
instrumentation/opentelemetry-instrumentation-genai-crewai/src/opentelemetry/instrumentation/genai/crewai/init.py Pass instrumentation scope name/version into TelemetryHandler.
instrumentation/opentelemetry-instrumentation-genai-crewai/pyproject.toml Bump opentelemetry-util-genai dependency lower bound to a 1.2b0.dev line.
instrumentation/opentelemetry-instrumentation-genai-crewai/tests/requirements.oldest.txt Add editable util-genai install for oldest factor until a release is published.
instrumentation/opentelemetry-instrumentation-genai-crewai/.changelog/632.fixed Document scope attribution fix for crewai.
instrumentation/opentelemetry-instrumentation-genai-claude-agent-sdk/src/opentelemetry/instrumentation/genai/claude_agent_sdk/init.py Pass instrumentation scope name/version into TelemetryHandler.
instrumentation/opentelemetry-instrumentation-genai-claude-agent-sdk/pyproject.toml Bump opentelemetry-util-genai dependency lower bound to a 1.2b0.dev line.
instrumentation/opentelemetry-instrumentation-genai-claude-agent-sdk/tests/requirements.oldest.txt Add editable util-genai install for oldest factor until a release is published.
instrumentation/opentelemetry-instrumentation-genai-claude-agent-sdk/.changelog/632.fixed Document scope attribution fix for claude-agent-sdk.
instrumentation/opentelemetry-instrumentation-genai-bedrock/src/opentelemetry/instrumentation/genai/bedrock/init.py Pass instrumentation scope name/version into TelemetryHandler.
instrumentation/opentelemetry-instrumentation-genai-bedrock/.changelog/632.fixed Document scope attribution fix for bedrock.
instrumentation/opentelemetry-instrumentation-genai-anthropic/src/opentelemetry/instrumentation/genai/anthropic/init.py Pass instrumentation scope name/version into TelemetryHandler.
instrumentation/opentelemetry-instrumentation-genai-anthropic/.changelog/632.fixed Document scope attribution fix for anthropic.
instrumentation/opentelemetry-instrumentation-genai-agno/src/opentelemetry/instrumentation/genai/agno/init.py Pass instrumentation scope name/version into TelemetryHandler.
instrumentation/opentelemetry-instrumentation-genai-agno/.changelog/632.fixed Document scope attribution fix for agno.
AGENTS.md Document the new “always pass handler scope name/version” rule and note the enforcing shared fixture.
.github/instructions/instrumentation.instructions.md Update reviewer instructions to flag missing scope args and new get_telemetry_handler() usage.
Review details
  • Files reviewed: 44/44 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@lmolkova
lmolkova marked this pull request as ready for review September 5, 2026 00:39
@lmolkova
lmolkova requested a review from a team as a code owner September 5, 2026 00:39

@xrmx xrmx left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks!

Comment thread .github/instructions/instrumentation.instructions.md Outdated
Comment thread AGENTS.md Outdated

@eternalcuriouslearner eternalcuriouslearner left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM!! Got a dumb question!! Can name be null/none in any case?

# Conflicts:
#	instrumentation/opentelemetry-instrumentation-genai-dspy/pyproject.toml
#	util/opentelemetry-util-genai/src/opentelemetry/util/genai/handler.py
@lmolkova

Copy link
Copy Markdown
Member Author

LGTM!! Got a dumb question!! Can name be null/none in any case?

Thanks! Not in normal circumstances, but technically possible to set it to None. Added tests to validate proper names.

@lmolkova
lmolkova enabled auto-merge September 12, 2026 18:32
@lmolkova
lmolkova added this pull request to the merge queue Sep 12, 2026
Merged via the queue into open-telemetry:main with commit 83b1cdb Sep 12, 2026
76 checks passed
@lmolkova
lmolkova deleted the fix-instr-scope branch September 12, 2026 19:05
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.

util-genai: telemetry is emitted under scope opentelemetry.util.genai.handler instead of the instrumentation library, losing attribution

4 participants