|
1 | 1 | --- |
2 | 2 | name: azure-functions |
3 | 3 | description: Build, deploy, and test Azure Functions instrumented with Datadog.AzureFunctions NuGet package. Use when working on Azure Functions integration, deploying to test environments, analyzing traces, or troubleshooting instrumentation issues. |
4 | | -argument-hint: [build|deploy|test|logs|trace] |
| 4 | +argument-hint: [build|deploy|test|logs|trace|configure] |
5 | 5 | disable-model-invocation: true |
6 | | -allowed-tools: Bash(az:functionapp:show:*) Bash(az:functionapp:list:*) Bash(az:functionapp:list-functions:*) Bash(az:functionapp:function:list:*) Bash(az:functionapp:function:show:*) Bash(az:functionapp:config:appsettings:list:*) Bash(az:functionapp:config:show:*) Bash(az:functionapp:deployment:list:*) Bash(az:functionapp:deployment:show:*) Bash(az:functionapp:deployment:source:show:*) Bash(az:functionapp:plan:list:*) Bash(az:functionapp:plan:show:*) Bash(az:functionapp:log:download:*) Bash(az:webapp:log:tail:*) Bash(az:group:list:*) Bash(az:group:show:*) Bash(curl:*) Bash(func:azure:functionapp:logstream:*) Bash(func:azure:functionapp:list-functions:*) Bash(func:azure:functionapp:fetch-app-settings:*) Bash(func:azure:functionapp:fetch:*) Bash(dotnet:restore) Bash(dotnet:clean) Bash(dotnet:build:*) Bash(unzip:*) Bash(date:*) Bash(grep:*) Bash(find:*) Bash(ls:*) Bash(cat:*) Bash(head:*) Bash(tail:*) Bash(wc:*) Bash(sort:*) Bash(jq:*) Read |
| 6 | +allowed-tools: Bash(az:functionapp:show:*) Bash(az:functionapp:list:*) Bash(az:functionapp:list-functions:*) Bash(az:functionapp:function:list:*) Bash(az:functionapp:function:show:*) Bash(az:functionapp:config:appsettings:list:*) Bash(az:functionapp:config:appsettings:set:*) Bash(az:functionapp:config:show:*) Bash(az:functionapp:deployment:list:*) Bash(az:functionapp:deployment:show:*) Bash(az:functionapp:deployment:source:show:*) Bash(az:functionapp:plan:list:*) Bash(az:functionapp:plan:show:*) Bash(az:functionapp:log:download:*) Bash(az:webapp:log:tail:*) Bash(az:group:list:*) Bash(az:group:show:*) Bash(curl:*) Bash(func:azure:functionapp:logstream:*) Bash(func:azure:functionapp:list-functions:*) Bash(func:azure:functionapp:fetch-app-settings:*) Bash(func:azure:functionapp:fetch:*) Bash(dotnet:restore) Bash(dotnet:clean) Bash(dotnet:build:*) Bash(unzip:*) Bash(date:*) Bash(grep:*) Bash(find:*) Bash(ls:*) Bash(cat:*) Bash(head:*) Bash(tail:*) Bash(wc:*) Bash(sort:*) Bash(jq:*) Bash(uname:*) Read |
7 | 7 | --- |
8 | 8 |
|
9 | 9 | # Azure Functions Development Workflow |
@@ -36,6 +36,7 @@ When invoked with an argument, perform the corresponding workflow: |
36 | 36 | - `/azure-functions test [app-name]` - Trigger and verify function execution |
37 | 37 | - `/azure-functions logs [app-name]` - Download and analyze logs |
38 | 38 | - `/azure-functions trace [trace-id]` - Analyze specific trace in Datadog |
| 39 | +- `/azure-functions configure [app-name]` - Configure environment variables for Datadog instrumentation |
39 | 40 |
|
40 | 41 | If no argument is provided, guide the user through the full workflow interactively. |
41 | 42 |
|
@@ -146,7 +147,64 @@ $deploy = .\tracer\tools\Deploy-AzureFunction.ps1 ` |
146 | 147 | -SampleAppPath "<path-to-sample-app>" |
147 | 148 | ``` |
148 | 149 |
|
149 | | -### 3. Download and Analyze Logs |
| 150 | +### 3. Configure Environment Variables |
| 151 | + |
| 152 | +Configure Datadog instrumentation environment variables for an Azure Function App: |
| 153 | + |
| 154 | +**Interactive mode** (recommended): |
| 155 | +```bash |
| 156 | +/azure-functions configure <app-name> |
| 157 | +``` |
| 158 | + |
| 159 | +This will: |
| 160 | +1. Detect the OS/platform (Linux or Windows) |
| 161 | +2. Show current environment variable configuration |
| 162 | +3. Ask which variables to configure: |
| 163 | + - **Required only** - Minimum variables needed for instrumentation |
| 164 | + - **Required + Recommended** - Add feature disables and sampling rules |
| 165 | + - **Required + Recommended + Debug** - Add debug logging (for troubleshooting) |
| 166 | + - **Custom** - User selects specific variables |
| 167 | +4. Prompt for required values (DD_API_KEY, DD_ENV, etc.) |
| 168 | +5. Set the variables using Azure CLI |
| 169 | + |
| 170 | +**Required variables** (must be set): |
| 171 | +```bash |
| 172 | +CORECLR_ENABLE_PROFILING=1 |
| 173 | +CORECLR_PROFILER={846F5F1C-F9AE-4B07-969E-05C26BC060D8} |
| 174 | +DD_API_KEY=<your-api-key> |
| 175 | +DOTNET_STARTUP_HOOKS=<path-to-compat-dll> |
| 176 | +``` |
| 177 | + |
| 178 | +**Platform-specific paths**: |
| 179 | +- **Linux**: |
| 180 | + - `CORECLR_PROFILER_PATH=/home/site/wwwroot/datadog/linux-x64/Datadog.Trace.ClrProfiler.Native.so` |
| 181 | +- **Windows** (requires both 32-bit and 64-bit paths): |
| 182 | + - `CORECLR_PROFILER_PATH_32=C:\home\site\wwwroot\datadog\win-x86\Datadog.Trace.ClrProfiler.Native.dll` |
| 183 | + - `CORECLR_PROFILER_PATH_64=C:\home\site\wwwroot\datadog\win-x64\Datadog.Trace.ClrProfiler.Native.dll` |
| 184 | + |
| 185 | +**Manual configuration**: |
| 186 | +```bash |
| 187 | +# Set multiple variables at once |
| 188 | +az functionapp config appsettings set \ |
| 189 | + --name <app-name> \ |
| 190 | + --resource-group <resource-group> \ |
| 191 | + --settings \ |
| 192 | + "CORECLR_ENABLE_PROFILING=1" \ |
| 193 | + "CORECLR_PROFILER={846F5F1C-F9AE-4B07-969E-05C26BC060D8}" \ |
| 194 | + "CORECLR_PROFILER_PATH=/home/site/wwwroot/datadog/linux-x64/Datadog.Trace.ClrProfiler.Native.so" \ |
| 195 | + "DD_DOTNET_TRACER_HOME=/home/site/wwwroot/datadog" \ |
| 196 | + "DD_API_KEY=<your-api-key>" \ |
| 197 | + "DOTNET_STARTUP_HOOKS=/home/site/wwwroot/Datadog.Serverless.Compat.dll" |
| 198 | +``` |
| 199 | + |
| 200 | +**Complete reference**: See [environment-variables.md](environment-variables.md) for all available variables, including: |
| 201 | +- Recommended feature disables (AppSec, CI Visibility, RCM, Agent Feature Polling) |
| 202 | +- Debug logging configuration |
| 203 | +- Direct log submission |
| 204 | +- Performance tuning |
| 205 | +- Integration-specific settings |
| 206 | + |
| 207 | +### 4. Download and Analyze Logs |
150 | 208 |
|
151 | 209 | Use the `Get-AzureFunctionLogs.ps1` script to download, extract, and analyze logs: |
152 | 210 |
|
@@ -213,6 +271,8 @@ After deployment and testing: |
213 | 271 |
|
214 | 272 | ## Common Troubleshooting |
215 | 273 |
|
| 274 | +**General guidance**: For environment variable configuration issues, see [environment-variables.md](environment-variables.md) for complete reference on required, recommended, and debugging variables. |
| 275 | + |
216 | 276 | ### Function Not Responding |
217 | 277 | ```bash |
218 | 278 | # Check deployment status |
@@ -243,6 +303,8 @@ az functionapp config appsettings list \ |
243 | 303 | grep "Datadog Tracer initialized" LogFiles/datadog/dotnet-tracer-managed-dotnet-*.log |
244 | 304 | ``` |
245 | 305 |
|
| 306 | +**Environment variables**: Verify all required environment variables are configured correctly. See [environment-variables.md](environment-variables.md) for complete reference. |
| 307 | + |
246 | 308 | ### Separate Traces (Parenting Issue) |
247 | 309 | 1. Get trace ID from host logs at execution timestamp |
248 | 310 | 2. Search worker logs for same trace ID |
@@ -273,28 +335,83 @@ curl -X POST https://api.datadoghq.com/api/v2/spans/events/search \ |
273 | 335 | }' |
274 | 336 | ``` |
275 | 337 |
|
| 338 | +## Configure Command Implementation |
| 339 | + |
| 340 | +When invoked with `/azure-functions configure [app-name]`: |
| 341 | + |
| 342 | +1. **Prompt for app name and resource group** (if not provided) |
| 343 | +2. **Detect shell environment** (to handle Git Bash path conversion): |
| 344 | + - Check if running in Git Bash on Windows: `uname -s` contains "MINGW" or "MSYS" |
| 345 | + - If Git Bash: Prefix Azure CLI commands with `MSYS_NO_PATHCONV=1` |
| 346 | + - Otherwise: Use commands without prefix |
| 347 | +3. **Detect platform**: |
| 348 | + ```bash |
| 349 | + az functionapp show --name <app-name> --resource-group <resource-group> --query "kind" -o tsv |
| 350 | + ``` |
| 351 | + - Look for "linux" or "windows" in the kind string |
| 352 | +4. **Show current configuration**: |
| 353 | + ```bash |
| 354 | + az functionapp config appsettings list --name <app-name> --resource-group <resource-group> |
| 355 | + ``` |
| 356 | + - Filter for DD_* and CORECLR_* variables |
| 357 | +5. **Ask configuration level**: |
| 358 | + - **Required only**: CORECLR_*, DD_DOTNET_TRACER_HOME, DD_API_KEY, DOTNET_STARTUP_HOOKS |
| 359 | + - **Required + Recommended**: Add DD_APPSEC_ENABLED=false, DD_CIVISIBILITY_ENABLED=false, DD_REMOTE_CONFIGURATION_ENABLED=false, DD_AGENT_FEATURE_POLLING_ENABLED=false, DD_ENV, DD_TRACE_SAMPLING_RULES |
| 360 | + - **Required + Recommended + Debug**: Add DD_TRACE_DEBUG=true, DD_TRACE_LOG_SINKS=file,console-experimental, DD_LOG_LEVEL=debug, DD_LOGS_DIRECT_SUBMISSION_* |
| 361 | + - **Custom**: User selects specific variables |
| 362 | +6. **Prompt for values**: |
| 363 | + - DD_API_KEY (required, never show existing value) |
| 364 | + - DD_ENV (optional, show current value if exists) |
| 365 | + - DD_TRACE_SAMPLING_RULES (optional, suggest default) |
| 366 | +7. **Set platform-specific paths** based on detected OS: |
| 367 | + - **Linux**: Single `CORECLR_PROFILER_PATH=/home/site/wwwroot/datadog/linux-x64/Datadog.Trace.ClrProfiler.Native.so` |
| 368 | + - **Windows**: Separate 32/64-bit paths: |
| 369 | + - `CORECLR_PROFILER_PATH_32=C:\home\site\wwwroot\datadog\win-x86\Datadog.Trace.ClrProfiler.Native.dll` |
| 370 | + - `CORECLR_PROFILER_PATH_64=C:\home\site\wwwroot\datadog\win-x64\Datadog.Trace.ClrProfiler.Native.dll` |
| 371 | +8. **Apply settings**: |
| 372 | + - **CRITICAL**: When using Git Bash on Windows, prefix the command with `MSYS_NO_PATHCONV=1` to prevent automatic path conversion (Linux paths like `/home/site/...` would otherwise be converted to `C:/Program Files/Git/home/site/...`) |
| 373 | + - **PowerShell/CMD**: No prefix needed, use command as-is |
| 374 | + ```bash |
| 375 | + # Git Bash (Windows) |
| 376 | + MSYS_NO_PATHCONV=1 az functionapp config appsettings set \ |
| 377 | + --name <app-name> \ |
| 378 | + --resource-group <resource-group> \ |
| 379 | + --settings "KEY1=value1" "KEY2=value2" ... |
| 380 | + |
| 381 | + # PowerShell/CMD/Linux/macOS |
| 382 | + az functionapp config appsettings set \ |
| 383 | + --name <app-name> \ |
| 384 | + --resource-group <resource-group> \ |
| 385 | + --settings "KEY1=value1" "KEY2=value2" ... |
| 386 | + ``` |
| 387 | +9. **Confirm success** and remind to restart if needed: |
| 388 | + ```bash |
| 389 | + az functionapp restart --name <app-name> --resource-group <resource-group> |
| 390 | + ``` |
| 391 | + |
276 | 392 | ## Interactive Mode |
277 | 393 |
|
278 | 394 | If invoked without arguments (`/azure-functions`), guide the user through: |
279 | 395 |
|
280 | | -1. **Understand the goal**: What are they testing? (New feature, bug fix, trace verification) |
281 | | -2. **Modify .csproj**: Temporarily change `Datadog.AzureFunctions.csproj` to use PackageReference instead of ProjectReference (see step 1 above) |
282 | | -3. **Build**: Run Build-AzureFunctionsNuget.ps1 |
283 | | -4. **Select app**: Which test app to deploy to? |
284 | | -5. **Verify prerequisites**: Check that the sample app has a `nuget.config` file configured with the local NuGet feed |
285 | | -6. **Deploy**: Navigate to sample app and publish |
286 | | -7. **Wait**: Remind to wait 1-2 minutes for worker restart |
287 | | -8. **Test**: Trigger function and capture timestamp |
288 | | -9. **Download logs**: Pull logs from Azure |
289 | | -10. **Analyze**: Guide through log analysis based on their goal |
290 | | -11. **Verify**: Run through verification checklist |
291 | | -12. **Revert .csproj**: Remind to revert the temporary change to `Datadog.AzureFunctions.csproj` (DO NOT commit) |
| 396 | +1. **Understand the goal**: What are they testing? (New feature, bug fix, trace verification, initial setup) |
| 397 | +2. **Check configuration**: Ask if environment variables are configured (offer to run `/azure-functions configure`) |
| 398 | +3. **Modify .csproj**: Temporarily change `Datadog.AzureFunctions.csproj` to use PackageReference instead of ProjectReference (see step 1 above) |
| 399 | +4. **Build**: Run Build-AzureFunctionsNuget.ps1 |
| 400 | +5. **Select app**: Which test app to deploy to? |
| 401 | +6. **Verify prerequisites**: Check that the sample app has a `nuget.config` file configured with the local NuGet feed |
| 402 | +7. **Deploy**: Navigate to sample app and publish |
| 403 | +8. **Wait**: Remind to wait 1-2 minutes for worker restart |
| 404 | +9. **Test**: Trigger function and capture timestamp |
| 405 | +10. **Download logs**: Pull logs from Azure |
| 406 | +11. **Analyze**: Guide through log analysis based on their goal |
| 407 | +12. **Verify**: Run through verification checklist |
| 408 | +13. **Revert .csproj**: Remind to revert the temporary change to `Datadog.AzureFunctions.csproj` (DO NOT commit) |
292 | 409 |
|
293 | 410 | ## Additional Resources |
294 | 411 |
|
295 | | -For detailed log analysis patterns and grep examples, see [log-analysis-guide.md](log-analysis-guide.md). |
296 | | - |
297 | | -For reusable bash/PowerShell scripts and one-liners, see [scripts-reference.md](scripts-reference.md). |
| 412 | +- **Log analysis**: [log-analysis-guide.md](log-analysis-guide.md) - Detailed log analysis patterns and grep examples |
| 413 | +- **Scripts**: [scripts-reference.md](scripts-reference.md) - Reusable bash/PowerShell scripts and one-liners |
| 414 | +- **Environment variables**: [environment-variables.md](environment-variables.md) - Complete reference for Azure Functions configuration |
298 | 415 |
|
299 | 416 | ## References |
300 | 417 |
|
|
0 commit comments