diff --git a/ghost/core/core/shared/instrumentation.js b/ghost/core/core/shared/instrumentation.js index 841029ffed..d4ab13a51b 100644 --- a/ghost/core/core/shared/instrumentation.js +++ b/ghost/core/core/shared/instrumentation.js @@ -1,7 +1,3 @@ -const {NodeSDK} = require('@opentelemetry/sdk-node'); -const {OTLPTraceExporter} = require('@opentelemetry/exporter-trace-otlp-http'); -const {getNodeAutoInstrumentations} = require('@opentelemetry/auto-instrumentations-node'); - async function initOpenTelemetry({config}) { // Always enable in development environment // In production, only enable if explicitly enabled via config `opentelemetry:enabled` @@ -16,6 +12,12 @@ async function initOpenTelemetry({config}) { headers: {}, concurrencyLimit: 10 }; + + // Lazyloaded to avoid boot time overhead when not enabled + const {NodeSDK} = require('@opentelemetry/sdk-node'); + const {OTLPTraceExporter} = require('@opentelemetry/exporter-trace-otlp-http'); + const {getNodeAutoInstrumentations} = require('@opentelemetry/auto-instrumentations-node'); + const sdk = new NodeSDK({ serviceName: 'ghost', traceExporter: new OTLPTraceExporter(collectorOptions), @@ -28,4 +30,4 @@ async function initOpenTelemetry({config}) { module.exports = { initOpenTelemetry -}; \ No newline at end of file +};