Skip to content

[opentelemetry-instrumentation-google-genai] Remove code supporting outdated sem convs. Cleanup code#110

Open
DylanRussell wants to merge 6 commits into
open-telemetry:mainfrom
DylanRussell:remove_default
Open

[opentelemetry-instrumentation-google-genai] Remove code supporting outdated sem convs. Cleanup code#110
DylanRussell wants to merge 6 commits into
open-telemetry:mainfrom
DylanRussell:remove_default

Conversation

@DylanRussell
Copy link
Copy Markdown
Contributor

@DylanRussell DylanRussell commented Jun 5, 2026

Description

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. 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.

  • [x ] Breaking change (fix or feature that would cause existing functionality to not work as expected)

How has this been tested?

Unit testsa

Checklist

See CONTRIBUTING.md
for the style guide, changelog guidance, and more.

  • [ x] Followed the style guidelines of this project
  • [ x] Changelog updated if the change requires an entry
  • [ x] Unit tests added
  • [x ] Documentation updated

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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_content instrumentation to rely on opentelemetry-util-genai’s TelemetryHandler for 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.

Comment thread instrumentation/opentelemetry-instrumentation-google-genai/README.rst Outdated
DylanRussell and others added 4 commits June 5, 2026 12:13
def fixture_setup_content_recording(request):
os.environ.update(
{
OTEL_SEMCONV_STABILITY_OPT_IN: "gen_ai_latest_experimental",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
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()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
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()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
return gen_ai_attributes.GenAiSystemValues.VERTEX_AI.name.lower()
return gen_ai_attributes.GenAiProviderNameValues.VERTEX_AI.value

)
},
)
invocation.finish_reasons = sorted(finish_reason_set)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

would this work?

Suggested change
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"] = (
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
invocation.attributes["gen_ai.usage.reasoning.output_tokens"] = (
invocation.attributes[gen_ai_attributes.GEN_AI_USAGE_REASONING_OUTPUT_TOKENS] = (

seems to be released https://github.com/open-telemetry/opentelemetry-python/blob/367e14d01104785ac28b1c66ac32b2082f864a12/opentelemetry-semantic-conventions/src/opentelemetry/semconv/_incubating/attributes/gen_ai_attributes.py#L432

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants