Skip to content

Google Cloud telemetry and logging plugin

The Google Cloud plugin exports Genkit’s telemetry and logging data to Google Cloud’s operation suite.

Note: Logging is facilitated by the slog package in favor of the OpenTelemetry logging APIs. Export of logs is done via a dedicated Google Cloud exporter.

Prerequisites

If you want to locally run flows that use this plugin, you need the Google Cloud CLI tool installed.

Set up a Google Cloud account

This plugin requires a Google Cloud account (sign up if you don’t already have one) and a Google Cloud project.

Prior to adding the plugin, make sure that the following APIs are enabled for your project:

These APIs should be listed in the API dashboard for your project.

Click here to learn more about enabling and disabling APIs.

Configuration

To enable exporting to Google Cloud Tracing, Logging, and Monitoring, import the googlecloud package and run Init(). After calling Init(), your telemetry gets automatically exported.

import "github.com/firebase/genkit/go/plugins/googlecloud"
if err := (&googlecloud.GoogleCloud{ProjectID: "your-google-cloud-project"}).Init(ctx, g); err != nil {
return err
}

You must specify the Google Cloud project to which you want to export telemetry data. There are also some optional parameters:

  • ProjectID: (Required) Your Google Cloud project ID.

  • ForceExport: Export telemetry data even when running in a dev environment (such as when using genkit start or genkit flow:run). This is a quick way to test your integration and send your first events for monitoring in Google Cloud.

    If you use this option, you also need to make your Cloud credentials available locally:

    Terminal window
    gcloud auth application-default login
  • MetricInterval: The interval (time.Duration) at which to export telemetry information. By default, this is 60 seconds.

  • LogLevel: The minimum severity level (slog.Level) of log entries to export. By default, slog.LevelInfo.

The plugin requires your Google Cloud project credentials. If you’re running your flows from a Google Cloud environment (Cloud Run, etc), the credentials are set automatically. Running in other environments requires setting up Application Default Credentials.

Production monitoring via Google Cloud’s operations suite

Once a flow is deployed, navigate to Google Cloud’s operations suite and select your project.

Google Cloud Operations Suite dashboard

Logs and traces

From the side menu, find ‘Logging’ and click ‘Logs explorer’.

Logs Explorer menu item in Cloud Logging

You will see all logs that are associated with your deployed flow, including console.log(). Any log which has the prefix [genkit] is a Genkit-internal log that contains information that may be interesting for debugging purposes. For example, Genkit logs in the format Config[...] contain metadata such as the temperature and topK values for specific LLM inferences. Logs in the format Output[...] contain LLM responses while Input[...] logs contain the prompts. Cloud Logging has robust ACLs that allow fine grained control over sensitive logs.

Note: Prompts and LLM responses are redacted from trace attributes in Cloud Trace.

For specific log lines, it is possible to navigate to their respective traces by clicking on the extended menu Log line menu icon icon and selecting “View in trace details”.

View in trace details option in log menu

This will bring up a trace preview pane providing a quick glance of the details of the trace. To get to the full details, click the “View in Trace” link at the top right of the pane.

View in Trace link in trace preview pane

The most prominent navigation element in Cloud Trace is the trace scatter plot. It contains all collected traces in a given time span.

Cloud Trace scatter plot

Clicking on each data point will show its details below the scatter plot.

Cloud Trace details view

The detailed view contains the flow shape, including all steps, and important timing information. Cloud Trace has the ability to interleave all logs associated with a given trace within this view. Select the “Show expanded” option in the “Logs & events” drop down.

Show expanded option in Logs & events dropdown

The resultant view allows detailed examination of logs in the context of the trace, including prompts and LLM responses.

Trace details view with expanded logs

Metrics

Viewing all metrics that Genkit exports can be done by selecting “Logging” from the side menu and clicking on “Metrics management”.

Metrics Management menu item in Cloud Logging

The metrics management console contains a tabular view of all collected metrics, including those that pertain to Cloud Run and its surrounding environment. Clicking on the ‘Workload’ option will reveal a list that includes Genkit-collected metrics. Any metric with the genkit prefix constitutes an internal Genkit metric.

Metrics table showing Genkit metrics

Genkit collects several categories of metrics, including flow-level, action-level, and generate-level metrics. Each metric has several useful dimensions facilitating robust filtering and grouping.

Common dimensions include:

  • flow_name - the top-level name of the flow.
  • flow_path - the span and its parent span chain up to the root span.
  • error_code - in case of an error, the corresponding error code.
  • error_message - in case of an error, the corresponding error message.
  • model - the name of the model.
  • temperature - the inference temperature value.
  • topK - the inference topK value.
  • topP - the inference topP value.

Flow-level metrics

NameDimensions
genkit/flow/requestsflow_name, error_code, error_message
genkit/flow/latencyflow_name

Action-level metrics

NameDimensions
genkit/action/requestsflow_name, error_code, error_message
genkit/action/latencyflow_name

Generate-level metrics

NameDimensions
genkit/ai/generateflow_path, model, temperature, topK, topP, error_code, error_message
genkit/ai/generate/input_tokensflow_path, model, temperature, topK, topP
genkit/ai/generate/output_tokensflow_path, model, temperature, topK, topP
genkit/ai/generate/input_charactersflow_path, model, temperature, topK, topP
genkit/ai/generate/output_charactersflow_path, model, temperature, topK, topP
genkit/ai/generate/input_imagesflow_path, model, temperature, topK, topP
genkit/ai/generate/output_imagesflow_path, model, temperature, topK, topP
genkit/ai/generate/latencyflow_path, model, temperature, topK, topP, error_code, error_message

Visualizing metrics can be done through the Metrics Explorer. Using the side menu, select ‘Logging’ and click ‘Metrics explorer’

Metrics Explorer menu item in Cloud Logging

Select a metrics by clicking on the “Select a metric” dropdown, selecting ‘Generic Node’, ‘Genkit’, and a metric.

Selecting a Genkit metric in Metrics Explorer

The visualization of the metric will depend on its type (counter, histogram, etc). The Metrics Explorer provides robust aggregation and querying facilities to help graph metrics by their various dimensions.

Metrics Explorer showing a Genkit metric graph

Telemetry Delay

There may be a slight delay before telemetry for a particular execution of a flow is displayed in Cloud’s operations suite. In most cases, this delay is under 1 minute.

Quotas and limits

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

Cost

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