mirror of
https://github.com/denoland/deno.git
synced 2025-09-30 22:21:15 +00:00
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>
This commit is contained in:
parent
6dd2d5e49e
commit
7c036772df
11 changed files with 1174 additions and 35 deletions
|
@ -15,6 +15,10 @@
|
|||
{
|
||||
"args": "run -A main.ts uncaught.ts",
|
||||
"output": "uncaught.out"
|
||||
},
|
||||
{
|
||||
"args": "run -A main.ts metric.ts",
|
||||
"output": "metric.out"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
@ -188,5 +188,6 @@
|
|||
"traceId": "00000000000000000000000000000003",
|
||||
"spanId": "1000000000000002"
|
||||
}
|
||||
]
|
||||
],
|
||||
"metrics": []
|
||||
}
|
||||
|
|
|
@ -15,5 +15,6 @@
|
|||
"traceId": "",
|
||||
"spanId": ""
|
||||
}
|
||||
]
|
||||
],
|
||||
"metrics": []
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
const data = {
|
||||
spans: [],
|
||||
logs: [],
|
||||
metrics: [],
|
||||
};
|
||||
|
||||
const server = Deno.serve(
|
||||
|
@ -45,6 +46,11 @@ const server = Deno.serve(
|
|||
data.spans.push(...sSpans.spans);
|
||||
});
|
||||
});
|
||||
body.resourceMetrics?.forEach((rMetrics) => {
|
||||
rMetrics.scopeMetrics.forEach((sMetrics) => {
|
||||
data.metrics.push(...sMetrics.metrics);
|
||||
});
|
||||
});
|
||||
return Response.json({ partialSuccess: {} }, { status: 200 });
|
||||
},
|
||||
},
|
||||
|
|
124
tests/specs/cli/otel_basic/metric.out
Normal file
124
tests/specs/cli/otel_basic/metric.out
Normal file
|
@ -0,0 +1,124 @@
|
|||
{
|
||||
"spans": [],
|
||||
"logs": [],
|
||||
"metrics": [
|
||||
{
|
||||
"name": "counter",
|
||||
"description": "Example of a Counter",
|
||||
"unit": "",
|
||||
"metadata": [],
|
||||
"sum": {
|
||||
"dataPoints": [
|
||||
{
|
||||
"attributes": [
|
||||
{
|
||||
"key": "attribute",
|
||||
"value": {
|
||||
"doubleValue": 1
|
||||
}
|
||||
}
|
||||
],
|
||||
"startTimeUnixNano": "[WILDCARD]",
|
||||
"timeUnixNano": "[WILDCARD]",
|
||||
"exemplars": [],
|
||||
"flags": 0,
|
||||
"asDouble": 1
|
||||
}
|
||||
],
|
||||
"aggregationTemporality": 2,
|
||||
"isMonotonic": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "up_down_counter",
|
||||
"description": "Example of a UpDownCounter",
|
||||
"unit": "",
|
||||
"metadata": [],
|
||||
"sum": {
|
||||
"dataPoints": [
|
||||
{
|
||||
"attributes": [
|
||||
{
|
||||
"key": "attribute",
|
||||
"value": {
|
||||
"doubleValue": 1
|
||||
}
|
||||
}
|
||||
],
|
||||
"startTimeUnixNano": "[WILDCARD]",
|
||||
"timeUnixNano": "[WILDCARD]",
|
||||
"exemplars": [],
|
||||
"flags": 0,
|
||||
"asDouble": -1
|
||||
}
|
||||
],
|
||||
"aggregationTemporality": 2,
|
||||
"isMonotonic": false
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "histogram",
|
||||
"description": "Example of a Histogram",
|
||||
"unit": "",
|
||||
"metadata": [],
|
||||
"histogram": {
|
||||
"dataPoints": [
|
||||
{
|
||||
"attributes": [
|
||||
{
|
||||
"key": "attribute",
|
||||
"value": {
|
||||
"doubleValue": 1
|
||||
}
|
||||
}
|
||||
],
|
||||
"startTimeUnixNano": "[WILDCARD]",
|
||||
"timeUnixNano": "[WILDCARD]",
|
||||
"count": 1,
|
||||
"sum": 1,
|
||||
"bucketCounts": [
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
],
|
||||
"explicitBounds": [
|
||||
0,
|
||||
5,
|
||||
10,
|
||||
25,
|
||||
50,
|
||||
75,
|
||||
100,
|
||||
250,
|
||||
500,
|
||||
750,
|
||||
1000,
|
||||
2500,
|
||||
5000,
|
||||
7500,
|
||||
10000
|
||||
],
|
||||
"exemplars": [],
|
||||
"flags": 0,
|
||||
"min": 1,
|
||||
"max": 1
|
||||
}
|
||||
],
|
||||
"aggregationTemporality": 2
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
34
tests/specs/cli/otel_basic/metric.ts
Normal file
34
tests/specs/cli/otel_basic/metric.ts
Normal file
|
@ -0,0 +1,34 @@
|
|||
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();
|
|
@ -15,5 +15,6 @@
|
|||
"traceId": "",
|
||||
"spanId": ""
|
||||
}
|
||||
]
|
||||
],
|
||||
"metrics": []
|
||||
}
|
||||
|
|
|
@ -33,5 +33,6 @@ throw new Error("uncaught");
|
|||
"traceId": "",
|
||||
"spanId": ""
|
||||
}
|
||||
]
|
||||
],
|
||||
"metrics": []
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue