As long as your command to run is passed as an argument to datadog-init, you will receive full instrumentation.
Set up logs.
To enable logging, set the environment variable DD_LOGS_ENABLED=true. This allows serverless-init to read logs from stdout and stderr.
Datadog also recommends setting the environment variable DD_LOGS_INJECTION=true and DD_SOURCE=nodejs to enable advanced Datadog log parsing.
If you want multiline logs to be preserved in a single log message, Datadog recommends writing your logs in JSON format. For example, you can use a third-party logging library such as winston:
The following command deploys the service and allows any external connection to reach it. In this example, your service listening is set to port 8080. Ensure that this port number matches the exposed port inside of your Dockerfile.
gcloud run deploy <APP_NAME>
--image=gcr.io/<YOUR_PROJECT>/<APP_NAME> \
--port=8080\
--update-env-vars=DD_API_KEY=$DD_API_KEY\
--update-env-vars=DD_SITE=$DD_SITE\
Add a service label in Google Cloud. In your Cloud Run service’s info panel, add a label with the following key and value:
Key
Value
service
The name of your service. Matches the value provided as the DD_SERVICE environment variable.
Set the log source to enable a Log Pipeline for advanced parsing. To automatically apply language-specific parsing rules, set to nodejs, or use your custom pipeline. Defaults to cloudrun.
DD_TAGS
Add custom tags to your logs, metrics, and traces. Tags should be comma separated in key/value format (for example: key1:value1,key2:value2).
Distributed tracing with Pub/Sub
To get end-to-end distributed traces between Pub/Sub producers and Cloud Run services, configure your push subscriptions with the --push-no-wrapper and --push-no-wrapper-write-metadata flags. This moves message attributes from the JSON body to HTTP headers, allowing Datadog to extract producer trace context and create proper span links.
Eventarc Pub/Sub triggers use push subscriptions as the underlying delivery mechanism. When you create an Eventarc trigger, GCP automatically creates a managed push subscription. However, Eventarc does not expose --push-no-wrapper-write-metadata as a trigger creation parameter, so you must manually update the auto-created subscription.
This integration depends on your runtime having a full SSL implementation. If you are using a slim image, you may need to add the following command to your Dockerfile to include certificates:
RUN apt-get update && apt-get install -y ca-certificates
To have your Cloud Run services appear in the software catalog, you must set the DD_SERVICE, DD_VERSION, and DD_ENV environment variables.
Further reading
Additional helpful documentation, links, and articles: