Skip to main content

Installation

Setup

Generate content

Span name: "gemini-generate", SpanKind: LLM
What gets traced
  • Input: contents plus system_instruction normalized to messages format (role "model" mapped to "assistant")
  • Output: answer text (non-thought parts)
  • Model name
  • Token usage
  • Model parameters: temperature, top_p, top_k, max_output_tokens, stop_sequences, and related fields
  • Thinking or reasoning parts stored in metadata as reasoning_summary

Streaming and async

All four methods are traced: synchronous blocking, synchronous streaming, asynchronous blocking, asynchronous streaming.
Use models.generate_content_stream for synchronous iterators and aio.models.generate_content_stream with async for when the call site is already async. The wrapper emits the same span fields in both cases; only the execution model differs.

Thinking mode

When using Gemini’s thinking mode, thought parts are automatically separated from answer parts. Thought content is stored in metadata as reasoning_summary, while the span output contains only the answer text.

Token usage mapping