[opentelemetry-instrumentation-google-genai] Remove code supporting outdated sem convs. Cleanup code#110
Conversation
There was a problem hiding this comment.
Pull request overview
This PR aims to simplify opentelemetry-instrumentation-google-genai by removing legacy semantic-conventions support and related gating logic, standardizing on the newer GenAI semantic conventions, and cleaning up instrumentation/tests accordingly.
Changes:
- Removes legacy semconv support code paths and deletes related helper modules (
otel_wrapper.py,flags.py). - Refactors
generate_contentinstrumentation to rely onopentelemetry-util-genai’sTelemetryHandlerfor spans/metrics/events. - Updates tests + VCR cassettes and refreshes documentation around content-capture modes.
Reviewed changes
Copilot reviewed 23 out of 27 changed files in this pull request and generated 12 comments.
Show a summary per file
| File | Description |
|---|---|
| pytest.ini | Adjusts pytest reporting flags. |
| instrumentation/opentelemetry-instrumentation-google-genai/src/opentelemetry/instrumentation/google_genai/generate_content.py | Major refactor of generate_content instrumentation to use util-genai handler; removes old semconv path. |
| instrumentation/opentelemetry-instrumentation-google-genai/src/opentelemetry/instrumentation/google_genai/instrumentor.py | Removes OTelWrapper usage and wires instrumentation directly through TelemetryHandler. |
| instrumentation/opentelemetry-instrumentation-google-genai/src/opentelemetry/instrumentation/google_genai/otel_wrapper.py | Deleted legacy wrapper around tracer/meter/logger + metrics creation. |
| instrumentation/opentelemetry-instrumentation-google-genai/src/opentelemetry/instrumentation/google_genai/flags.py | Deleted legacy content-recording flag helper. |
| instrumentation/opentelemetry-instrumentation-google-genai/src/opentelemetry/instrumentation/google_genai/allowlist_util.py | Minor cleanup removing unused constants. |
| instrumentation/opentelemetry-instrumentation-google-genai/README.rst | Updates documentation for content capture modes and what’s captured. |
| instrumentation/opentelemetry-instrumentation-google-genai/.changelog/110.removed | Changelog entry for removing legacy semconv support/gating. |
| instrumentation/opentelemetry-instrumentation-google-genai/tests/common/base.py | Updates default env setup for tests; ensures instrumentation context cleared on teardown. |
| instrumentation/opentelemetry-instrumentation-google-genai/tests/utils/test_tool_call_wrapper.py | Updates env var values for content capture modes; removes semconv stability initialization usage in this test. |
| instrumentation/opentelemetry-instrumentation-google-genai/tests/generate_content/util.py | Changes mocked response token defaults (now defaulting to 0). |
| instrumentation/opentelemetry-instrumentation-google-genai/tests/generate_content/test_finish_reasons.py | Makes finish-reason attribute optional when no reasons are present. |
| instrumentation/opentelemetry-instrumentation-google-genai/tests/generate_content/test_e2e.py | Simplifies content-recording fixture params and semconv setup; removes older semconv parametrization. |
| instrumentation/opentelemetry-instrumentation-google-genai/tests/generate_content/streaming_base.py | Updates streaming tests to assert the new inference-details event instead of legacy choice events; fixes typo in test name. |
| instrumentation/opentelemetry-instrumentation-google-genai/tests/generate_content/nonstreaming_base.py | Updates assertions/fixtures for new provider attribute + content capture modes; refactors completion-recording tests. |
| instrumentation/opentelemetry-instrumentation-google-genai/tests/generate_content/cassettes/test_upload_hook_non_streaming[SPAN_AND_EVENT-gemini-2.5-flash-vertexaiapi-sync-enable_completion_hook].yaml | New/updated VCR cassette for upload hook (span+event). |
| instrumentation/opentelemetry-instrumentation-google-genai/tests/generate_content/cassettes/test_upload_hook_non_streaming[SPAN_AND_EVENT-gemini-2.5-flash-vertexaiapi-async-enable_completion_hook].yaml | New/updated VCR cassette for upload hook (span+event). |
| instrumentation/opentelemetry-instrumentation-google-genai/tests/generate_content/cassettes/test_upload_hook_non_streaming[NO_CONTENT-gemini-2.5-flash-vertexaiapi-sync-enable_completion_hook].yaml | New/updated VCR cassette for upload hook (no content). |
| instrumentation/opentelemetry-instrumentation-google-genai/tests/generate_content/cassettes/test_upload_hook_non_streaming[NO_CONTENT-gemini-2.5-flash-vertexaiapi-async-enable_completion_hook].yaml | New/updated VCR cassette for upload hook (no content). |
| instrumentation/opentelemetry-instrumentation-google-genai/tests/generate_content/cassettes/test_streaming[logcontent-gemini-2.5-flash-vertexaiapi-sync-default].yaml | Removes older cassette variant. |
| instrumentation/opentelemetry-instrumentation-google-genai/tests/generate_content/cassettes/test_streaming[logcontent-gemini-2.5-flash-vertexaiapi-async-default].yaml | Removes older cassette variant. |
| instrumentation/opentelemetry-instrumentation-google-genai/tests/generate_content/cassettes/test_streaming[excludecontent-gemini-2.5-flash-vertexaiapi-sync-default].yaml | Removes older cassette variant. |
| instrumentation/opentelemetry-instrumentation-google-genai/tests/generate_content/cassettes/test_streaming[excludecontent-gemini-2.5-flash-vertexaiapi-async-default].yaml | Removes older cassette variant. |
| instrumentation/opentelemetry-instrumentation-google-genai/tests/generate_content/cassettes/test_non_streaming[logcontent-gemini-2.5-flash-vertexaiapi-sync-default].yaml | Removes older cassette variant. |
| instrumentation/opentelemetry-instrumentation-google-genai/tests/generate_content/cassettes/test_non_streaming[logcontent-gemini-2.5-flash-vertexaiapi-async-default].yaml | Removes older cassette variant. |
| instrumentation/opentelemetry-instrumentation-google-genai/tests/generate_content/cassettes/test_non_streaming[excludecontent-gemini-2.5-flash-vertexaiapi-sync-default].yaml | Removes older cassette variant. |
| instrumentation/opentelemetry-instrumentation-google-genai/tests/generate_content/cassettes/test_non_streaming[excludecontent-gemini-2.5-flash-vertexaiapi-async-default].yaml | Removes older cassette variant. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
| def fixture_setup_content_recording(request): | ||
| os.environ.update( | ||
| { | ||
| OTEL_SEMCONV_STABILITY_OPT_IN: "gen_ai_latest_experimental", |
There was a problem hiding this comment.
seems we'll need to come back and clean this up after we remove experimental gate from utils
| @@ -0,0 +1 @@ | |||
| Remove the code supporting the old semantic conventions, and the `OTEL_SEMCONV_STABILITY_OPT_IN` flag that was gating the new conventions. The newest conventions will be used by default. No newline at end of file | |||
There was a problem hiding this comment.
is this correct though ? does util work without env var yet?
| ]: | ||
| return _get_vertexai_system_name() | ||
| return _get_gemini_system_name() | ||
| return gen_ai_attributes.GenAiSystemValues.VERTEX_AI.name.lower() |
There was a problem hiding this comment.
| return gen_ai_attributes.GenAiSystemValues.VERTEX_AI.name.lower() | |
| return gen_ai_attributes.GenAiProviderNameValues.VERTEX_AI.value |
| return _get_vertexai_system_name() | ||
| return _get_gemini_system_name() | ||
| return gen_ai_attributes.GenAiSystemValues.VERTEX_AI.name.lower() | ||
| return gen_ai_attributes.GenAiSystemValues.GEMINI.name.lower() |
There was a problem hiding this comment.
| return gen_ai_attributes.GenAiSystemValues.GEMINI.name.lower() | |
| return gen_ai_attributes.GenAiProviderNameValues.GEMINI.name.lower() |
| if vertexai_attr: | ||
| return _get_vertexai_system_name() | ||
| return _get_gemini_system_name() | ||
| return gen_ai_attributes.GenAiSystemValues.VERTEX_AI.name.lower() |
There was a problem hiding this comment.
| return gen_ai_attributes.GenAiSystemValues.VERTEX_AI.name.lower() | |
| return gen_ai_attributes.GenAiProviderNameValues.VERTEX_AI.value |
| ) | ||
| }, | ||
| ) | ||
| invocation.finish_reasons = sorted(finish_reason_set) |
There was a problem hiding this comment.
finish reasons should be in the same order as output messages, no need to dedup or order, why?
| for candidate in response.candidates or []: | ||
| if candidate.finish_reason: | ||
| finish_reason_set.add( | ||
| candidate.finish_reason.name.lower().removeprefix( |
There was a problem hiding this comment.
would this work?
| candidate.finish_reason.name.lower().removeprefix( | |
| candidate.finish_reason.value.removeprefix( |
| invocation.output_tokens = ( | ||
| invocation.output_tokens or 0 | ||
| ) + thinking_tokens | ||
| invocation.attributes["gen_ai.usage.reasoning.output_tokens"] = ( |
There was a problem hiding this comment.
| invocation.attributes["gen_ai.usage.reasoning.output_tokens"] = ( | |
| invocation.attributes[gen_ai_attributes.GEN_AI_USAGE_REASONING_OUTPUT_TOKENS] = ( |
Description
Remove the code supporting the old semantic conventions, and the
OTEL_SEMCONV_STABILITY_OPT_INflag that was gating the new conventions. The newest conventions will be used by default. Also do a lot of code cleanup..We need to clean up GenAI utils as well to stop using that env var, and always expect the content captured to be an enum..
Type of change
Please delete options that are not relevant.
How has this been tested?
Unit testsa
Checklist
See CONTRIBUTING.md
for the style guide, changelog guidance, and more.