Python · Instrumentation
openinference-instrumentation-google-genai
OpenInference Google GenAI Instrumentation
- Module
openinference.instrumentation.google_genai- Version
- 1.6.4
- Python
- >=3.10, <3.16
- Instruments
google-genai >= 2.0.0
Install
pip install openinference-instrumentation-google-genaiUsage
Instrument once, at startup, before the library is used. The GoogleGenAIInstrumentor reference below lists the options.
from opentelemetry.sdk.trace import TracerProvider
from openinference.instrumentation import TraceConfig
from openinference.instrumentation.google_genai import GoogleGenAIInstrumentor
tracer_provider = TracerProvider()
# ...add a span processor that exports to Phoenix or any OTLP backend.
GoogleGenAIInstrumentor().instrument(
tracer_provider=tracer_provider,
config=TraceConfig(hide_inputs=True), # optional
)openinference.instrumentation.google_genai
GoogleGenAIInstrumentor
classSource ↗class GoogleGenAIInstrumentor(BaseInstrumentor)An instrumentor for google-genai
instrument
methoddef instrument(
*,
tracer_provider: Optional[TracerProvider] = None,
config: Optional[TraceConfig] = None,
skip_dep_check: bool = False,
) -> NoneStart tracing google-genai: patch it so its calls make OpenInference spans. Calling it again does nothing. Inherited from OpenTelemetry’s BaseInstrumentor.
Parameters
| Name | Description |
|---|---|
tracer_provider | The tracer provider the spans are made with. Defaults to the global one, |
config | What the spans record: hide inputs, outputs or messages, or limit image sizes. Defaults to |
skip_dep_check | Instrument even if the installed version of |
uninstrument
methoddef uninstrument() -> NoneStop tracing: undo the patches instrument() made. Inherited from OpenTelemetry’s BaseInstrumentor.
instrumentation_dependencies
methodSource ↗def instrumentation_dependencies() -> Collection[str]openinference.instrumentation.google_genai.cache_attributes
get_attributes_from_request
functionSource ↗def get_attributes_from_request(
request_parameters: Mapping[str, Any],
config: TraceConfig | None,
) -> Iterator[tuple[str, AttributeValue]]get_attributes_from_response
functionSource ↗def get_attributes_from_response(
response: types.CachedContent,
) -> Iterator[tuple[str, AttributeValue]]openinference.instrumentation.google_genai.interactions_attributes
get_output_messages
functionSource ↗def get_output_messages(steps: Any) -> list[Message]get_message_objects
functionSource ↗def get_message_objects(inputs: Any) -> list[Message]get_tools
functionSource ↗def get_tools(request_params: Mapping[str, Any]) -> list[Tool]get_token_object_from_response
functionSource ↗def get_token_object_from_response(response: Any) -> TokenCountis_agent_call
functionSource ↗def is_agent_call(request_parameters: Mapping[str, Any]) -> boolis_agent_response
functionSource ↗def is_agent_response(response: Any) -> boolget_attributes_from_request_object
functionSource ↗def get_attributes_from_request_object(
request_parameters: Mapping[str, Any],
config: TraceConfig | None,
) -> dict[str, AttributeValue]get_attributes_from_get_request_object
functionSource ↗def get_attributes_from_get_request_object(
request_parameters: Mapping[str, Any],
) -> dict[str, AttributeValue]get_attributes_from_request
functionSource ↗def get_attributes_from_request(
request_parameters: Mapping[str, Any],
config: TraceConfig | None,
) -> Iterable[tuple[str, AttributeValue]]get_attributes_from_get_request
functionSource ↗def get_attributes_from_get_request(
request_parameters: Mapping[str, Any],
) -> Iterable[tuple[str, AttributeValue]]get_attributes_from_response
functionSource ↗def get_attributes_from_response(
request_parameters: Mapping[str, Any],
response: Any,
) -> dict[str, AttributeValue]