Skip to content

Commit 0c11d5f

Browse files
authored
🔨 chore(observability-otel): interval of metrics not small enough (#10175)
fix(observability-otel): interval of metrics not small enough
1 parent be9678e commit 0c11d5f

File tree

1 file changed

+15
-1
lines changed
  • packages/obervability-otel/src

1 file changed

+15
-1
lines changed

‎packages/obervability-otel/src/node.ts‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { resourceFromAttributes } from '@opentelemetry/resources';
88
import { PeriodicExportingMetricReader } from '@opentelemetry/sdk-metrics';
99
import { NodeSDK } from '@opentelemetry/sdk-node';
1010
import { ATTR_SERVICE_NAME, ATTR_SERVICE_VERSION } from '@opentelemetry/semantic-conventions';
11+
import { env } from 'node:process';
1112

1213
export 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

Comments
 (0)