Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.trodo.ai/docs/llms.txt

Use this file to discover all available pages before exploring further.

What auto-instruments

Two separate instrumentation packages, one per SDK:
  • opentelemetry-instrumentation-google-generativeai — for the google-generativeai PyPI package (Gemini API).
  • opentelemetry-instrumentation-vertexai — for the google-cloud-aiplatform / vertexai package (Vertex AI).
CallSpan kindAuto-extracted
GenerativeModel.generate_contentllmmodel, tokens (usageMetadata), prompt, response
GenerativeModel.generate_content_streamllmSame, accumulated
GenerativeModel.start_chatsend_messagellmSame, with chat history in input
embed_contentllmmodel, input tokens
(Vertex) TextGenerationModel.predict (legacy PaLM)llmmodel, tokens
Provider field is google for Gemini, google-vertex for Vertex.

Install

pip install google-generativeai opentelemetry-instrumentation-google-generativeai
# or
pip install google-cloud-aiplatform opentelemetry-instrumentation-vertexai

Gemini minimum example

import trodo, os
import google.generativeai as genai

trodo.init(site_id=os.environ["TRODO_SITE_ID"])
genai.configure(api_key=os.environ["GEMINI_API_KEY"])
model = genai.GenerativeModel("gemini-2.5-flash")

with trodo.wrap_agent("gemini-bot") as run:
    r = model.generate_content("Explain TimescaleDB in one sentence.")
    run.set_output(r.text)

Vertex minimum example

import trodo, os
import vertexai
from vertexai.generative_models import GenerativeModel

trodo.init(site_id=os.environ["TRODO_SITE_ID"])
vertexai.init(project=os.environ["GCP_PROJECT"], location="us-central1")
model = GenerativeModel("gemini-2.5-pro")

with trodo.wrap_agent("vertex-bot") as run:
    r = model.generate_content("Explain TimescaleDB in one sentence.")
    run.set_output(r.text)

Token extraction

Both SDKs return usage_metadata with:
  • prompt_token_countinput_tokens
  • candidates_token_countoutput_tokens
  • total_token_count → ignored (we recompute from inputs + outputs)

Function calling

Gemini’s function-calling loop alternates generate_content calls and your tool executions. Wrap the tool side:
while True:
    r = model.generate_content(history)
    part = r.candidates[0].content.parts[0]
    if not getattr(part, "function_call", None):
        answer = r.text; break
    with trodo.span(part.function_call.name, kind="tool") as s:
        s.set_tool(part.function_call.name)
        result = run_tool(part.function_call)
        s.set_output(result)
    history.append(r.candidates[0].content)
    history.append({"role": "function", "parts": [{"function_response": {...}}]})

Auto vs manual cheat-table

OperationAuto?Notes
generate_content / streamyes
start_chat + send_messageyesEach send = one span
embed_contentyes
File API (upload_file)noOut of scope — usually one-off
Caching (CachedContent)partialCreation silent; usage reflected in span’s cached_content_token_count
Vertex endpoint mode (Endpoint.predict)noCustom-trained models — wrap with trodo.llm + extractUsage

Gotchas

  • Node support is via REST only — there is no Google-provided first-party OTel instrumentation for the JS SDK. Use trodo.llm or trodo.trackLlmCall with the default extractUsage (which handles usageMetadata).
  • The Gemini SDK and the Vertex SDK both expose a GenerativeModel class — the instrumentation packages are mutually non-interfering but you must install whichever one matches the SDK you import.
  • Thinking tokens (Gemini 2.5): usage_metadata.thoughts_token_count is available on the span’s raw attributes but is not rolled into input_tokens / output_tokens — read it from the span detail drawer.