| 35 | let sdk: NodeSDK | null = null; |
| 36 | |
| 37 | export const initializeOpenTelemetry = (): void => { |
| 38 | if (env.OTEL_EXPORTER_OTLP_ENDPOINT === "") { |
| 39 | return; |
| 40 | } |
| 41 | |
| 42 | sdk = new NodeSDK({ |
| 43 | resource: resourceFromAttributes({ |
| 44 | [ATTR_SERVICE_NAME]: env.OTEL_SERVICE_NAME, |
| 45 | [ATTR_SERVICE_VERSION]: env.APP_NAME, |
| 46 | "deployment.environment": env.NODE_ENV, |
| 47 | }), |
| 48 | traceExporter: new OTLPTraceExporter({ |
| 49 | url: `${env.OTEL_EXPORTER_OTLP_ENDPOINT}/v1/traces`, |
| 50 | }), |
| 51 | instrumentations: [ |
| 52 | getNodeAutoInstrumentations({ |
| 53 | /* |
| 54 | * Disable file-system instrumentation: it generates an enormous |
| 55 | * volume of spans for normal Node operations and drowns out the |
| 56 | * application signal. Disable dns for the same reason. |
| 57 | */ |
| 58 | "@opentelemetry/instrumentation-fs": { enabled: false }, |
| 59 | "@opentelemetry/instrumentation-dns": { enabled: false }, |
| 60 | }), |
| 61 | ], |
| 62 | }); |
| 63 | |
| 64 | sdk.start(); |
| 65 | }; |
| 66 | |
| 67 | /* |
| 68 | * Best-effort shutdown, called from the process exit handlers so |