forked from newrelic-forks/microservices-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tracing.js
36 lines (31 loc) · 1.07 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 { NodeTracerProvider } = require('@opentelemetry/node')
const { BatchSpanProcessor } = require('@opentelemetry/tracing')
const { ZipkinExporter } = require('@opentelemetry/exporter-zipkin')
const { Resource, SERVICE_RESOURCE } = require('@opentelemetry/resources')
const os = require('os')
const identifier = process.env.HOSTNAME || os.hostname()
const instanceResource = new Resource({
[SERVICE_RESOURCE.INSTANCE_ID]: identifier,
[SERVICE_RESOURCE.NAME]: 'PaymentService'
})
const mergedResource = Resource.createTelemetrySDKResource().merge(instanceResource)
const NR_ZIPKIN_HEADERS = {
'Api-Key': process.env.NEW_RELIC_API_KEY,
'Data-Format': 'zipkin',
'Data-Format-Version': '2',
}
const traceProvider = new NodeTracerProvider({
resource: mergedResource
})
traceProvider.addSpanProcessor(
new BatchSpanProcessor(
new ZipkinExporter({
url: process.env.NEW_RELIC_TRACE_URL,
headers: NR_ZIPKIN_HEADERS,
statusCodeTagName: 'otel.status_code',
statusDescriptionTagName: 'otel.status_description'
})
)
)
traceProvider.register()