Skip to content

Conversation

@RKest
Copy link

@RKest RKest commented Dec 5, 2025

Description

Support suppress_instrumentation context manager in opentelemetry-instrumentor-google-genai.
Motivation for this change is to add a default, stable across LLM providers instrumentation of inference in google/adk-python.
When ADK instruments inference, we want to be able to suppress the third party instrumentation.

Similar merged PR #3460

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • Added unit tests
  • Manual test:
export GOOGLE_CLOUD_PROJECT="<gcp project id>"
uv venv --python "python3.12" .venv
. .venv/bin/activate
uv pip install opentelemetry-sdk google-genai
uv pip install 'opentelemetry-instrumentation-google-genai @ git+https://github.com/RKest/opentelemetry-python-contrib.git#subdirectory=instrumentation-genai/opentelemetry-instrumentation-google-genai'
from google import genai
import os
from opentelemetry import trace
from opentelemetry.instrumentation.google_genai import GoogleGenAiSdkInstrumentor
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.instrumentation.utils import suppress_instrumentation
from opentelemetry.sdk.trace.export import (
    ConsoleSpanExporter,
    SimpleSpanProcessor,
)

GoogleGenAiSdkInstrumentor().instrument()

tracer_provider = TracerProvider()
tracer_provider.add_span_processor(SimpleSpanProcessor(ConsoleSpanExporter()))
trace.set_tracer_provider(tracer_provider)

client = genai.Client(
    vertexai=False,
    project=os.getenv("GOOGLE_CLOUD_PROJECT"),
    location='us-central1',
)

with suppress_instrumentation():
  resp = client.models.generate_content(
      model="gemini-2.5-pro",
      contents="What's 9 + 10",
  )

  print(F"{resp=}")

Does This PR Require a Core Repo Change?

  • Yes. - Link to PR:
  • No.

Checklist:

See contributing.md for styleguide, changelog guidelines, and more.

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added

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.

6 participants