Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

🔨 chore(observability-otel): interval of metrics not small enough (#10175)

Neko0c11d5fceec1
diff --git a/packages/obervability-otel/src/node.ts b/packages/obervability-otel/src/node.ts
index 24f6be9337f..fbf5b21a682 100644
--- a/packages/obervability-otel/src/node.ts
+++ b/packages/obervability-otel/src/node.ts
@@ -8,6 +8,7 @@ import { resourceFromAttributes } from '@opentelemetry/resources';
import { PeriodicExportingMetricReader } from '@opentelemetry/sdk-metrics';
import { NodeSDK } from '@opentelemetry/sdk-node';
import { ATTR_SERVICE_NAME, ATTR_SERVICE_VERSION } from '@opentelemetry/semantic-conventions';
+import { env } from 'node:process';
export function register(options?: { debug?: true | DiagLogLevel; version?: string }) {
const attributes: Record<string, string> = {
@@ -23,13 +24,26 @@ export function register(options?: { debug?: true | DiagLogLevel; version?: stri
);
}
+ let metricsExporterInterval = 1000;
+ if (env.OTEL_METRICS_EXPORTER_INTERVAL) {
+ const parsed = parseInt(env.OTEL_METRICS_EXPORTER_INTERVAL, 10);
+ if (!isNaN(parsed)) {
+ metricsExporterInterval = parsed;
+ }
+ }
+
const sdk = new NodeSDK({
instrumentations: [
new PgInstrumentation(),
new HttpInstrumentation(),
getNodeAutoInstrumentations(),
],
- metricReaders: [new PeriodicExportingMetricReader({ exporter: new OTLPMetricExporter() })],
+ metricReaders: [
+ new PeriodicExportingMetricReader({
+ exportIntervalMillis: metricsExporterInterval,
+ exporter: new OTLPMetricExporter(),
+ }),
+ ],
resource: resourceFromAttributes(attributes),
traceExporter: new OTLPTraceExporter(),
});