Azure App Service - Linux Code

Overview

To instrument your Azure App Service with the Datadog wrapper instead of using a sidecar, see Instrument Azure App Service - Linux Code Deployment with the Datadog wrapper.

This instrumentation method provides the following additional monitoring capabilities for 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.
  • Support for submitting logs using file tailing.

This solution uses a sidecar container and Application Settings for Linux Azure App Service to instrument the application and manage its configuration.

Supported runtimes: Java, Node.js, .NET, PHP, Python

Setup

  1. Install a tracing library. You must install a tracing library within the application package prior to deployment.

Java supports adding instrumentation code through the use of a command line argument, javaagent.

  1. Download the latest version of Datadog’s Java tracing library.
  2. Place the tracing library inside your project. It must be included with your deployment. If you are using the azure-webapp-maven plugin, you can add the Java tracing library as a resource entry with type lib.
  3. Set the environment variable JAVA_OPTS with --javaagent:/home/site/lib/dd-java-agent.jar. When your application is deployed, the Java tracer is copied to /home/site/lib/dd-java-agent.jar.

Instrumentation starts when the application is launched.

  1. Add the ddtrace package to your project using your package manager.
  2. Initialize the tracer by doing one of the following:
    • Set NODE_OPTIONS with --require=dd-trace/init
    • Include the tracer in your application’s entrypoint file:
      const tracer = require('dd-trace').init({ logInjection: true, });
      
      This also configures trace log correlation.

Add the Datadog.Trace.Bundle Nuget package to your project.

Note: When you complete Step 2, ensure that you also set the additional environment variables required by the .NET tracer.

Run the following script to install Datadog’s PHP tracing library:

#!/usr/bin/env bash

echo "Setting up Datadog tracing for PHP"
DD_PHP_TRACER_VERSION=1.8.3

    DD_PHP_TRACER_URL=https://github.com/DataDog/dd-trace-php/releases/download/${DD_PHP_TRACER_VERSION}/datadog-setup.php

echo "Installing PHP tracer from ${DD_PHP_TRACER_URL}"
if curl -LO --fail "${DD_PHP_TRACER_URL}"; then
eval "php datadog-setup.php --php-bin=all"
else
       echo "Downloading the tracer was unsuccessful"
       return
fi

cp /home/site/wwwroot/default /etc/nginx/sites-available/default && service nginx reload

This script is intended to run as the startup command, which installs the tracing module into PHP and then restarts the application.

  1. Add ddtrace to your project.

  2. Modify your startup command. Your new command should run ddtrace-run with your old command as an argument. That is: if your startup command is foo, modify it to run ddtrace-run foo.

    For example:

    ddtrace-run gunicorn --bind=0.0.0.0 --timeout 600 quickstartproject.wsgi
    
  1. Configure environment variables. In Azure, add the following key-value pairs in Settings > Configuration > Application settings:
NameValueDescription
DD_API_KEYYour Datadog API key.See Organization Settings > API Keys in Datadog.
DD_SITEYour Datadog site. Defaults to datadoghq.com.
DD_SERVICEYour application’s service name.Defaults to the name field value in package.json.

For .NET applications, the following environment variables are required unless otherwise specified:

NameValueDescription
DD_DOTNET_TRACER_HOME/home/site/wwwroot/datadogPath to tracing libraries, copied within the Docker file
DD_TRACE_LOG_DIRECTORY/home/Logfiles/dotnetWhere tracer logs are stored
CORECLR_ENABLE_PROFILING1Instructs the .NET CLR that profiling should be enabled.
CORECLR_PROFILER846F5F1C-F9AE-4B07-969E-05C26BC060D8Profiler GUID.
CORECLR_PROFILER_PATH/home/site/wwwroot/datadog/linux-musl-x64/Datadog.Trace.ClrProfiler.Native.soThe profiler binary that the .NET CLR loads into memory, which contains the GUID.
DD_PROFILING_ENABLED (optional)trueEnables Datadog’s Continuous Profiler.
  1. Configure a sidecar container for Datadog.

    1. In Azure, navigate to Deployment > Deployment Center. Select the Containers tab.
    2. Click Add and select Custom container.
    3. In the Edit container form, provide the following:
      • Image source: Other container registries
      • Image type: Public
      • Registry server URL: index.docker.io
      • Image and tag: datadog/serverless-init:latest
      • Port: 8126
    4. Select Apply.
  2. Restart your application.

    If you modified a startup command, restart your application. Azure automatically restarts the application when new Application Settings are saved.

View traces in Datadog

After your application restarts, go to Datadog’s APM Service page and search for the service name you set for your application (DD_SERVICE).

Custom metrics

To configure your application to submit custom metrics, follow the appropriate steps for your runtime:

Deployment

To update your Datadog instrumentation with zero downtime, use deployment slots. You can create a workflow that uses GitHub Action for Azure CLI.

See the sample GitHub workflow.

Troubleshooting

If you are not receiving traces or custom metric data as expected, enable agent debug logging by setting DD_LOG_LEVEL in the sidecar configuration options. For tracer debugging set DD_TRACE_DEBUG to true. This generates logs additional debug logs for the sidecar and tracing library.

Be sure to enable App Service logs to receive debugging logs.

Azure App Service Configuration: App Service logs, under the Monitoring section of Settings in the Azure UI. The 'Application logging' option is set to 'File System'.

Share the content of the Log stream with Datadog Support.

Further reading

Additional helpful documentation, links, and articles:

PREVIEWING: domalessi/docs-10698-di-toc