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

Setup

A sample application is available on GitHub.
  1. Install the Datadog PHP tracer in your Dockerfile.

    Dockerfile

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

    When running the datadog-setup.php script, you can also enable Application Security and Profiling by using the --enable-appsec and --enable-profiling flags, respectively.

    If you are using Alpine Linux, you need to install libgcc_s prior to running the installer:

    apk add libgcc

    For more information, see Tracing PHP applications.

  2. Install serverless-init.

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

    hub.docker.comgcr.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

    Add the following instructions and arguments to your Dockerfile.

    COPY --from=datadog/serverless-init:1 /datadog-init /app/datadog-init
    ENTRYPOINT ["/app/datadog-init"]
    CMD ["apache2-foreground"]
    

    Datadog expects serverless-init to be the top-level application, with the rest of your app’s command line passed in for serverless-init to execute.

    If you already have an entrypoint defined inside your Dockerfile, you can instead modify the CMD argument.

    CMD ["/app/datadog-init", "apache2-foreground"]
    

    If you require your entrypoint to be instrumented as well, you can instead swap your entrypoint and CMD arguments.

    ENTRYPOINT ["/app/datadog-init"]
    CMD ["/your_entrypoint.sh", "apache2-foreground"]
    

    As long as your command to run is passed as an argument to datadog-init, you will receive full instrumentation.


  3. 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_SOURCE=php to enable advanced Datadog log parsing.

    For more information, see Correlating PHP Logs and Traces.

  4. Configure your application.

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

    • DD_API_KEY: Your Datadog API key, used to send data to your Datadog account. For privacy and safety, configure this API key as a Google Cloud Secret.
    • DD_SITE: Your Datadog site. For example, datadoghq.com.

    For more environment variables, see the Environment variables section on this page.

    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 \
    
  5. Finally, add a service label in Google Cloud. In your Cloud Run service’s info panel, add a label with the following key and value:

    KeyValue
    serviceThe name of your service. Matches the value provided as the DD_SERVICE environment variable.

    See Configure labels for services in the Cloud Run documentation for instructions.

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. See Correlate Logs and Traces for more information.
DD_SERVICESee Unified Service Tagging. Recommended
DD_VERSIONSee Unified Service Tagging. Recommended
DD_ENVSee Unified Service Tagging. Recommended
DD_SOURCESet the log source to enable a Log Pipeline for advanced parsing. To automatically apply language-specific parsing rules, set to php, or use your custom pipeline. Defaults to cloudrun.
DD_TAGSAdd custom tags to your logs, metrics, and traces. Tags should be comma separated in key/value format (for example: key1:value1,key2:value2).

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

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