1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 15:24:46 -05:00
denoland-deno/tests/specs/cli/otel_basic/metric.ts
snek 7c036772df
feat(unstable): add metrics to otel (#27143)
Refs: https://github.com/denoland/deno/issues/26852

Initial support for exporting metrics.

Co-authored-by: Luca Casonato <hello@lcas.dev>
2024-12-02 20:45:41 +01:00

34 lines
838 B
TypeScript

import {
MeterProvider,
PeriodicExportingMetricReader,
} from "npm:@opentelemetry/sdk-metrics@1.28.0";
const meterProvider = new MeterProvider();
meterProvider.addMetricReader(
new PeriodicExportingMetricReader({
exporter: new Deno.telemetry.MetricExporter(),
exportIntervalMillis: 100,
}),
);
const meter = meterProvider.getMeter("m");
const counter = meter.createCounter("counter", {
description: "Example of a Counter",
});
const upDownCounter = meter.createUpDownCounter("up_down_counter", {
description: "Example of a UpDownCounter",
});
const histogram = meter.createHistogram("histogram", {
description: "Example of a Histogram",
});
const attributes = { attribute: 1 };
counter.add(1, attributes);
upDownCounter.add(-1, attributes);
histogram.record(1, attributes);
await meterProvider.forceFlush();