-
Notifications
You must be signed in to change notification settings - Fork 0
/
tracer.js
58 lines (51 loc) · 1.82 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
const { trace, context } = require("@opentelemetry/api");
const { Resource } = require("@opentelemetry/resources");
const {
SemanticResourceAttributes,
} = require("@opentelemetry/semantic-conventions");
const { BatchSpanProcessor } = require("@opentelemetry/sdk-trace-base");
const { NodeTracerProvider } = require("@opentelemetry/sdk-trace-node");
const { ConsoleSpanExporter } = require("@opentelemetry/sdk-trace-base");
const { ZipkinExporter } = require("@opentelemetry/exporter-zipkin");
// const {
// OTLPTraceExporter,
// } = require("@opentelemetry/exporter-trace-otlp-http");
const {
ExpressInstrumentation,
} = require("opentelemetry-instrumentation-express");
const { HttpInstrumentation } = require("@opentelemetry/instrumentation-http");
const { registerInstrumentations } = require("@opentelemetry/instrumentation");
module.exports = () => {
const provider = new NodeTracerProvider({
resource: new Resource({
[SemanticResourceAttributes.SERVICE_NAME]: process.env.OTEL_SERVICE_NAME,
}),
});
provider.addSpanProcessor(
new BatchSpanProcessor(
new ZipkinExporter({
url: `${process.env.OTEL_API_HOST}/api/v2/spans`,
serviceName: process.env.OTEL_SERVICE_NAME,
})
)
);
// provider.addSpanProcessor(new BatchSpanProcessor(new ConsoleSpanExporter()));
// provider.addSpanProcessor(
// new BatchSpanProcessor(
// new OTLPTraceExporter({
// url: process.env.OTEL_API_HOST,
// })
// )
// );
provider.register();
registerInstrumentations({
instrumentations: [
new HttpInstrumentation(),
new ExpressInstrumentation({ includeHttpAttributes: true }),
],
tracerProvider: provider,
});
const tracer = trace.getTracer(process.env.OTEL_SERVICE_NAME);
tracer.startSpan("ROOT", {}, context.ROOT_CONTEXT);
return { tracer };
};