Learn how to instrument Google GenAI API calls with the LangWatch Python SDK
OpenInference
or OpenLLMetry
, LangWatch can seamlessly integrate with them. These libraries provide instrumentors that automatically capture data from various LLM providers, including Google GenAI.
There are two main ways to integrate these:
langwatch.setup()
GoogleGenAIInstrumentor
from OpenInference or OpenLLMetry) to the instrumentors
list in the langwatch.setup()
call. LangWatch will then manage the lifecycle of this instrumentor.
pip install openinference-instrumentation-google-genai
or pip install opentelemetry-instrumentation-google-genai
).TracerProvider
configured in your application (or if LangWatch is configured to use the global provider), you can use the community instrumentor’s instrument()
method directly. LangWatch will automatically pick up the spans generated by these instrumentors as long as its exporter is part of the active TracerProvider
.
langwatch.setup(instrumentors=[...])
, LangWatch handles the setup.GoogleGenAIInstrumentor().instrument()
), ensure that the TracerProvider
used by the instrumentor is the same one LangWatch is exporting from. This usually means LangWatch is configured to use an existing global provider or one you explicitly pass to langwatch.setup()
.autotrack_google_genai_calls()
is ideal for targeted instrumentation within specific traces or when you want fine-grained control over which Google GenAI client instances are tracked. It’s simpler if you’re not deeply invested in a separate OpenTelemetry setup.