Choose an instrumentation approach

This page contains recommendations for instrumenting your app on different Google Cloud platforms, such as Google Kubernetes Engine (GKE) and Cloud Run. If your app isn't already instrumented, then use these recommendations for guidance as to how to instrument your app to send telemetry data to Google Cloud. The recommendations on this page aren't the only solutions, and other approaches can work. For additional guidance, contact Google Cloud Support.

There are recommendations for the following:

For information about instrumentation examples, see the documents listed in the Code samples section.

GKE

For general information about GKE, see GKE overview.

Type Recommendation
Metrics

We recommend that you use Google Cloud Managed Service for Prometheus.

For instrumentation, do one of the following:

Traces

Do the following:

  1. Use the OpenTelemetry SDK and the OTLP exporter for your language.
  2. Configure the OpenTelemetry collector to send OTLP traces to Google Cloud.
Logs

Configure your app to output JSON-structured logs to stdout and stderr. For a list of frameworks, see Recommended logging frameworks.

GKE collects logs written to stdout and stderr automatically. For more information, see About GKE logs.

Compute Engine

For general information about Compute Engine, see Virtual machine instances.

Type Recommendation
Metrics and Traces

Do the following:

  1. Use the OpenTelemetry SDK and the OTLP exporter for your language.
  2. Use the Ops Agent to collect metrics and traces. For an example, see Collect OpenTelemetry Protocol (OTLP) metrics and traces.

Alternatively, if you only want to configure collection for Prometheus-format metrics, you can use the Ops Agent Prometheus Receiver to collect metrics instrumented using Prometheus client libraries or the OpenTelemetry SDK.

Logs

Do the following:

  1. Configure your app to output JSON-structured logs to a file. For a list of frameworks, see Recommended logging frameworks.
  2. Install the Ops Agent and configure a receiver. For an example, see Logging receivers.

Cloud Run

For general information about Cloud Run, see What is Cloud Run.

Type Recommendation
Metrics and Traces

Do the following:

  1. Use the OpenTelemetry SDK and the OTLP exporter for your language.
  2. Configure the OpenTelemetry sidecar to collect metrics and traces. For an example, see Write OTLP metrics by using an OpenTelemetry sidecar.

Alternatively, if you only want to configure collection for Prometheus-format metrics, you can use the Prometheus sidecar for Cloud Run to collect metrics instrumented using Prometheus client libraries or the OpenTelemetry SDK.

Logs

Configure your app to output JSON-structured logs to stdout and stderr. For a list of frameworks, see Recommended logging frameworks.

Cloud Run collects logs written to stdout and stderr automatically. For more information, see Write container logs.

Cloud Functions

For general information about Cloud Functions, see Cloud Functions overview.

Type Recommendation
Metrics Direct writing of metrics is not supported in Cloud Functions. To generate metrics, we recommend you use log-based metrics.
Traces Use the SDK and the Cloud Trace exporter for your language.
Logs

Configure your app to output JSON-structured logs to stdout and stderr. For a list of frameworks, see Recommended logging frameworks.

Cloud Functions collects logs written to stdout and stderr automatically. For more information, see View and write Cloud Function logs.

App Engine

For general information about App Engine, see An overview of App Engine.

Type Recommendation
Metrics Use the SDK and the Cloud Monitoring exporter for your language.
Traces Use the SDK and the Cloud Trace exporter for your language.
Logs

Configure your app to output JSON-structured logs to stdout and stderr. For a list of frameworks, see Recommended logging frameworks.

App Engine collects logs written to stdout and stderr automatically. For more information, see Writing and viewing logs.

Recommended logging frameworks

To collect logs, we recommend that you use a framework which can be configured to output serialized JSON objects to stdout, stderr, or to a file. The logging agent, whether integrated or installed, scrapes the file and writes structured logs for Cloud Logging. For writing log data, we recommend the following:

Code samples

For code samples that illustrate how to instrument your application to send telemetry to Google Cloud, see the following:

References to OpenTelemetry

This section provides links to the OpenTelemetry SDK, and the exporters for OTLP, Cloud Trace, and Cloud Monitoring.

General references:

Go

Java

JavaScript

Python