@@ -4,7 +4,7 @@ import { OTLPTraceExporter as OTLPHttpTraceExporter } from '@opentelemetry/expor
4
4
import { OTLPTraceExporter as OTLPGrpcTraceExporter } from '@opentelemetry/exporter-trace-otlp-grpc' ;
5
5
import { OTLPMetricExporter } from '@opentelemetry/exporter-metrics-otlp-grpc' ;
6
6
import { PrometheusExporter } from '@opentelemetry/exporter-prometheus' ;
7
- import { PeriodicExportingMetricReader } from ' @opentelemetry/sdk-metrics' ;
7
+ import { ExplicitBucketHistogramAggregation , PeriodicExportingMetricReader , View } from " @opentelemetry/sdk-metrics" ;
8
8
import { alibabaCloudEcsDetector } from '@opentelemetry/resource-detector-alibaba-cloud' ;
9
9
import { awsEc2Detector , awsEksDetector } from '@opentelemetry/resource-detector-aws' ;
10
10
import { containerDetector } from '@opentelemetry/resource-detector-container' ;
@@ -50,11 +50,35 @@ function getMetricReader() {
50
50
}
51
51
}
52
52
53
+ function getView ( ) {
54
+ const buckets = process . env . OTEL_METRICS_EXPLICIT_BUCKET_HISTOGRAM ;
55
+ const defaultHistogramBuckets = [
56
+ 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 ,
57
+ ] ;
58
+ if ( ! buckets ) {
59
+ return new View ( {
60
+ aggregation : new ExplicitBucketHistogramAggregation (
61
+ defaultHistogramBuckets ,
62
+ ) ,
63
+ instrumentName : "*" ,
64
+ } ) ;
65
+ } else {
66
+ return new View ( {
67
+ // parse buckets and make it a list of numbers
68
+ aggregation : new ExplicitBucketHistogramAggregation (
69
+ buckets . split ( "," ) . map ( ( x ) => parseFloat ( x ) ) ,
70
+ ) ,
71
+ instrumentName : "*" ,
72
+ } ) ;
73
+ }
74
+ }
75
+
53
76
const sdk = new NodeSDK ( {
54
77
autoDetectResources : true ,
55
78
instrumentations : [ getNodeAutoInstrumentations ( ) ] ,
56
79
traceExporter : getTraceExporter ( ) ,
57
80
metricReader : getMetricReader ( ) ,
81
+ views : [ getView ( ) ] ,
58
82
resourceDetectors :
59
83
[
60
84
// Standard resource detectors.
0 commit comments