forked from open-telemetry/opentelemetry-js-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtracer.js
41 lines (34 loc) · 1.26 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
39
40
41
'use strict';
const api = require('@opentelemetry/api');
const { NodeTracerProvider } = require('@opentelemetry/sdk-trace-node');
const { SimpleSpanProcessor } = require('@opentelemetry/sdk-trace-base');
const { JaegerExporter } = require('@opentelemetry/exporter-jaeger');
const { ZipkinExporter } = require('@opentelemetry/exporter-zipkin');
const { HapiInstrumentation } = require('@opentelemetry/instrumentation-hapi');
const { HttpInstrumentation } = require('@opentelemetry/instrumentation-http');
const { registerInstrumentations } = require('@opentelemetry/instrumentation');
const EXPORTER = process.env.EXPORTER || '';
module.exports = (serviceName) => {
let exporter;
if (EXPORTER === 'jaeger') {
exporter = new JaegerExporter({ serviceName });
} else {
exporter = new ZipkinExporter({ serviceName });
}
const provider = new NodeTracerProvider({
spanProcessors: [
new SimpleSpanProcessor(exporter),
],
});
// Initialize the OpenTelemetry APIs to use the NodeTracerProvider bindings
provider.register();
registerInstrumentations({
instrumentations: [
new HapiInstrumentation({
enhancedDatabaseReporting: true,
}),
new HttpInstrumentation(),
],
});
return api.trace.getTracer('hapi-example');
};