@@ -8,6 +8,7 @@ import { resourceFromAttributes } from '@opentelemetry/resources';
88import { PeriodicExportingMetricReader } from '@opentelemetry/sdk-metrics' ;
99import { NodeSDK } from '@opentelemetry/sdk-node' ;
1010import { ATTR_SERVICE_NAME , ATTR_SERVICE_VERSION } from '@opentelemetry/semantic-conventions' ;
11+ import { env } from 'node:process' ;
1112
1213export function register ( options ?: { debug ?: true | DiagLogLevel ; version ?: string } ) {
1314 const attributes : Record < string , string > = {
@@ -23,13 +24,26 @@ export function register(options?: { debug?: true | DiagLogLevel; version?: stri
2324 ) ;
2425 }
2526
27+ let metricsExporterInterval = 1000 ;
28+ if ( env . OTEL_METRICS_EXPORTER_INTERVAL ) {
29+ const parsed = parseInt ( env . OTEL_METRICS_EXPORTER_INTERVAL , 10 ) ;
30+ if ( ! isNaN ( parsed ) ) {
31+ metricsExporterInterval = parsed ;
32+ }
33+ }
34+
2635 const sdk = new NodeSDK ( {
2736 instrumentations : [
2837 new PgInstrumentation ( ) ,
2938 new HttpInstrumentation ( ) ,
3039 getNodeAutoInstrumentations ( ) ,
3140 ] ,
32- metricReaders : [ new PeriodicExportingMetricReader ( { exporter : new OTLPMetricExporter ( ) } ) ] ,
41+ metricReaders : [
42+ new PeriodicExportingMetricReader ( {
43+ exportIntervalMillis : metricsExporterInterval ,
44+ exporter : new OTLPMetricExporter ( ) ,
45+ } ) ,
46+ ] ,
3347 resource : resourceFromAttributes ( attributes ) ,
3448 traceExporter : new OTLPTraceExporter ( ) ,
3549 } ) ;
0 commit comments