forked from open-telemetry/opentelemetry-js-contrib
-
Notifications
You must be signed in to change notification settings - Fork 1
/
tracer.js
38 lines (32 loc) · 1.1 KB
/
tracer.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
'use strict';
const opentelemetry = require('@opentelemetry/api');
const { NodeTracerProvider } = require('@opentelemetry/node');
const { SimpleSpanProcessor } = require('@opentelemetry/tracing');
const { JaegerExporter } = require('@opentelemetry/exporter-jaeger');
const { ZipkinExporter } = require('@opentelemetry/exporter-zipkin');
const EXPORTER = process.env.EXPORTER || '';
module.exports = (serviceName) => {
const provider = new NodeTracerProvider({
plugins: {
'@hapi/hapi': {
enabled: true,
path: '@opentelemetry/hapi-instrumentation',
enhancedDatabaseReporting: true,
},
http: {
enabled: true,
path: '@opentelemetry/plugin-http',
},
},
});
let exporter;
if (EXPORTER === 'jaeger') {
exporter = new JaegerExporter({ serviceName });
} else {
exporter = new ZipkinExporter({ serviceName });
}
provider.addSpanProcessor(new SimpleSpanProcessor(exporter));
// Initialize the OpenTelemetry APIs to use the NodeTracerProvider bindings
provider.register();
return opentelemetry.trace.getTracer('hapi-example');
};