-
Notifications
You must be signed in to change notification settings - Fork 4
/
tracing.js
54 lines (51 loc) · 1.52 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
const { BatchSpanProcessor } = require('@opentelemetry/sdk-trace-base')
const { Resource } = require('@opentelemetry/resources')
const { NodeSDK } = require('@opentelemetry/sdk-node')
const { OTLPTraceExporter } = require('@opentelemetry/exporter-trace-otlp-http')
const { SemanticResourceAttributes } = require('@opentelemetry/semantic-conventions')
const {
getNodeAutoInstrumentations,
} = require('@opentelemetry/auto-instrumentations-node')
const exporter = new OTLPTraceExporter({
timeoutMillis: 2000,
url: process.env.OTEL_URL,
headers: {
Authorization: process.env.OTEL_TOKEN
},
})
const sdk = new NodeSDK({
resource: new Resource({
[SemanticResourceAttributes.SERVICE_NAME]: 'danube-api',
'cx.application.name': 'danube-api',
'cx.subsystem.name': 'express',
}),
traceExporter: exporter,
spanProcessor: new BatchSpanProcessor(exporter),
instrumentations: [getNodeAutoInstrumentations({
'@opentelemetry/instrumentation-hapi': {
enabled: false,
},
'@opentelemetry/instrumentation-fs': {
enabled: false,
},
'@opentelemetry/instrumentation-net': {
enabled: false,
},
'@opentelemetry/instrumentation-dns': {
enabled: false,
},
'@opentelemetry/instrumentation-http': {
enabled: true,
},
})],
})
sdk.start()
process.on("SIGTERM", () => {
sdk
.shutdown()
.then(
() => console.log("SDK shut down successfully"),
(err) => console.log("Error shutting down SDK", err)
)
.finally(() => process.exit(0));
});