-
Notifications
You must be signed in to change notification settings - Fork 4
/
trace-instrumentation.js
36 lines (30 loc) · 1.01 KB
/
trace-instrumentation.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 opentelemetry = require('@opentelemetry/sdk-node')
const { HttpInstrumentation } = require('@opentelemetry/instrumentation-http')
const { PinoInstrumentation } = require('@opentelemetry/instrumentation-pino')
const { Resource } = require('@opentelemetry/resources')
const { ConsoleSpanExporter } = require('@opentelemetry/sdk-trace-node')
const {
SemanticResourceAttributes
} = require('@opentelemetry/semantic-conventions')
const traceExporter = new ConsoleSpanExporter()
const instrumentations = [
new HttpInstrumentation(),
new PinoInstrumentation()
]
const sdk = new opentelemetry.NodeSDK({
resource: new Resource({
[SemanticResourceAttributes.SERVICE_NAME]: 'Pino OpenTelemetry Example'
}),
traceExporter,
instrumentations
})
sdk.start()
process.on('SIGTERM', () => {
sdk
.shutdown()
.then(() => console.log('Tracing terminated'))
.catch(error => console.log('Error terminating tracing', error))
.finally(() => process.exit(0))
})