Gemini
Coralogix's AI Observability integrations provide deep visibility into applications that rely on Google Gemini models. With a dedicated integration for the Google Generative AI SDK, Coralogix delivers consolidated insight into synchronous, streaming, and async calls, enabling teams to monitor performance, cost, and reliability across every Gemini workload.
Overview
This library supplies production-ready OpenTelemetry instrumentation for the Google GenAI SDK. It automatically traces invocations of Gemini text and tool-calling workflows, enriches spans with model metadata, and records usage metrics. The integration accelerates debugging, highlights token consumption, and standardizes observability across Gemini-powered features.
Note
Instrumentation covers synchronous, streaming, and async variants of Models.generate_content while preserving tool-call metadata emitted by the SDK.
Requirements
- Python version 3.9 and above.
- Coralogix API keys.
google-genaipackage version 1.0.0 (minimum) and below 2.0.0.
Configure the Gemini SDK with a valid API key before activating the instrumentation.
Installation
Run the following command.
Authentication
Exporting spans to Coralogix requires configuring OTLP credentials before enabling instrumentation. Use setup_export_to_coralogix or the corresponding environment variables to supply authentication details.
Using setup_export_to_coralogix
from llm_tracekit import setup_export_to_coralogix
setup_export_to_coralogix(
coralogix_token="<your_coralogix_token>",
coralogix_endpoint="<your_coralogix_endpoint>",
application_name="<ai-application>",
subsystem_name="<ai-subsystem>",
capture_content=True
)
Using environment variables
If arguments are not passed to setup_export_to_coralogix, the helper reads the following environment variables:
CX_TOKEN: Your Coralogix API key.CX_ENDPOINT: ingress.:443, the OpenTelemetry endpoint associated with your Coralogix domain.CX_APPLICATION_NAME: Your application's name.CX_SUBSYSTEM_NAME: Your subsystem's name.
Usage
Set up instrumentation for the Google GenAI SDK.
Set up tracing
Instrument
To instrument all Gemini models, create an instance of GeminiInstrumentor and call the instrument method.
from llm_tracekit import GeminiInstrumentor
instrumentor = GeminiInstrumentor()
instrumentor.instrument()
Uninstrument
To remove instrumentation, call the uninstrument method.
Full example
from google import genai
from llm_tracekit import setup_export_to_coralogix
from llm_tracekit import GeminiInstrumentor
setup_export_to_coralogix(
coralogix_token="<your_coralogix_token>",
coralogix_endpoint="<your_coralogix_endpoint>",
application_name="<ai-application>",
subsystem_name="<ai-subsystem>"
)
instrumentor = GeminiInstrumentor()
instrumentor.instrument()
client = genai.Client()
try:
response = client.models.generate_content(
model="gemini-2.0-flash-lite",
contents="What's the temperature in Tel Aviv?"
)
finally:
client.close()
print(response)
Enable message content capture
By default, message content - such as prompts, completions, tool call arguments, and tool responses - is not captured.
To capture message content as span attributes, set the environment variable OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT to true.
Many Coralogix AI evaluations rely on message content, so enabling capture is strongly recommended.
Key differences from OpenTelemetry
- User prompts, tool invocations, and model responses are stored as span attributes instead of log events, preserving a single correlated timeline for each request.
Semantic conventions
| Attribute | Type | Description | Example |
|---|---|---|---|
gen_ai.operation.name | string | The specific name of the Gemini operation being performed | chat |
gen_ai.system | string | The provider or framework responsible for the operation | gemini |
gen_ai.request.model | string | The name of the model requested by the user or application | gemini-2.0-flash-lite |
gen_ai.request.temperature | float | The temperature parameter passed in the request. Higher values increase randomness, while lower values make output more deterministic. | 0.7 |
gen_ai.request.top_p | float | The top_p parameter used for nucleus sampling, limiting token selection to the top probability mass. | 0.8 |
gen_ai.prompt.<message_number>.role | string | Role of the author for each input message | user |
gen_ai.prompt.<message_number>.content | string | Contents of the input message (captured when content capture is enabled) | What's the temperature in Tel Aviv? |
gen_ai.prompt.<message_number>.tool_calls.<tool_call_number>.id | string | ID of a tool call issued from the prompt | call_yPIxaozNPCSp1tJ34Hsbdtzg |
gen_ai.prompt.<message_number>.tool_calls.<tool_call_number>.type | string | Type of tool call issued from the prompt | function |
gen_ai.prompt.<message_number>.tool_calls.<tool_call_number>.function.name | string | Function name used in the prompt's tool call | get_current_temperature |
gen_ai.prompt.<message_number>.tool_calls.<tool_call_number>.function.arguments | string | Arguments passed to the prompt's tool call | {"location": "Tel Aviv"} |
gen_ai.completion.<choice_number>.role | string | Role of the author for each returned choice | model |
gen_ai.completion.<choice_number>.finish_reason | string | Finish reason reported for the choice | STOP |
gen_ai.completion.<choice_number>.content | string | Text returned by the model for the choice (captured when content capture is enabled) | The current temperature in Tel Aviv is 22°C. |
gen_ai.completion.<choice_number>.tool_calls.<tool_call_number>.id | string | ID of a tool call triggered by the model | call_O8NOz8VlxosSASEsOY7LDUcP |
gen_ai.completion.<choice_number>.tool_calls.<tool_call_number>.type | string | Type of tool call triggered by the model | function |
gen_ai.completion.<choice_number>.tool_calls.<tool_call_number>.function.name | string | Function name executed by the model's tool call | get_current_temperature |
gen_ai.completion.<choice_number>.tool_calls.<tool_call_number>.function.arguments | string | Arguments supplied to the model's tool call | {"location": "Tel Aviv"} |
gen_ai.response.model | string | Exact model identifier that produced the response | gemini-2.0-flash-lite |
gen_ai.response.id | string | Unique identifier assigned to the specific Gemini response | resp-20241010-abcdef1234567890 |
gen_ai.response.finish_reasons | string[] | Ordered list of finish reasons observed across all choices | ["STOP"] |
gen_ai.usage.input_tokens | int | Number of tokens consumed by the prompt | 66 |
gen_ai.usage.output_tokens | int | Number of tokens generated in the response | 44 |