Skip to content

Telemetry collection

The Firebase telemetry plugin exports a combination of metrics, traces, and logs to Google Cloud Observability. This document details which metrics, trace attributes, and logs will be collected and what you can expect in terms of latency, quotas, and cost.

There may be a slight delay before telemetry from a given invocation is available in Firebase. This is dependent on your export interval (5 minutes by default).

There are several quotas that are important to keep in mind:

Cloud Logging, Cloud Trace, and Cloud Monitoring have generous free-of-charge tiers. Specific pricing can be found at the following links:

enable_google_cloud_telemetry() exports telemetry that follows the OpenTelemetry GenAI semantic conventions. It installs GenAiInstrumentation from genkit-otel unless one is already configured. It does not write the genkit/feature/*, genkit/action/*, or genkit/ai/generate/* metrics, or the [genkit] Input[...] style log entries.

GenAiInstrumentation records two histograms for every model call on the process MeterProvider. Metrics are not sampled.

  • gen_ai.client.token.usage: histogram of token counts, split by gen_ai.token.type (input or output).
  • gen_ai.client.operation.duration: histogram of model call latency in seconds, for successful and failed calls. Failures carry error.type, the exception class name.

Both carry gen_ai.operation.name (chat), gen_ai.request.model, and gen_ai.provider.name when the provider is known.

Each Genkit request produces one connected trace in Cloud Trace:

  • Model spans (chat <model>): CLIENT spans with the gen_ai.* attributes listed in What gets emitted.
  • Tool spans (execute_tool <name>): INTERNAL spans with gen_ai.tool.name and gen_ai.tool.type = 'function'. Emitted only when you configure GenAiInstrumentation(emit_tool_spans=True) before calling enable_google_cloud_telemetry().
  • Other action spans (<action name>): INTERNAL spans with genkit.action.type, such as flow or retriever, so model calls nest under their flow. If a tool or flow raises Interrupt, the span gets genkit.interrupted = True and no error status.

Before export, GcpAdjustingTraceExporter adjusts each span for Cloud Trace:

  • : in attribute keys becomes /, so genkit:metadata:<key> arrives as genkit/metadata/<key>.
  • Spans with an error status get /http/status_code = '599', so Cloud Trace highlights them.
  • Zero-length spans are padded to 1 microsecond.

Prompt and response events are off by default. Turn them on with content_capturing_mode='EVENT_ONLY' or 'SPAN_AND_EVENT', either on GenAiInstrumentation before you call enable_google_cloud_telemetry() or through OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT. See Capturing message content.

Each model call then emits a gen_ai.client.inference.operation.details log record with gen_ai.input.messages, gen_ai.output.messages, and gen_ai.system_instructions. With emit_tool_spans=True, each tool call emits one with gen_ai.tool.call.arguments and gen_ai.tool.call.result. Records go to Cloud Logging under the log name gen_ai.client.inference.operation.details.

  • Cloud Trace does not store prompt or reply content: before export, GcpAdjustingTraceExporter replaces these attributes with '<redacted>': gen_ai.input.messages, gen_ai.output.messages, gen_ai.system_instructions, gen_ai.tool.call.arguments, gen_ai.tool.call.result, genkit.input, genkit.output, genkit:input, genkit:output, genkit:metadata:interrupt, and genkit:metadata:resumed.
  • Genkit span errors are redacted too: str(exc), for example from a Pydantic ValidationError, can quote prompt or tool payloads. On spans Genkit created, the status description, exception.message, and exception.stacktrace become '<redacted>'. error.type and exception.type are kept.
  • Other spans pass through unchanged: spans from HTTP frameworks, database drivers, or your own code keep their attributes and exception messages.
  • Cloud Logging is not redacted: with EVENT_ONLY or SPAN_AND_EVENT, the operation-details records carry the full prompt, reply, system instructions, and tool payloads to Cloud Logging.
  • Your own exporters see the content: with content_capturing_mode='SPAN_ONLY' or capture_action_io=True, a SpanExporter you attach to the same TracerProvider receives the unredacted attributes. Only the Cloud Trace export is redacted.