This guide shows you how to monitor a Go Cloud Function with Atatus Serverless Monitoring using OpenTelemetry (OTel).

Instrument your serverless Cloud Function with OpenTelemetry Go

1

Get your API key

If you need an API key, go to Atatus Dashboard —> Settings —> Account Settings —> API Keys. Generate a new API key, or copy an existing one with write permission. You will set this key in your function’s environment in a later step.
2

Create the function file

Create your Go function file, for example function.go, and add the code below:
function.go
Important: Google Cloud Functions can throttle or freeze the execution environment right after the HTTP handler returns. Calling tracerProvider.ForceFlush(r.Context()) before the function completes exports all pending spans to Atatus before the CPU pauses.
3

Add the package dependencies

Run these commands in your function’s root directory:
4

Set the environment variables

Set your Atatus API key and service name in your function’s deployment environment:
  • ATATUS_API_KEY: <YOUR_ATATUS_API_KEY>
  • ATATUS_APP_NAME: <YOUR_FUNCTION_NAME>
5

Deploy the function

Deploy with the gcloud CLI: