Skip to content

Commit

Permalink
feat(nodejs-autoinstrumentation): enable overwriting default histogra…
Browse files Browse the repository at this point in the history
…m buckets
  • Loading branch information
CCOLLOT authored Nov 11, 2024
1 parent 7c79f2d commit c8ba094
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion autoinstrumentation/nodejs/src/autoinstrumentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { OTLPTraceExporter as OTLPHttpTraceExporter } from '@opentelemetry/expor
import { OTLPTraceExporter as OTLPGrpcTraceExporter } from '@opentelemetry/exporter-trace-otlp-grpc';
import { OTLPMetricExporter } from '@opentelemetry/exporter-metrics-otlp-grpc';
import { PrometheusExporter } from '@opentelemetry/exporter-prometheus';
import { PeriodicExportingMetricReader } from '@opentelemetry/sdk-metrics';
import { ExplicitBucketHistogramAggregation, PeriodicExportingMetricReader, View } from "@opentelemetry/sdk-metrics";
import { alibabaCloudEcsDetector } from '@opentelemetry/resource-detector-alibaba-cloud';
import { awsEc2Detector, awsEksDetector } from '@opentelemetry/resource-detector-aws';
import { containerDetector } from '@opentelemetry/resource-detector-container';
Expand Down Expand Up @@ -50,11 +50,35 @@ function getMetricReader() {
}
}

function getView() {
const buckets = process.env.OTEL_METRICS_EXPLICIT_BUCKET_HISTOGRAM;
const defaultHistogramBuckets = [
0.005, 0.01, 0.025, 0.05, 0.075, 0.1, 0.25, 0.5, 0.75, 1, 2.5, 5, 7.5, 10,
];
if (!buckets) {
return new View({
aggregation: new ExplicitBucketHistogramAggregation(
defaultHistogramBuckets,
),
instrumentName: "*",
});
} else {
return new View({
// parse buckets and make it a list of numbers
aggregation: new ExplicitBucketHistogramAggregation(
buckets.split(",").map((x) => parseFloat(x)),
),
instrumentName: "*",
});
}
}

const sdk = new NodeSDK({
autoDetectResources: true,
instrumentations: [getNodeAutoInstrumentations()],
traceExporter: getTraceExporter(),
metricReader: getMetricReader(),
views: [getView()],
resourceDetectors:
[
// Standard resource detectors.
Expand Down

0 comments on commit c8ba094

Please sign in to comment.