Google Cloud Run

Overview

Google Cloud Run is a fully managed serverless platform for deploying and scaling container-based applications. Datadog provides monitoring and log collection for Cloud Run through the GCP integration. Datadog also provides a solution, now in public beta, for instrumenting your Cloud Run applications with a purpose-built Agent to enable tracing, custom metrics, and direct log collection.

This feature is in public beta. You can provide feedback through a feedback form, or through your standard support channels. During the beta period, Cloud Run monitoring and APM tracing are available without a direct cost. Existing APM customers may incur increased span ingestion and volume costs.

Tracing and custom metrics

Build your container

If you are using a Dockerfile to build your application, complete the following:

  1. Instrument your application with a supported Datadog tracing library

  2. Use the COPY instruction to copy the Datadog serverless-init binary into your Docker image.

  3. Use the ENTRYPOINT instruction to run the serverless-init binary as your Docker container is initiated.

  4. Use the CMD instruction to run your existing application and other required commands as arguments.

The following are examples of how to complete these three steps. You may need to adjust these examples depending on your existing Dockerfile setup.

COPY --from=datadog/serverless-init:beta4 /datadog-init /app/datadog-init
ENTRYPOINT ["/app/datadog-init"]
CMD ["/path/to/your-go-binary"] (adapt this line to your needs)

See Tracing Go Applications for more details. Sample code for a simple Go application.

COPY --from=datadog/serverless-init:beta4 /datadog-init /app/datadog-init
ENTRYPOINT ["/app/datadog-init"]
CMD ["ddtrace-run", "python", "app.py"] (adapt this line to your needs)

See Tracing Python Applications for detailed instructions. Sample code for a simple Python application.

COPY --from=datadog/serverless-init:beta4 /datadog-init /app/datadog-init
ENTRYPOINT ["/app/datadog-init"]
CMD ["/nodejs/bin/node", "/path/to/your/app.js"] (adapt this line to your needs)

See Tracing Node.js Applications for detailed instructions. Sample code for a simple Node.js application.

COPY --from=datadog/serverless-init:beta4 /datadog-init /app/datadog-init
ENTRYPOINT ["/app/datadog-init"]
CMD ["./mvnw", "spring-boot:run"] (adapt this line to your needs)

See Tracing Java Applications for detailed instructions. Sample code for a simple Java application.

COPY --from=datadog/serverless-init:beta4 /datadog-init /app/datadog-init
ENTRYPOINT ["/app/datadog-init"]
CMD ["dotnet", "helloworld.dll"] (adapt this line to your needs)

See Tracing .NET Applications for detailed instructions. Sample code for a simple .NET application.

COPY --from=datadog/serverless-init:beta4 /datadog-init /app/datadog-init
ENTRYPOINT ["/app/datadog-init"]
CMD ["rails", "server", "-b", "0.0.0.0"] (adapt this line to your needs)

See Tracing Ruby Applications for detailed instructions. Sample code for a simple Ruby application.

Troubleshooting

This integration depends on your runtime having a full SSL implementation. If you are using a slim image for Node, you may need to add the following command to your Dockerfile to include certificates.

RUN apt-get update && apt-get install -y ca-certificates

Build with the Datadog buildpack

  1. Use pack to build your application by running the following:

    pack build --builder=gcr.io/buildpacks/builder \
    --buildpack from=builder \
    --buildpack datadog/serverless-buildpack:beta4 \
    gcr.io/YOUR_PROJECT/YOUR_APP_NAME
    

    Note: Not compatible with Alpine.

  2. Push your image to GCP:

    docker push gcr.io/YOUR_PROJECT/YOUR_APP_NAME
    

Deploy to Cloud Run

Below are instructions for deploying a Cloud Run service using standard GCP tools. If you have other systems in place for managing container images, secrets, or deployments, you may use those instead.

  1. Run this command to submit your build to GCP.

    gcloud builds submit --tag gcr.io/YOUR_PROJECT/YOUR_APP_NAME
    
  2. Create a secret from your Datadog API key. Go to Secret Manager in your GCP console and click on Create secret.

    Set a name (for example, datadog-api-key) in the Name field. Then, paste your Datadog API key in the Secret value field.

  3. Deploy your service. Go to Cloud Run in your GCP console. and click on Create service.

    Select Deploy one revision from an existing container image. Choose your previously built image.

    Select your authentication method.

    Reference your previously created secret. Go to the Container, Variables & Secrets, Connections, Security section and select the Variables & Secrets tab.

    Under Secrets, click on Reference a secret and choose the secret you created from your Datadog API key. You may need to grant your user access to the secret.

    Under Reference method, select Exposed as environment variable.

    Under the Environment variables section, ensure that the name is set to DD_API_KEY.

Custom metrics

You can submit custom metrics using a DogStatsd client.

Note: Only DISTRIBUTION metrics should be used.

Advanced options and configurations

Environment variables

VariableDescription
DD_SITEDatadog site.
DD_LOGS_ENABLEDWhen true, send logs (stdout and stderr) to Datadog. Defaults to false.
DD_SERVICESee Unified Service Tagging.
DD_VERSIONSee Unified Service Tagging.
DD_ENVSee Unified Service Tagging.
DD_SOURCESee Unified Service Tagging.
DD_TAGSSee Unified Service Tagging.

Log collection

You can use the GCP integration to collect logs. Alternatively, you can set the DD_LOGS_ENABLED environment variable to true to capture application logs through the Agent.

Further reading

Additional helpful documentation, links, and articles: