Skip to content

Commit 12ca299

Browse files
committed
Start pushing exponential histograms instead of classic.
1 parent ee48e7e commit 12ca299

File tree

9 files changed

+478
-452
lines changed

9 files changed

+478
-452
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,4 @@ jobs:
6464
env:
6565
OTEL_EXPORTER_OTLP_PROTOCOL: 'http/protobuf'
6666
ACTIONS_STEP_DEBUG: 'true'
67-
OTEL_EXPORTER_OTLP_METRICS_DEFAULT_HISTOGRAM_AGGREGATION: 'base2_exponential_bucket_histogram'
67+
OTEL_EXPORTER_OTLP_METRICS_DEFAULT_HISTOGRAM_AGGREGATION: 'BASE2_EXPONENTIAL_BUCKET_HISTOGRAM'

badges/coverage.svg

Lines changed: 1 addition & 1 deletion
Loading

dist/index.js

Lines changed: 14 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

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

package-lock.json

Lines changed: 428 additions & 441 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@
4848
"@actions/core": "1.11.1",
4949
"@actions/github": "6.0.1",
5050
"@opentelemetry/api": "^1.9.0",
51-
"@opentelemetry/auto-instrumentations-node": "^0.62.0",
52-
"@opentelemetry/exporter-metrics-otlp-proto": "^0.203.0",
53-
"@opentelemetry/resources": "^2.0.1",
54-
"@opentelemetry/sdk-metrics": "^2.0.1",
55-
"@opentelemetry/sdk-node": "^0.203.0",
51+
"@opentelemetry/auto-instrumentations-node": "^0.64.1",
52+
"@opentelemetry/exporter-metrics-otlp-proto": "^0.205.0",
53+
"@opentelemetry/resources": "^2.1.0",
54+
"@opentelemetry/sdk-metrics": "^2.1.0",
55+
"@opentelemetry/sdk-node": "^0.205.0",
5656
"@opentelemetry/semantic-conventions": "^1.36.0",
5757
"fast-xml-parser": "^5.2.5"
5858
},

src/__snapshots__/metrics-submitter.test.ts.snap

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ exports[`MetricsSubmitter should configures histogram with explicit buckets 1`]
1616
"1.0.0",
1717
],
1818
],
19+
"_schemaUrl": undefined,
1920
},
2021
"scopeMetrics": [
2122
{
@@ -110,6 +111,7 @@ exports[`MetricsSubmitter should creates instruments for each metric type 1`] =
110111
"1.0.0",
111112
],
112113
],
114+
"_schemaUrl": undefined,
113115
},
114116
"scopeMetrics": [
115117
{
@@ -246,6 +248,7 @@ exports[`MetricsSubmitter should handles metrics with different attributes corre
246248
"1.0.0",
247249
],
248250
],
251+
"_schemaUrl": undefined,
249252
},
250253
"scopeMetrics": [
251254
{
@@ -307,6 +310,7 @@ exports[`MetricsSubmitter should handles multiple metric types in one submission
307310
"1.0.0",
308311
],
309312
],
313+
"_schemaUrl": undefined,
310314
},
311315
"scopeMetrics": [
312316
{
@@ -443,6 +447,7 @@ exports[`MetricsSubmitter should handles updowncounter negative values correctly
443447
"1.0.0",
444448
],
445449
],
450+
"_schemaUrl": undefined,
446451
},
447452
"scopeMetrics": [
448453
{
@@ -496,6 +501,7 @@ exports[`MetricsSubmitter should reuses existing instruments for same metric nam
496501
"1.0.0",
497502
],
498503
],
504+
"_schemaUrl": undefined,
499505
},
500506
"scopeMetrics": [
501507
{

src/main.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ const mockMeterProvider = {
3131
const mockOpenTelemetry = {
3232
MeterProvider: jest.fn(() => mockMeterProvider),
3333
PeriodicExportingMetricReader: jest.fn(() => ({})),
34-
ConsoleMetricExporter: jest.fn(() => ({}))
34+
ConsoleMetricExporter: jest.fn(() => ({})),
35+
AggregationType: {
36+
EXPONENTIAL_HISTOGRAM: 5
37+
}
3538
}
3639

3740
const mockOTLPExporter = {
@@ -144,6 +147,7 @@ describe('main.ts', () => {
144147
})
145148

146149
expect(mockOTLPExporter.OTLPMetricExporter).toHaveBeenCalledWith({
150+
aggregationPreference: expect.any(Function),
147151
url: 'http://localhost:4318/v1/metrics',
148152
headers: {
149153
'api-key': 'secret123',

src/main.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ import { ingestDir } from './junit-parser.js'
55
import { generateMetrics, type TMetricsConfig } from './metrics-generator.js'
66
import { MetricsSubmitter } from './metrics-submitter.js'
77
import {
8+
InstrumentType,
89
MeterProvider,
9-
PeriodicExportingMetricReader
10+
PeriodicExportingMetricReader,
11+
AggregationType
1012
} from '@opentelemetry/sdk-metrics'
1113
import { OTLPMetricExporter } from '@opentelemetry/exporter-metrics-otlp-proto'
1214
import { resourceFromAttributes } from '@opentelemetry/resources'
@@ -28,6 +30,8 @@ import {
2830
DiagLogger,
2931
diag
3032
} from '@opentelemetry/api'
33+
import { DEFAULT_AGGREGATION_SELECTOR } from '@opentelemetry/sdk-metrics/build/src/export/AggregationSelector.js'
34+
import { ExponentialHistogramAggregationOption } from '@opentelemetry/sdk-metrics/build/src/view/AggregationOption.js'
3135

3236
class CapturingDiagLogger implements DiagLogger {
3337
private baseLogger: DiagConsoleLogger
@@ -122,7 +126,19 @@ export async function run(): Promise<void> {
122126
[ATTR_DEPLOYMENT_ENVIRONMENT_NAME]: deploymentEnvironment
123127
})
124128

129+
const aggregationPreference = (t: InstrumentType) => {
130+
if (t === 'HISTOGRAM') {
131+
return {
132+
type: AggregationType.EXPONENTIAL_HISTOGRAM,
133+
options: {
134+
recordMinMax: true
135+
}
136+
} as ExponentialHistogramAggregationOption
137+
}
138+
return DEFAULT_AGGREGATION_SELECTOR(t)
139+
}
125140
const exporter = new OTLPMetricExporter({
141+
aggregationPreference,
126142
url: otlpEndpoint,
127143
headers,
128144
timeoutMillis: DEFAULT_TIMEOUT_MS

0 commit comments

Comments
 (0)