|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node'; |
| 4 | +import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http'; |
| 5 | +import { ExpressInstrumentation } from '@opentelemetry/instrumentation-express'; |
| 6 | +import { HttpInstrumentation } from '@opentelemetry/instrumentation-http'; |
| 7 | +import { NestInstrumentation } from '@opentelemetry/instrumentation-nestjs-core'; |
| 8 | +import { PinoInstrumentation } from '@opentelemetry/instrumentation-pino'; |
| 9 | +import { Resource } from '@opentelemetry/resources'; |
| 10 | +import * as opentelemetry from '@opentelemetry/sdk-node'; |
| 11 | +import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions'; |
| 12 | + |
| 13 | +// Configure the SDK to export telemetry data to the console |
| 14 | +// Enable all auto-instrumentations from the meta package |
| 15 | +const exporterOptions = { |
| 16 | + url: 'http://otelcollector.dmp.cnna.io/v1/traces', |
| 17 | +}; |
| 18 | +// http://localhost:4318/v1/traces |
| 19 | + |
| 20 | +const traceExporter = new OTLPTraceExporter(exporterOptions); |
| 21 | +const sdk = new opentelemetry.NodeSDK({ |
| 22 | + traceExporter, |
| 23 | + instrumentations: [ |
| 24 | + getNodeAutoInstrumentations(), |
| 25 | + new NestInstrumentation(), |
| 26 | + new PinoInstrumentation(), |
| 27 | + new HttpInstrumentation(), |
| 28 | + new ExpressInstrumentation(), |
| 29 | + ], |
| 30 | + resource: new Resource({ |
| 31 | + [SemanticResourceAttributes.SERVICE_NAME]: 'salesforce-automation', |
| 32 | + [SemanticResourceAttributes.DEPLOYMENT_ENVIRONMENT]: process.env.NODE_ENV || 'local', |
| 33 | + }), |
| 34 | +}); |
| 35 | + |
| 36 | +// initialize the SDK and register with the OpenTelemetry API |
| 37 | +// this enables the API to record telemetry |
| 38 | +sdk.start(); |
| 39 | + |
| 40 | +// gracefully shut down the SDK on process exit |
| 41 | +process.on("SIGTERM", () => { |
| 42 | + sdk |
| 43 | + .shutdown() |
| 44 | + .then(() => console.log("Tracing terminated")) |
| 45 | + .catch((error) => console.log("Error terminating tracing", error)) |
| 46 | + .finally(() => process.exit(0)); |
| 47 | +}); |
| 48 | + |
| 49 | +export default sdk; |
0 commit comments