forked from open-telemetry/opentelemetry-js-contrib
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtracer.js
40 lines (34 loc) · 1.39 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
'use strict';
const opentelemetry = require('@opentelemetry/api');
const { NodeTracerProvider } = require('@opentelemetry/sdk-trace-node');
const { SimpleSpanProcessor, ConsoleSpanExporter } = require('@opentelemetry/sdk-trace-base');
const { HttpTraceContextPropagator } = require('@opentelemetry/core');
const { GrpcCensusPropagator } = require('@opentelemetry/propagator-grpc-census-binary');
const { registerInstrumentations } = require('@opentelemetry/instrumentation');
const { GrpcInstrumentation } = require('@opentelemetry/instrumentation-grpc');
/**
* Return an OpenTelemetry tracer configured to use the gRPC plugin and with the
* requested propagator
*/
module.exports = (serviceName, binaryPropagator) => {
const provider = new NodeTracerProvider();
// It is recommended to use this `BatchSpanProcessor` for better performance
// and optimization, especially in production.
provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter()));
if (binaryPropagator) {
// Initialize the OpenTelemetry APIs to use the NodeTracerProvider bindings
provider.register({
propagator: new GrpcCensusPropagator(),
});
} else {
provider.register({
propagator: new HttpTraceContextPropagator(),
});
}
registerInstrumentations({
instrumentations: [
new GrpcInstrumentation(),
],
});
return opentelemetry.trace.getTracer(serviceName);
};