-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtracing.ts
76 lines (69 loc) · 2.26 KB
/
tracing.ts
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node'
// import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http'
// import { OTLPMetricExporter } from '@opentelemetry/exporter-metrics-otlp-http'
import { Resource } from '@opentelemetry/resources'
import { NodeSDK } from '@opentelemetry/sdk-node'
import {
BatchSpanProcessor,
ConsoleSpanExporter,
} from '@opentelemetry/sdk-trace-base'
import {
PeriodicExportingMetricReader,
ConsoleMetricExporter,
} from '@opentelemetry/sdk-metrics'
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions'
import { getNodeMqttAutoInstrumentations } from '../src'
// Outputs to Jaeger
// const traceExporter = new OTLPTraceExporter({
// url: 'http://localhost:4318/v1/traces',
// })
// const metricExporter = new OTLPMetricExporter({
// url: 'http://localhost:4318/v1/metrics',
// })
// Outputs to STDOUT
const traceExporter = new ConsoleSpanExporter()
const metricExporter = new ConsoleMetricExporter()
const metricReader = new PeriodicExportingMetricReader({
exporter: metricExporter,
})
const sdk = new NodeSDK({
resource: new Resource({
[SemanticResourceAttributes.SERVICE_NAME]: 'test service',
[SemanticResourceAttributes.SERVICE_VERSION]:
process.env.npm_package_version,
[SemanticResourceAttributes.DEPLOYMENT_ENVIRONMENT]: process.env.NODE_ENV,
}),
traceExporter,
metricReader,
instrumentations: [
getNodeAutoInstrumentations({
'@opentelemetry/instrumentation-fs': {
enabled: false,
},
}),
getNodeMqttAutoInstrumentations({
'@opentelemetry/instrumentation-mqtt-packet': {
enabled: true,
},
'@opentelemetry/instrumentation-aedes': {
enabled: true,
// publishHook: (span, info) => {
// console.log('publishHook', span)
// },
// consumeHook: (span, info) => {
// console.log('consumeHook', span)
// },
// consumeEndHook: (span, info) => {
// console.log('consumeEndHook', span)
// },
},
}),
],
spanProcessor: new BatchSpanProcessor(traceExporter),
})
sdk.start()
process.on('SIGTERM', () => {
sdk
.shutdown()
.catch((error) => console.error('Error terminating tracing', error))
})