Skip to content

Commit

Permalink
use exponential histograms for the quickstart sample
Browse files Browse the repository at this point in the history
  • Loading branch information
dashpole committed Jan 14, 2025
1 parent f8b5157 commit 7ffebf1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion samples/instrumentation-quickstart/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ services:
depends_on:
- otelcol
otelcol:
image: otel/opentelemetry-collector-contrib:0.110.0
image: otel/opentelemetry-collector-contrib:0.115.1
volumes:
- ./otel-collector-config.yaml:/etc/otelcol-contrib/config.yaml:ro
- logs:/var/log:ro
Expand Down
8 changes: 8 additions & 0 deletions samples/instrumentation-quickstart/otel-collector-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@ processors:
detectors: ["env", "gcp"]

service:
telemetry:
metrics:
readers:
- pull:
exporter:
prometheus:
host: '0.0.0.0'
port: 8888
pipelines:
traces:
receivers: ["otlp"]
Expand Down
15 changes: 14 additions & 1 deletion samples/instrumentation-quickstart/src/instrumentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ import {
import {
ConsoleMetricExporter,
PeriodicExportingMetricReader,
ExponentialHistogramAggregation,
DefaultAggregation,
InstrumentType,
} from '@opentelemetry/sdk-metrics';
import {OTLPMetricExporter} from '@opentelemetry/exporter-metrics-otlp-proto';

Expand All @@ -48,7 +51,17 @@ function getMetricReader() {
diag.info('using otel metrics exporter');
return new PeriodicExportingMetricReader({
...readerOptions,
exporter: new OTLPMetricExporter(),
exporter: new OTLPMetricExporter({
// Use exponential histograms for histogram instruments.
// This can be done using an environment variable after
// https://github.com/open-telemetry/opentelemetry-js/issues/3920 is implemented.
aggregationPreference: (_instrumentType: InstrumentType) => {
if (_instrumentType === InstrumentType.HISTOGRAM) {
return new ExponentialHistogramAggregation()
}
return new DefaultAggregation()
}
}),
});
case 'console':
return new PeriodicExportingMetricReader({
Expand Down

0 comments on commit 7ffebf1

Please sign in to comment.