Skip to content

openai-agents-v2: use genai-utils for env var constant, histogram factories, and meter_provider#4456

Open
nagkumar91 wants to merge 3 commits intoopen-telemetry:mainfrom
nagkumar91:use-genai-utils-openai-agents-v2
Open

openai-agents-v2: use genai-utils for env var constant, histogram factories, and meter_provider#4456
nagkumar91 wants to merge 3 commits intoopen-telemetry:mainfrom
nagkumar91:use-genai-utils-openai-agents-v2

Conversation

@nagkumar91
Copy link
Copy Markdown
Contributor

Summary

Three improvements to align opentelemetry-instrumentation-openai-agents-v2 with opentelemetry-util-genai:

Changes

1. Env var constant — single source of truth

Remove _CONTENT_CAPTURE_ENV = "OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT" from __init__.py and import the constant from opentelemetry.util.genai.environment_variables.

2. Fix silently-ignored meter_provider

GenAISemanticProcessor._init_metrics() previously called get_meter(...) without any provider, so a caller-supplied meter_provider was silently ignored. This PR:

  • Adds meter_provider: Optional[MeterProvider] = None to GenAISemanticProcessor.__init__
  • Threads it through to _init_metrics(meter_provider)
  • Passes it to get_meter() along with the package's actual __version__ (was hardcoded as "0.1.0")

3. Semconv bucket boundaries via genai-utils histogram factories

Replace inline meter.create_histogram() calls with create_duration_histogram(meter) and create_token_histogram(meter) from opentelemetry.util.genai.instruments. This adds the semconv-specified explicit bucket boundaries that were previously missing from the agent's metrics.

Testing

All 103 existing tests pass.

…nd meter_provider

Three improvements to align with opentelemetry-util-genai:

1. Import OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT from
   opentelemetry.util.genai.environment_variables instead of re-defining
   it locally in __init__.py.

2. Add meter_provider parameter to GenAISemanticProcessor and thread it
   through _init_metrics(), fixing the bug where a caller-supplied
   MeterProvider was silently ignored.

3. Replace inline create_histogram() calls with create_duration_histogram()
   and create_token_histogram() from opentelemetry.util.genai.instruments,
   which adds the semconv-specified explicit bucket boundaries that were
   previously missing.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
nagkumar91 and others added 2 commits April 16, 2026 15:13
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant