|
| 1 | +--- |
| 2 | +title: Azure App Service - Linux |
| 3 | +kind: documentation |
| 4 | +--- |
| 5 | +## Overview |
| 6 | + |
| 7 | +This instrumentation method provides the following additional monitoring capabilities for Linux Azure App Service workloads: |
| 8 | + |
| 9 | +- Fully distributed APM tracing using automatic instrumentation. |
| 10 | +- Customized APM service and trace views showing relevant Azure App Service metrics and metadata. |
| 11 | +- Support for manual APM instrumentation to customize spans. |
| 12 | +- `Trace_ID` injection into application logs. |
| 13 | +- Support for submitting custom metrics using [DogStatsD][1]. |
| 14 | + |
| 15 | +This solution uses the startup command setting and Application Settings for Linux Azure App Service to instrument the application and manage its configuration. Java, Node, .NET, PHP, and Python are supported. |
| 16 | + |
| 17 | +### Setup |
| 18 | +#### Set application settings |
| 19 | +To instrument your application, begin by adding the following key-value pairs under **Application Settings** in your Azure configuration settings. |
| 20 | + |
| 21 | +{{< img src="serverless/azure_app_service/application-settings.jpg" alt="Azure App Service Configuration: the Application Settings, under the Configuration section of Settings in the Azure UI. Three settings are listed: DD_API_KEY, DD_SERVICE, and DD_START_APP." style="width:80%;" >}} |
| 22 | + |
| 23 | +- `DD_API_KEY` is your Datadog API key. |
| 24 | +- `DD_CUSTOM_METRICS_ENABLED` (optional) enables [custom metrics](#custom-metrics). |
| 25 | +- `DD_SITE` is the Datadog site [parameter][2]. Your site is {{< region-param key="dd_site" code="true" >}}. This value defaults to `datadoghq.com`. |
| 26 | +- `DD_SERVICE` is the service name used for this program. Defaults to the name field value in `package.json`. |
| 27 | +- `DD_START_APP` is the command used to start your application. For example, `node ./bin/www`. |
| 28 | + |
| 29 | +### Identifying your startup command |
| 30 | + |
| 31 | +Linux Azure App Service Web Apps built using the code deployment option on built-in runtimes depend on a startup command that varies by language. The default values are outlined in [Azure's documentation][7]. Examples are included below. |
| 32 | + |
| 33 | +Set these values in the `DD_START_APP` environment variable. Examples below are for an application named `datadog-demo`, where relevant. |
| 34 | + |
| 35 | +| Runtime | `DD_START_APP` Example Value | Description |
| 36 | +| ---- | --- | --- | |
| 37 | +| Node.js | `node ./bin/www` | Runs the [Node PM2 configuration file][12], or your script file | |
| 38 | +| .NET Core | `dotnet datadog-demo.dll` | Runs a .dll file that uses your Web App name by default | |
| 39 | +| PHP | `cp /home/site/wwwroot/default /etc/nginx/sites-available/default && service nginx reload` | Copies script to correct location and starts application | |
| 40 | +| Python | `gunicorn --bind=0.0.0.0 --timeout 600 quickstartproject.wsgi` | Custom [startup script][13]. This example shows a Gunicorn command for starting a Django app. | |
| 41 | +| Java | `java -jar /home/site/wwwroot/datadog-demo.jar` | The command to start your app | |
| 42 | + |
| 43 | +[7]: https://learn.microsoft.com/en-us/troubleshoot/azure/app-service/faqs-app-service-linux#what-are-the-expected-values-for-the-startup-file-section-when-i-configure-the-runtime-stack- |
| 44 | +[12]: https://learn.microsoft.com/en-us/azure/app-service/configure-language-nodejs?pivots=platform-linux#configure-nodejs-server |
| 45 | +[13]: https://learn.microsoft.com/en-us/azure/app-service/configure-language-php?pivots=platform-linux#customize-start-up |
| 46 | + |
| 47 | + |
| 48 | +**Note**: The application restarts when new settings are saved. |
| 49 | + |
| 50 | +#### Set General Settings |
| 51 | + |
| 52 | +{{< tabs >}} |
| 53 | +{{% tab "Node, .NET, PHP, Python" %}} |
| 54 | +Go to **General settings** and add the following to the **Startup Command** field: |
| 55 | + |
| 56 | +``` |
| 57 | +curl -s https://raw.githubusercontent.com/DataDog/datadog-aas-linux/v1.1.0/datadog_wrapper | bash |
| 58 | +``` |
| 59 | + |
| 60 | +{{< img src="serverless/azure_app_service/startup-command-1.jpeg" alt="Azure App Service Configuration: the Stack settings, under the Configuration section of Settings in the Azure UI. Underneath the stack, major version, and minor version fields is a 'Startup Command' field that is populated by the above curl command." style="width:100%;" >}} |
| 61 | +{{% /tab %}} |
| 62 | +{{% tab "Java" %}} |
| 63 | +Download the [`datadog_wrapper`][8] file from the releases and upload it to your application with the Azure CLI command: |
| 64 | + |
| 65 | +``` |
| 66 | + az webapp deploy --resource-group <group-name> --name <app-name> --src-path <path-to-datadog-wrapper> --type=startup |
| 67 | +``` |
| 68 | + |
| 69 | +Alternatively, you can upload this script as part of your application and set the startup command in general settings as its location (for example, `/home/site/wwwroot/datadog_wrapper`.) |
| 70 | + |
| 71 | +If you are already using a startup script, add the following curl command to the end of your script: |
| 72 | + |
| 73 | +``` |
| 74 | + curl -s https://raw.githubusercontent.com/DataDog/datadog-aas-linux/v1.1.0/datadog_wrapper | bash |
| 75 | +``` |
| 76 | + |
| 77 | +[8]: https://github.com/DataDog/datadog-aas-linux/releases |
| 78 | +{{% /tab %}} |
| 79 | +{{< /tabs >}} |
| 80 | + |
| 81 | +### Viewing traces |
| 82 | + |
| 83 | +When new Application Settings are saved, Azure restarts the application. However, if a startup command is added and saved, a restart may be required. |
| 84 | + |
| 85 | +After the application restarts, you can view traces by searching for the service name (`DD_SERVICE`) in the [APM Service page][4] of Datadog. |
| 86 | + |
| 87 | +### Custom metrics |
| 88 | + |
| 89 | +To enable custom metrics for your application with DogStatsD, add `DD_CUSTOM_METRICS_ENABLED` and set it as `true` in your Application Settings. |
| 90 | + |
| 91 | +To configure your application to submit metrics, follow the appropriate steps for your runtime. |
| 92 | + |
| 93 | +- [Java][9] |
| 94 | +- [Node][5] |
| 95 | +- [.NET][6] |
| 96 | +- [PHP][10] |
| 97 | +- [Python][11] |
| 98 | + |
| 99 | +## Troubleshooting |
| 100 | + |
| 101 | +If you are not receiving traces or custom metric data as expected, enable **App Service logs** to receive debugging logs. |
| 102 | + |
| 103 | +{{< img src="serverless/azure_app_service/app-service-logs.png" alt="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'." style="width:100%;" >}} |
| 104 | + |
| 105 | +Share the content of the **Log stream** with [Datadog Support][14]. |
| 106 | + |
| 107 | +[1]: /developers/dogstatsd |
| 108 | +[2]: /getting_started/site/#access-the-datadog-site |
| 109 | +[3]: https://www.datadoghq.com/blog/azure-app-service-datadog-serverless-view/ |
| 110 | +[4]: /tracing/services/service_page/ |
| 111 | +[5]: https://github.com/brightcove/hot-shots |
| 112 | +[6]: /developers/dogstatsd/?tab=hostagent&code-lang=dotnet#code |
| 113 | +[9]: https://docs.datadoghq.com/developers/dogstatsd/?tab=hostagent&code-lang=java |
| 114 | +[10]: https://docs.datadoghq.com/developers/dogstatsd/?tab=hostagent&code-lang=php |
| 115 | +[11]: https://docs.datadoghq.com/developers/dogstatsd/?tab=hostagent&code-lang=python |
| 116 | +[14]: /help |
0 commit comments