-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtracing.js
36 lines (31 loc) · 1.33 KB
/
tracing.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"use strict";
const process = require('process');
const { NodeSDK } = require('@opentelemetry/sdk-node');
const { getNodeAutoInstrumentations } = require('@opentelemetry/auto-instrumentations-node');
const { Resource } = require('@opentelemetry/resources');
const { SemanticResourceAttributes } = require('@opentelemetry/semantic-conventions');
const { CollectorTraceExporter } = require("@opentelemetry/exporter-collector-grpc");
// Create an OpenTelemetry Collector exporter for traces
const traceExporter = new CollectorTraceExporter({
url: process.env.OTEL_EXPORTER_OTLP_ENDPOINT
});
// create the OpenTelemetry NodeSDK trace provider
const sdk = new NodeSDK({
resource: new Resource({
[SemanticResourceAttributes.SERVICE_NAME]: process.env.SERVICE_NAME,
[ 'ip' ]: process.env.POD_IP,
}),
traceExporter,
instrumentations: [getNodeAutoInstrumentations()] // enable all Auto Instrumentations
});
// Start the OpenTelemetry tracing SDK
sdk.start()
.then(() => console.log('Tracing initialized'))
.catch((error) => console.log('Error initializing tracing', error));
// On shutdown, ensure we flush all telemetry first
process.on('SIGTERM', () => {
sdk.shutdown()
.then(() => console.log('Tracing terminated'))
.catch((error) => console.log('Error terminating tracing', error))
.finally(() => process.exit(0));
});