Instrument Azure App Service with serverless-init - Linux Containers

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

Overview

To instrument your Azure App Service containers with a sidecar, see Instrument Azure App Service.

This instrumentation method uses serverless-init and provides the following additional monitoring capabilities for containerized Linux Azure App Service workloads:

  • Fully distributed APM tracing using automatic instrumentation.
  • Customized APM service and trace views showing relevant Azure App Service metrics and metadata.
  • Support for manual APM instrumentation to customize spans.
  • Trace_ID injection into application logs.
  • Support for submitting custom metrics using DogStatsD.

Prerequisites

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

Instrument your application

Dockerfile

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

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

Dockerfile에 다음 명령과 인수를 추가하세요.

COPY --from=datadog/serverless-init:1 /datadog-init /app/datadog-init
ADD https://github.com/DataDog/dd-trace-php/releases/latest/download/datadog-setup.php /datadog-setup.php
RUN php /datadog-setup.php --php-bin=all
ENV DD_SERVICE=datadog-demo-run-php
ENV DD_ENV=datadog-demo
ENV DD_VERSION=1
ENTRYPOINT ["/app/datadog-init"]

# Apache 및 mod_php 기반 이미지에 다음을 사용하세요
RUN sed -i "s/Listen 80/Listen 8080/" /etc/apache2/ports.conf
EXPOSE 8080
CMD ["apache2-foreground"]

# Nginx 및 php-fpm 기반 이미지에 다음을 사용하세요
RUN ln -sf /dev/stdout /var/log/nginx/access.log && ln -sf /dev/stderr /var/log/nginx/error.log
EXPOSE 8080
CMD php-fpm; nginx -g daemon off;

참고: datadog-init 엔트리 포인트는 프로세스를 래핑한 후 로그를 수집합니다. 로그가 제대로 작동하려면 Apache, Nginx, 또는 PHP 프로세스가 출력을 stdout로 보내야 합니다.

설명

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

    COPY --from=datadog/serverless-init:1 /datadog-init /app/datadog-init
    
  2. Datadog PHP 트레이서를 복사하고 설치합니다.

    ADD https://github.com/DataDog/dd-trace-php/releases/latest/download/datadog-setup.php /datadog-setup.php
    RUN php /datadog-setup.php --php-bin=all
    

    수동 트레이서 계측 방법에 안내된 대로 애플리케이션에 바로 Datadog 트레이서 라이브러리를 설치하는 경우에는 이 단계를 건너뛰세요.

  3. (선택사항) Datadog 태그를 추가합니다.

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

    ENTRYPOINT ["/app/datadog-init"]
    
  5. 애플리케이션을 실행합니다.

    Apache 및 mod_php 기반 이미지에는 다음을 사용하세요.

    RUN sed -i "s/Listen 80/Listen 8080/" /etc/apache2/ports.conf
    EXPOSE 8080
    CMD ["apache2-foreground"]
    

    Nginx와 php-fpm 기반 이미지에는 다음을 사용하세요.

    RUN ln -sf /dev/stdout /var/log/nginx/access.log && ln -sf /dev/stderr /var/log/nginx/error.log
    EXPOSE 8080
    CMD php-fpm; nginx -g daemon off;
    

대체 구성: CMD 인수

Dockerfile에 이미 정의된 엔트리 포인트가 있고 Apache와 mod_php 기반 이미지를 사용하는 중이라면, 대신 CMD 인수를 수정할 수 있습니다.

COPY --from=datadog/serverless-init:1 /datadog-init /app/datadog-init
ADD https://github.com/DataDog/dd-trace-php/releases/latest/download/datadog-setup.php /datadog-setup.php
RUN php /datadog-setup.php --php-bin=all
ENV DD_SERVICE=datadog-demo-run-php
ENV DD_ENV=datadog-demo
ENV DD_VERSION=1
RUN sed -i "s/Listen 80/Listen 8080/" /etc/apache2/ports.conf
EXPOSE 8080
CMD ["/app/datadog-init", "apache2-foreground"]

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

COPY --from=datadog/serverless-init:1 /datadog-init /app/datadog-init
ADD https://github.com/DataDog/dd-trace-php/releases/latest/download/datadog-setup.php /datadog-setup.php
RUN php /datadog-setup.php --php-bin=all
ENV DD_SERVICE=datadog-demo-run-php
ENV DD_ENV=datadog-demo
ENV DD_VERSION=1
ENTRYPOINT ["/app/datadog-init"]

# Apache 및 mod_php 기반 이미지에 다음을 사용하세요
RUN sed -i "s/Listen 80/Listen 8080/" /etc/apache2/ports.conf
EXPOSE 8080
CMD ["your_entrypoint.sh", "apache2-foreground"]

# Nginx 및 php-fpm 기반 이미지에 다음을 사용하세요
RUN ln -sf /dev/stdout /var/log/nginx/access.log && ln -sf /dev/stderr /var/log/nginx/error.log
EXPOSE 8080
CMD your_entrypoint.sh php-fpm; your_entrypoint.sh nginx -g daemon off;

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

2. 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 an Azure 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.
  • DD_TRACE_ENABLED: Set to true to enable tracing.

For more environment variables and their function, see Additional Configurations.

3. 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.

Deployment

Datadog 계측을 제로 다운타임으로 업데이트하려면 배포 슬롯을 사용합니다. Azure CLI용 GitHub Action을 활용하는 워크플로우를 생성할 수 있습니다.

샘플 GitHub 워크플로우를 참조하세요.

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 Azure 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.

  • Trace Sampling: To manage the APM traced request sampling rate for serverless applications, set the DD_TRACE_SAMPLE_RATE environment variable on the function to a value between 0.000 (no tracing of Container App requests) and 1.000 (trace all Container App requests).

Metrics are calculated based on 100% of the application’s traffic, and remain accurate regardless of any sampling configuration.

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.js, .NET, and PHP. See additional docs for Python, Go, and Ruby.
DD_TRACE_SAMPLE_RATEControls the trace ingestion sample rate between 0.0 and 1.0.
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

If you are not receiving traces or custom metric data as expected, enable App Service logs to receive debugging logs.

Share the content of the Log stream with Datadog Support.

Further reading

PREVIEWING: watson/nodejs-docs-update