Google Cloud Functions monitoring with traces and metrics
by Obseria · Cloud platforms- OpenTelemetry
- Application Observability
- Cloud platforms
- Category
- Cloud platforms
- Key metrics
- 9
- Ready-made
- 5 dashboards & alerts
- Setup
- 3 steps
- Standard
- OTLP
Instrument your functions with the OpenTelemetry SDK and pull execution metrics from Cloud Monitoring: Obseria shows every invocation, its dependencies and how each function scales.
Standard OpenTelemetry SDKs
Node.js, Python, Java and Go functions use the regular OpenTelemetry SDKs and export over OTLP; the GCP resource detector adds project and region.
Platform metrics without code
The Collector's googlecloudmonitoring receiver reads execution count, execution times and active instances with a Monitoring Viewer service account.
Errors traced to their cause
Obseria Intelligence connects failing executions with the deploy, the slow downstream call or the exception behind them and shows the evidence.
Obseria interface



Ready the moment data arrives
- Functions overview: executions, errors, execution time
- Active instances and scaling per function
- Alert on error status share per function
- Alert on execution time approaching the timeout
- Startup latency and cold starts for 2nd gen functions
What Obseria monitors in Google Cloud Functions
HTTP functions
A server span per request with route, status code and duration, plus all outbound calls as child spans.
Event-driven functions
Pub/Sub, Cloud Storage and Eventarc triggers, with trace context carried in message attributes where you propagate it.
Outbound dependencies
HTTP calls, Firestore, Cloud SQL and other client libraries as spans, through the language's auto-instrumentation.
Execution metrics
Execution count by status, execution time distribution and active instances from Cloud Monitoring.
Cloud Run functions
2nd gen functions run on Cloud Run, so request, latency, instance and startup metrics from Cloud Run apply as well.
Errors and logs
Exceptions recorded on spans and function logs correlated with traces by trace ID.
The Cloud Functions signals that matter
Obseria collects these values automatically and shows them in ready-made dashboards and alerts.
| Metric | Unit | What it tells you |
|---|---|---|
cloudfunctions.googleapis.com/function/execution_count | Count | Executions per function, split by status, the basis for error rates. |
cloudfunctions.googleapis.com/function/execution_times | ns | Distribution of execution time per function; watch the upper percentiles against the timeout. |
cloudfunctions.googleapis.com/function/active_instances | Count | Instances currently running, to see how a function scales under load. |
cloudfunctions.googleapis.com/function/user_memory_bytes | Bytes | Memory used by the function, compared with its configured memory. |
cloudfunctions.googleapis.com/function/network_egress | Bytes | Outgoing network traffic per function. |
run.googleapis.com/request_count | Count | Requests served by a 2nd gen function's underlying Cloud Run service, by response code class. |
run.googleapis.com/request_latencies | ms | Request latency distribution for 2nd gen functions. |
run.googleapis.com/container/instance_count | Count | Container instances by state, to spot scaling limits and idle capacity. |
run.googleapis.com/container/startup_latencies | ms | Time to start a new container instance, the direct cost of a cold start. |
Set up Cloud Functions monitoring in minutes
- 1
Add the OpenTelemetry SDK
Install the SDK, auto-instrumentations, OTLP exporter and GCP resource detector for your runtime and load them before the function code.
- 2
Set the export variables
Deploy the function with OTEL_SERVICE_NAME, OTEL_EXPORTER_OTLP_ENDPOINT and OTEL_EXPORTER_OTLP_HEADERS pointing at Obseria.
- 3
Add platform metrics
Run the OpenTelemetry Collector with the googlecloudmonitoring receiver and a service account with Monitoring Viewer for execution metrics.
// tracing.js: required as the first line of index.js
const { NodeSDK } = require("@opentelemetry/sdk-node");
const { getNodeAutoInstrumentations } = require("@opentelemetry/auto-instrumentations-node");
const { OTLPTraceExporter } = require("@opentelemetry/exporter-trace-otlp-http");
const { gcpDetector } = require("@opentelemetry/resource-detector-gcp");
// Endpoint and token come from OTEL_EXPORTER_OTLP_ENDPOINT / _HEADERS
new NodeSDK({
traceExporter: new OTLPTraceExporter(),
instrumentations: [getNodeAutoInstrumentations()],
resourceDetectors: [gcpDetector],
}).start();
// index.js
// require("./tracing");
// const functions = require("@google-cloud/functions-framework");
// functions.http("checkout", async (req, res) => { ... });
// Deploy:
// gcloud functions deploy checkout --gen2 --runtime=nodejs22 \
// --region=europe-west3 --trigger-http --entry-point=checkout \
// --set-env-vars=OTEL_SERVICE_NAME=checkout,\
// OTEL_EXPORTER_OTLP_ENDPOINT=${OBSERIA_OTLP_ENDPOINT},\
// OTEL_EXPORTER_OTLP_HEADERS=Authorization=Bearer%20${OBSERIA_TOKEN}Why Cloud Functions monitoring needs more than logs
Google Cloud Functions runs small pieces of code on demand, triggered by HTTP requests, Pub/Sub messages or events from Cloud Storage and Eventarc. Each function is simple on its own, but together they form workflows where one slow step delays everything after it. Logs alone tell you that something failed, not where the time went or which caller was affected. Cloud Functions monitoring combines execution metrics for every function with traces that follow a request through functions and the services they call.
Since 2024, Google calls the product Cloud Run functions, and 2nd gen functions run on Cloud Run infrastructure. For monitoring that means two sets of platform metrics: the classic cloudfunctions.googleapis.com metrics and, for 2nd gen functions, the run.googleapis.com metrics of the underlying service. Obseria works with both.
How Google Cloud Functions monitoring is set up
- Traces from the SDK: install the OpenTelemetry SDK for your runtime, enable auto-instrumentation for HTTP and client libraries, and add the GCP resource detector so spans carry project, region and function name. The SDK exports over OTLP directly to Obseria, configured with the standard
OTEL_EXPORTER_OTLP_*environment variables. - Metrics from Cloud Monitoring: the OpenTelemetry Collector's
googlecloudmonitoringreceiver reads execution count, execution times and active instances with a service account that has the Monitoring Viewer role. Cloud Monitoring publishes with a delay and bills API reads, so a collection interval of several minutes is a sensible default.
The OpenTelemetry semantic conventions describe function spans with attributes such as faas.trigger, faas.invocation_id and faas.coldstart. Setting them on your server span makes trigger types and cold starts filterable in Obseria.
Metrics that matter for GCP serverless monitoring
- Executions and errors:
execution_countsplit by status gives the error share per function, also for event-driven triggers without an HTTP status. - Execution time:
execution_timesas a distribution shows the slow tail. Compare the upper percentiles with the function's timeout. - Scaling:
active_instancesand, for 2nd gen,run.googleapis.com/container/instance_countshow whether a function hits its maximum instance setting. - Cold starts:
run.googleapis.com/container/startup_latenciesmeasures how long new instances take to start. Large dependencies and heavy initialisation code make it grow. - Memory:
user_memory_bytescompared with the configured memory warns before out-of-memory errors.
Common Cloud Functions problems and how to detect them
Spans that never arrive
Functions can be throttled or frozen once the response has been sent. Spans that are still waiting in the exporter's batch may then be lost. Allocate CPU outside requests for 2nd gen functions, or flush the tracer provider before the function finishes, so telemetry leaves reliably.
Retries and duplicate processing
Event-driven functions with retries enabled run again after a failure. Without traces, repeated executions look like extra load. Error spans with the event ID show which events fail and how often they are retried.
Slow downstream calls
A function that waits on Firestore, Cloud SQL or an external API spends its time, and your money, idling. Child spans make the slow dependency visible immediately.
Scaling limits
When active instances stay at the configured maximum while execution time rises, requests start to queue or fail. Raising the limit or reducing per-request work are the two levers, and the metrics show which one is needed.
Best practices for Cloud Functions tracing
- Load the OpenTelemetry setup before any other module so auto-instrumentation can patch libraries.
- Set
OTEL_SERVICE_NAMEper function andservice.versionper deployment. - Propagate trace context through Pub/Sub message attributes to connect publishers and subscribers.
- Store the Obseria token in Secret Manager and expose it to the function as an environment variable.
- Restrict the
googlecloudmonitoringreceiver to the metric types you need.
How Obseria helps with Cloud Functions monitoring
Obseria receives traces from your functions over OTLP and platform metrics through the OpenTelemetry Collector, alongside data from the Google Cloud integration. TopoGraph shows which functions call which services, topics and databases. When errors or latency rise, Obseria Intelligence checks deploys, failing dependencies and exceptions and presents the root cause with its chain of evidence. Dashboards, alerts and SLOs are included, EU hosting is available, and all data stays exportable via OTLP.
Learn more
What is APM (application performance monitoring)?
What is APM? Learn how application performance monitoring measures latency, throughput and errors, how distributed tracing works, and which metrics matter.
What is OpenTelemetry?
What is OpenTelemetry? Learn how OTel's APIs, SDKs, Collector, OTLP and semantic conventions produce vendor-neutral traces, metrics, logs and profiles.
Cloud Functions monitoring FAQ
Yes. Cloud Run functions is the current name for Cloud Functions. 2nd gen functions run on Cloud Run, so in addition to the Cloud Functions metrics you can use Cloud Run metrics such as request latency and startup latency.
Any runtime with an OpenTelemetry SDK, including Node.js, Python, Java, Go and .NET. Auto-instrumentation is most complete for Node.js, Python and Java.
Without CPU allocated outside requests, a function may be throttled after it responds, and batched spans may not be exported. Allocate CPU for 2nd gen functions or flush the tracer provider at the end of each invocation.
No. The SDK in the function exports traces directly to Obseria over OTLP. The Collector is only needed to pull platform metrics from Cloud Monitoring with the googlecloudmonitoring receiver.
Yes, if the trace context is written into the message attributes when publishing and extracted in the subscribing function. Then the publishing service and the triggered function appear in one trace.
Start monitoring Cloud Functions today
Connect Cloud Functions in minutes with OpenTelemetry or the Obseria Agent. Free for 14 days.