Skip to content

The open alternative to Salesforce, designed for AI.

perf(server): read the OTLP metrics export interval from OTEL_METRIC_EXPORT_INTERVAL, default 30s (#26443)

Etienne39e053b4d2c8
diff --git a/packages/twenty-server/.env.example b/packages/twenty-server/.env.example
index 3ca1ca0e3a5..54d071cbb44 100644
--- a/packages/twenty-server/.env.example
+++ b/packages/twenty-server/.env.example
@@ -44,6 +44,7 @@ FRONTEND_URL=http://localhost:3001
# LOGGER_IS_BUFFER_ENABLED=true
# EXCEPTION_HANDLER_DRIVER=sentry
# METER_DRIVER=opentelemetry,console
+# METER_EXPORT_INTERVAL_MS=30000
# SENTRY_ENVIRONMENT=main
# SENTRY_DSN=https://[email protected]/xxx
# SENTRY_FRONT_DSN=https://[email protected]/xxx
diff --git a/packages/twenty-server/src/engine/core-modules/twenty-config/config-variables.ts b/packages/twenty-server/src/engine/core-modules/twenty-config/config-variables.ts
index f1159fa7bc1..c769ea66d21 100644
--- a/packages/twenty-server/src/engine/core-modules/twenty-config/config-variables.ts
+++ b/packages/twenty-server/src/engine/core-modules/twenty-config/config-variables.ts
@@ -1219,6 +1219,17 @@ export class ConfigVariables {
@IsOptional()
METER_DRIVER: MeterDriver[] = [];
+ @ConfigVariablesMetadata({
+ group: ConfigVariablesGroup.LOGGING,
+ description:
+ 'Interval in milliseconds between two metric exports, for every meter driver. Read before the config store is available, so it cannot be overridden from the database.',
+ type: ConfigVariableType.NUMBER,
+ isEnvOnly: true,
+ })
+ @CastToPositiveNumber()
+ @IsOptional()
+ METER_EXPORT_INTERVAL_MS = 30_000;
+
@ConfigVariablesMetadata({
group: ConfigVariablesGroup.LOGGING,
description: 'Driver used for logging (only console for now)',
diff --git a/packages/twenty-server/src/instrument.ts b/packages/twenty-server/src/instrument.ts
index 224581e4ef1..bdb21d87570 100644
--- a/packages/twenty-server/src/instrument.ts
+++ b/packages/twenty-server/src/instrument.ts
@@ -45,6 +45,13 @@ const parseSampleRate = ({
: fallback;
};
+const parsedExportInterval = Number(process.env.METER_EXPORT_INTERVAL_MS);
+
+const metricExportIntervalMillis =
+ Number.isInteger(parsedExportInterval) && parsedExportInterval > 0
+ ? parsedExportInterval
+ : 30_000;
+
if (process.env.EXCEPTION_HANDLER_DRIVER === ExceptionHandlerDriver.SENTRY) {
const tracesSampleRate = parseSampleRate({
value: process.env.SENTRY_TRACES_SAMPLE_RATE,
@@ -135,7 +142,7 @@ const meterProvider = new MeterProvider({
? [
new PeriodicExportingMetricReader({
exporter: new ConsoleMetricExporter(),
- exportIntervalMillis: 10000,
+ exportIntervalMillis: metricExportIntervalMillis,
}),
]
: []),
@@ -146,7 +153,7 @@ const meterProvider = new MeterProvider({
url: process.env.OTLP_COLLECTOR_METRICS_ENDPOINT_URL,
temporalityPreference: AggregationTemporality.DELTA,
}),
- exportIntervalMillis: 10000,
+ exportIntervalMillis: metricExportIntervalMillis,
}),
]
: []),