As long as your command to run is passed as an argument to datadog-init, you will receive full instrumentation.
Configurez les logs.
Pour activer la journalisation, définissez la variable d’environnement DD_LOGS_ENABLED=true. Cela permet à serverless-init de lire les logs depuis stdout et stderr.
Datadog recommande également de définir les variables d’environnement DD_LOGS_INJECTION=true et DD_SOURCE=nodejs pour activer le parsing avancé des logs Datadog.
Si vous souhaitez que les logs multilignes soient conservés dans un seul message de log, Datadog recommande d’écrire vos logs au format JSON. Par exemple, vous pouvez utiliser une bibliothèque de journalisation tierce telle que 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).
Do not set the following environment variables in your serverless environment. They should only be set in non-serverless environments.
DD_AGENT_HOST
DD_TRACE_AGENT_URL
Traçage distribué avec Pub/Sub
To get end-to-end distributed traces between Pub/Sub producers and Cloud Run, 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 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.
If you are using request-based billing for a Google Cloud Run application instrumented in-container, very short requests may lead to dropped logs during the post-request CPU throttling. You can control the speed at which logs are sent to Datadog using the DD_LOGS_CONFIG_BATCH_WAIT environment variable. Set DD_LOGS_CONFIG_BATCH_WAIT to a value shorter than your typical request duration to avoid dropped logs. Sidecar instrumentation also prevents this issue, as the sidecar is not affected by request-based CPU throttling.
Pour aller plus loin
Documentation, liens et articles supplémentaires utiles: