Local observability and metrics
Genkit records a trace of every flow, model call, tool, and step it runs.
During development, the Genkit Developer UI shows these traces so you can debug
a flow step by step. In production, genkit-google-cloud sends traces and
metrics to Genkit Monitoring, or genkit-otel exports them to any
OpenTelemetry backend. See
Getting started with Genkit Monitoring.
Tracing & metrics
Section titled “Tracing & metrics”Under genkit start, Genkit sends its spans straight to the Developer UI’s
telemetry server, so you can analyze a
flow step by step with its inputs, outputs, and timing. No code change is
needed.
Everywhere else, Genkit installs no instrumentation provider, so nothing leaves
the process until one is configured. enable_google_cloud_telemetry() from
genkit-google-cloud configures one. So does passing GenAiInstrumentation
from genkit-otel to configure_instrumentation() from genkit.telemetry.
Metrics travel a separate path. Genkit core records no metrics.
GenAiInstrumentation records the OpenTelemetry GenAI client metrics
gen_ai.client.token.usage and gen_ai.client.operation.duration, and
enable_google_cloud_telemetry() installs it for you. The Developer UI does
not display metrics. See
Telemetry collection and
OpenTelemetry GenAI semantic conventions.
Log and export events
Section titled “Log and export events”Log with get_logger from genkit. It is built on
structlog: each call takes an event string and
keyword fields, which are recorded as structured attributes.
from genkit import Genkit, get_loggerfrom genkit_google_genai import GoogleAI
ai = Genkit(plugins=[GoogleAI()], model=GoogleAI.gemini('gemini-flash-latest'))logger = get_logger(__name__)
@ai.flow()async def generate_menu(theme: str) -> str: logger.info('Starting menu generation', theme=theme) # => console: [info] Starting menu generation theme=Italian
logger.debug('Calling model', theme=theme) # => console: nothing unless GENKIT_LOG=debug
response = await ai.generate(prompt=f'Suggest a {theme} menu item.') return response.textView logs in the Developer UI
Section titled “View logs in the Developer UI”Under genkit start, records written through this logger inside a flow are
also sent to the Developer UI, attached to the span that was active when they
were written. No configuration is needed.
The Developer UI receives every record at debug level and above, independent of the console level, so the terminal can stay quiet while debug records land in the trace viewer. Export never blocks your code: records are batched and posted from a background thread.
Before export, Genkit replaces the value of any field whose name looks like a
credential, such as api_key, token, or password, with <redacted>.
Environment variables
Section titled “Environment variables”GENKIT_LOG: console level, one ofdebug,info,warn,error, orcritical. Defaults toinfo. It does not change what the Developer UI receives. If your application configured its own structlog level, Genkit leaves it alone.GENKIT_OTEL_ENABLE_LOGS: set tofalse,0, orfto stop sending log records to the Developer UI. Export is on by default.