이 페이지는 아직 영어로 제공되지 않습니다. 번역 작업 중입니다.
현재 번역 프로젝트에 대한 질문이나 피드백이 있으신 경우 언제든지 연락주시기 바랍니다.

Overview

If you are running multiple containers per Google Cloud Run application, Datadog recommends using the Datadog sidecar: Instrument Google Cloud Run.

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 Google Cloud integration. Datadog also provides a solution for instrumenting your Cloud Run applications with a purpose-built Agent to enable tracing, custom metrics, and direct log collection.

Prerequisites

Make sure you have a Datadog API key and are using a programming language supported by a Datadog tracing library.

Instrument your application

You can instrument your application in one of two ways: Dockerfile or buildpack.

Dockerfile

Datadog publishes new releases of the serverless-init container image to Google’s gcr.io, AWS’s ECR, and on Docker Hub:

dockerhub.iogcr.iopublic.ecr.aws
datadog/serverless-initgcr.io/datadoghq/serverless-initpublic.ecr.aws/datadog/serverless-init

Images are tagged based on semantic versioning, with each new version receiving three relevant tags:

  • 1, 1-alpine: use these to track the latest minor releases, without breaking changes
  • 1.x.x, 1.x.x-alpine: use these to pin to a precise version of the library
  • latest, latest-alpine: use these to follow the latest version release, which may include breaking changes

How serverless-init works

The serverless-init application wraps your process and executes it as a subprocess. It starts a DogStatsD listener for metrics and a Trace Agent listener for traces. It collects logs by wrapping the stdout/stderr streams of your application. After bootstrapping, serverless-init then launches your command as a subprocess.

To get full instrumentation, ensure you are calling datadog-init as the first command that runs inside your Docker container. You can do this through by setting it as the entrypoint, or by setting it as the first argument in CMD.

애플리케이션을 배포하기 전에 Go 트레이서를 수동으로 설치하세요. Dockerfile에 다음 지침과 인수를 추가합니다.

COPY --from=datadog/serverless-init:1 /datadog-init /app/datadog-init
ENTRYPOINT ["/app/datadog-init"]
ENV DD_SERVICE=datadog-demo-run-go
ENV DD_ENV=datadog-demo
ENV DD_VERSION=1
CMD ["/path/to/your-go-binary"]

설명

  1. Docker 이미지에 Datadog serverless-init을 복사합니다.

    COPY --from=datadog/serverless-init:1 /datadog-init /app/datadog-init
    
  2. Datadog serverless-init 프로세스에서 애플리케이션을 래핑하도록 엔트리 포인트를 변경합니다. 참고: Dockerfile에 이미 정의된 엔트리 포인트가 있는 경우 대체 구성 방법을 참고하세요.

    ENTRYPOINT ["/app/datadog-init"]
    
  3. (선택사항) Datadog 태그를 추가합니다.

    ENV DD_SERVICE=datadog-demo-run-go
    ENV DD_ENV=datadog-demo
    ENV DD_VERSION=1
    
  4. 엔트리 포인트에 래핑된 이진 애플리케이션을 실행합니다. 상황에 맞게 명령줄을 수정하세요.

    CMD ["/path/to/your-go-binary"]
    

대체 구성 방법

Dockerfile에 이미 정의된 엔트리 포인트가 있는 경우 대신 CMD 인수를 수정할 수 있습니다.

COPY --from=datadog/serverless-init:1 /datadog-init /app/datadog-init
ENV DD_SERVICE=datadog-demo-run-go
ENV DD_ENV=datadog-demo
ENV DD_VERSION=1
CMD ["/app/datadog-init", "/path/to/your-go-binary"]

엔트리 포인트도 계측해야 하는 경우 엔트리 포인트와 CMD 인수를 맞바꿀 수 있습니다. 자세한 정보는 serverless-init이 작동하는 방식을 참고하세요.

COPY --from=datadog/serverless-init:1 /datadog-init /app/datadog-init
ENV DD_SERVICE=datadog-demo-run-go
ENV DD_ENV=datadog-demo
ENV DD_VERSION=1
ENTRYPOINT ["/app/datadog-init"]
CMD ["your_entrypoint.sh", "/path/to/your-go-binary"]

실행할 명령이 datadog-init 인수로 전달되는 한, 전체 계측을 받을 수 있습니다.

참고: Go 코드를 자동으로 계측하는 도구인 Orchestrion을 사용할 수도 있습니다. Orchestrion은 비공개 베타 버전입니다. 자세한 내용을 보려면 Orchestrion 리포지토리에서 GitHub 이슈를 열거나 지원팀에 문의하세요.

Buildpack

Pack Buildpacks provide a convenient way to package your container without using a Dockerfile.

First, manually install your tracer:

Then, build your application by running the following command:

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

Note: Buildpack instrumentation is not compatible with Alpine images.

Configure your application

Once the container is built and pushed to your registry, the last step is to set the required environment variables for the Datadog Agent:

  • DD_API_KEY: Datadog API key, used to send data to your Datadog account. It should be configured as a Google Cloud Secret for privacy and safety.
  • DD_SITE: Datadog endpoint and website. Select your site on the right side of this page. Your site is: datadoghq.com.

For more environment variables and their function, see Environment Variables.

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.

shell
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 \

See all arguments and flags for gcloud run deploy.

Results

Once the deployment is completed, your metrics and traces are sent to Datadog. In Datadog, navigate to Infrastructure > Serverless to see your serverless metrics and traces.

Additional configurations

  • Advanced Tracing: The Datadog Agent already provides some basic tracing for popular frameworks. Follow the advanced tracing guide for more information.

  • Logs: If you use the Google Cloud integration, your logs are already being collected. Alternatively, you can set the DD_LOGS_ENABLED environment variable to true to capture application logs through the serverless instrumentation directly.

  • Custom Metrics: You can submit custom metrics using a DogStatsD client. For monitoring Cloud Run and other serverless applications, use distribution metrics. Distributions provide avg, sum, max, min, and count aggregations by default. On the Metric Summary page, you can enable percentile aggregations (p50, p75, p90, p95, p99) and also manage tags. To monitor a distribution for a gauge metric type, use avg for both the time and space aggregations. To monitor a distribution for a count metric type, use sum for both the time and space aggregations.

Environment Variables

VariableDescription
DD_API_KEYDatadog API key - Required
DD_SITEDatadog site - Required
DD_LOGS_ENABLEDWhen true, send logs (stdout and stderr) to Datadog. Defaults to false.
DD_LOGS_INJECTIONWhen true, enrich all logs with trace data for supported loggers in Java, Node, .NET, and PHP. See additional docs for Python, Go, and Ruby.
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.

Troubleshooting

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

Further reading

PREVIEWING: drodriguezhdez/add_public_docs_log_summarization