Skip to content

Commit ddbac24

Browse files
committed
feat: add OpenTelemetry tracing setup with Azure Monitor
1 parent 22dce1d commit ddbac24

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

package-lock.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/burger-api/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "1.0.0",
44
"description": "Azure Functions API for Contoso Burgers",
55
"private": true,
6-
"main": "./dist/src/functions/*.js",
6+
"main": "./dist/src/{tracing.js,functions/*.js}",
77
"scripts": {
88
"build": "tsc",
99
"watch": "tsc -w",
@@ -21,6 +21,7 @@
2121
"@azure/cosmos": "^4.3.0",
2222
"@azure/functions": "^4.7.0",
2323
"@azure/identity": "^4.8.0",
24+
"@azure/monitor-opentelemetry": "^1.14.0",
2425
"@azure/storage-blob": "^12.27.0",
2526
"js-yaml": "^4.1.0"
2627
},

packages/burger-api/src/tracing.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// OpenTelemetry tracing setup
2+
// This file is loaded automatically by the Azure Functions host,
3+
// as configured in package.json "main" field.
4+
5+
import { useAzureMonitor } from "@azure/monitor-opentelemetry";
6+
7+
let isTracingInitialized = false;
8+
if (!isTracingInitialized) {
9+
// Initialize tracing and export to Azure Monitor
10+
const appInsightsConnectionString = process.env["APPLICATIONINSIGHTS_CONNECTION_STRING"];
11+
if (appInsightsConnectionString) {
12+
useAzureMonitor({
13+
azureMonitorExporterOptions: { connectionString: appInsightsConnectionString }
14+
});
15+
}
16+
17+
isTracingInitialized = true;
18+
}

0 commit comments

Comments
 (0)