/** * @fileoverview OpenTelemetry tracing setup for the application * * This file should be imported before any other application code to ensure * proper instrumentation setup. */ import { NodeSDK } from '@opentelemetry/sdk-node'; import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node'; import { Resource } from '@opentelemetry/resources'; import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions'; // Initialize OpenTelemetry SDK const sdk = new NodeSDK({ resource: new Resource({ [SemanticResourceAttributes.SERVICE_NAME]: 'throttler-example-app', [SemanticResourceAttributes.SERVICE_VERSION]: '1.0.0', }), instrumentations: [ getNodeAutoInstrumentations({ // Disable file system instrumentation to reduce noise '@opentelemetry/instrumentation-fs': { enabled: false, }, }), ], }); // Start the SDK sdk.start(); console.log('OpenTelemetry tracing initialized successfully'); // Graceful shutdown process.on('SIGTERM', () => { sdk.shutdown() .then(() => console.log('OpenTelemetry terminated')) .catch((error) => console.log('Error terminating OpenTelemetry', error)) .finally(() => process.exit(0)); });