mirror of
https://github.com/denoland/deno.git
synced 2024-12-20 22:34:46 -05:00
7c036772df
Refs: https://github.com/denoland/deno/issues/26852 Initial support for exporting metrics. Co-authored-by: Luca Casonato <hello@lcas.dev>
34 lines
838 B
TypeScript
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();
|