-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathcustomMetric.ts
More file actions
33 lines (25 loc) · 883 Bytes
/
customMetric.ts
File metadata and controls
33 lines (25 loc) · 883 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
/**
* @summary Demonstrates how to generate custom metrics that will be sent to Azure Monitor.
*/
import { useAzureMonitor, shutdownAzureMonitor } from "@azure/monitor-opentelemetry";
import { metrics } from "@opentelemetry/api";
import "dotenv/config";
async function main(): Promise<void> {
const options = {
azureMonitorExporterOptions: {
connectionString:
process.env.APPLICATIONINSIGHTS_CONNECTION_STRING || "<your connection string>",
},
};
useAzureMonitor(options);
const meter = metrics.getMeter("testMeter");
const customCounter = meter.createCounter("TestCounter");
customCounter.add(1);
customCounter.add(2);
customCounter.add(3);
console.log("Custom metrics sent to Azure Monitor");
await shutdownAzureMonitor();
}
main().catch(console.error);