-
Notifications
You must be signed in to change notification settings - Fork 0
/
useOpentelemetry.js
57 lines (45 loc) · 1.57 KB
/
useOpentelemetry.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
import {
ConsoleSpanExporter,
SimpleSpanProcessor,
BatchSpanProcessor,
} from "@opentelemetry/tracing";
import { WebTracerProvider } from "@opentelemetry/web";
import { ZoneContextManager } from "@opentelemetry/context-zone";
import { CollectorTraceExporter } from "@opentelemetry/exporter-collector";
import { B3Propagator } from "@opentelemetry/propagator-b3";
import { getWebAutoInstrumentations } from "@opentelemetry/auto-instrumentations-web";
import { registerInstrumentations } from "@opentelemetry/instrumentation";
import { Resource } from "@opentelemetry/resources";
import { ResourceAttributes } from "@opentelemetry/semantic-conventions";
const useOpentelemetry = () => {
const resource = new Resource({
[ResourceAttributes.SERVICE_NAME]: "NEXTJS APP",
});
const provider = new WebTracerProvider({ resource });
provider.addSpanProcessor(
new SimpleSpanProcessor(
new CollectorTraceExporter({
url: "http://localhost:55681/v1/traces",
headers: {},
})
)
);
provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter()));
provider.register({
contextManager: new ZoneContextManager(),
propagator: new B3Propagator(),
});
const instrumentations = getWebAutoInstrumentations({
"@opentelemetry/instrumentation-xml-http-request": {
ignoreUrls: [],
propagateTraceHeaderCorsUrls: ["http://localhost:3000"],
clearTimingResources: true,
},
});
registerInstrumentations({
instrumentations,
tracerProvider: provider,
});
return null;
};
export default useOpentelemetry;