Stay organized with collections
Save and categorize content based on your preferences.
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.
Ensure that you configure the OpenTelemetry collector to
report OTLP metrics to Managed Service for Prometheus. For more
information, see
Get
started with the OpenTelemetry Collector.
Set the CPU to be always-allocated in Cloud Run. Because
OpenTelemetry instrumentation does background processing, we recommend
that instrumented Cloud Run services use an
always-allocated CPU; for more information, see
CPU allocation
(services).
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:
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-29 UTC."],[],[],null,["# Choose an instrumentation approach\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nThis page contains recommendations for instrumenting your app on different\nGoogle Cloud platforms, such as Google Kubernetes Engine (GKE) and\nCloud Run. If your app isn't already instrumented,\nthen use these recommendations for guidance as to how to instrument your\napp to send telemetry data to Google Cloud.\nThe recommendations on this page aren't the only solutions, and other\napproaches can work. For additional guidance,\ncontact [Google Cloud Support](/support).\n\nThere are recommendations for the following:\n\n- [GKE](#containers)\n- [Compute Engine](#instances)\n- [Cloud Run](#run)\n- [Cloud Run functions](#functions)\n- [App Engine](#app_engine)\n- [Logging frameworks](#logging-frameworks)\n\nFor information about instrumentation examples, see the documents listed in the\n[Code samples](#samples) section.\n\nGKE\n---\n\nFor general information about GKE, see\n[GKE overview](/kubernetes-engine/docs/concepts/kubernetes-engine-overview).\n\nCompute Engine\n--------------\n\nFor general information about Compute Engine, see\n[Virtual machine instances](/compute/docs/instances).\n\nCloud Run\n---------\n\nFor general information about Cloud Run, see\n[What is Cloud Run](/run/docs/overview/what-is-cloud-run).\n\nCloud Run functions\n-------------------\n\nFor general information about Cloud Run functions, see\n[Cloud Run functions overview](/functions/docs/concepts/overview).\n\nApp Engine\n----------\n\nFor general information about App Engine, see\n[An overview of App Engine](/appengine/docs/an-overview-of-app-engine).\n\nRecommended logging frameworks\n------------------------------\n\nTo collect logs, we recommend that you use a framework which can be\nconfigured to output serialized JSON objects to `stdout`, `stderr`, or to a\nfile. The logging agent, whether integrated or installed, scrapes the file\nand writes [structured logs for Cloud Logging](/logging/docs/structured-logging).\nFor writing log data, we recommend the following:\n\n- Go: [`slog`](https://pkg.go.dev/log/slog).\n- Python: [`logging`](https://docs.python.org/3/library/logging.html).\n- JavaScript: [Pino](https://getpino.io/).\n- Java: [SLF4J](https://www.slf4j.org/) with [Log4j2](https://logging.apache.org/log4j/2.x/).\n\nCode samples\n------------\n\nFor code samples that illustrate how to instrument your application to\nsend telemetry to Google Cloud, see the following:\n\n- [Sample overview](/stackdriver/docs/instrumentation/setup/sample-overview).\n- [Go instrumentation sample](/stackdriver/docs/instrumentation/setup/go).\n- [Java instrumentation sample](/stackdriver/docs/instrumentation/setup/java).\n- [Node.js instrumentation sample](/stackdriver/docs/instrumentation/setup/nodejs).\n- [Python instrumentation sample](/stackdriver/docs/instrumentation/setup/python).\n\nReferences to OpenTelemetry\n---------------------------\n\nThis section provides links to the OpenTelemetry SDK, and the exporters for\nOTLP, Cloud Trace, and Cloud Monitoring.\n\nGeneral references:\n\n- [Language APIs \\& SDKs](https://opentelemetry.io/docs/languages/)\n- [OTLP exporter](https://opentelemetry.io/docs/specs/otel/protocol/exporter/)\n\n### Go\n\n- [Go SDK](https://opentelemetry.io/docs/languages/go/)\n- [Go OTLP exporter](https://opentelemetry.io/docs/languages/go/exporters/#otlp)\n- [Go Cloud Trace exporter](https://github.com/GoogleCloudPlatform/opentelemetry-operations-go/blob/main/exporter/trace)\n- [Go Cloud Monitoring exporter](https://github.com/GoogleCloudPlatform/opentelemetry-operations-go/tree/main/exporter/metric)\n\n### Java\n\n- [Java SDK](https://opentelemetry.io/docs/languages/java/)\n- [Java OTLP exporter](https://opentelemetry.io/docs/languages/java/configuration/#properties-exporters)\n- [Java Cloud Trace exporter](https://github.com/GoogleCloudPlatform/opentelemetry-operations-java/blob/main/exporters/trace)\n- [Java Cloud Monitoring exporter](https://github.com/GoogleCloudPlatform/opentelemetry-operations-java/tree/main/exporters/metrics)\n\n### JavaScript\n\n- [JavaScript SDK](https://opentelemetry.io/docs/languages/js/)\n- [JavaScript OTLP exporter](https://opentelemetry.io/docs/languages/js/exporters/#otlp)\n- [JavaScript Cloud Trace exporter](https://github.com/GoogleCloudPlatform/opentelemetry-operations-js/tree/main/packages/opentelemetry-cloud-trace-exporter)\n- [JavaScript Cloud Monitoring exporter](https://github.com/GoogleCloudPlatform/opentelemetry-operations-js/tree/main/packages/opentelemetry-cloud-monitoring-exporter)\n\n### Python\n\n- [Python SDK](https://opentelemetry.io/docs/languages/python/)\n- [Python OTLP exporter](https://opentelemetry.io/docs/languages/python/exporters/)\n- [Python Cloud Trace exporter](https://github.com/GoogleCloudPlatform/opentelemetry-operations-python/tree/main/opentelemetry-exporter-gcp-trace)\n- [Python Cloud Monitoring exporter](https://github.com/GoogleCloudPlatform/opentelemetry-operations-python/tree/main/opentelemetry-exporter-gcp-monitoring)"]]