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
Open
Conversation
…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>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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
Three improvements to align
opentelemetry-instrumentation-openai-agents-v2withopentelemetry-util-genai:Changes
1. Env var constant — single source of truth
Remove
_CONTENT_CAPTURE_ENV = "OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT"from__init__.pyand import the constant fromopentelemetry.util.genai.environment_variables.2. Fix silently-ignored
meter_providerGenAISemanticProcessor._init_metrics()previously calledget_meter(...)without any provider, so a caller-suppliedmeter_providerwas silently ignored. This PR:meter_provider: Optional[MeterProvider] = NonetoGenAISemanticProcessor.__init___init_metrics(meter_provider)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 withcreate_duration_histogram(meter)andcreate_token_histogram(meter)fromopentelemetry.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.