@@ -5,23 +5,23 @@ import { DocumentLoadInstrumentation } from '@opentelemetry/instrumentation-docu
5
5
import { UserInteractionInstrumentation } from '@opentelemetry/instrumentation-user-interaction'
6
6
import { XMLHttpRequestInstrumentation } from '@opentelemetry/instrumentation-xml-http-request'
7
7
import { GlobalConfig } from './config/config.ts'
8
- import { resourceFromAttributes } from '@opentelemetry/resources'
8
+ import { detectResources , resourceFromAttributes } from '@opentelemetry/resources'
9
9
import { ATTR_SERVICE_NAME , ATTR_SERVICE_VERSION , SemanticResourceAttributes } from '@opentelemetry/semantic-conventions'
10
10
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http'
11
+ import { browserDetector } from '@opentelemetry/opentelemetry-browser-detector'
11
12
12
13
/*
13
14
Useful links:
14
15
https://opentelemetry.io/docs/languages/js/getting-started/browser/
15
16
https://opentelemetry.io/docs/concepts/semantic-conventions/
16
17
*/
17
-
18
18
const provider = new WebTracerProvider ( {
19
19
spanProcessors : getProcessors ( ) ,
20
20
resource : resourceFromAttributes ( {
21
21
[ ATTR_SERVICE_NAME ] : GlobalConfig . otlp . attrs . serviceName ,
22
22
[ ATTR_SERVICE_VERSION ] : GlobalConfig . otlp . attrs . serviceVersion ,
23
23
[ SemanticResourceAttributes . DEPLOYMENT_ENVIRONMENT ] : GlobalConfig . otlp . attrs . deploymentEnvironment ,
24
- } ) ,
24
+ } ) . merge ( detectResources ( { detectors : [ browserDetector ] } ) ) ,
25
25
} )
26
26
27
27
provider . register ( {
@@ -44,65 +44,3 @@ function getProcessors(): SpanProcessor[] {
44
44
registerInstrumentations ( {
45
45
instrumentations : [ new UserInteractionInstrumentation ( ) , new XMLHttpRequestInstrumentation ( ) , new DocumentLoadInstrumentation ( ) ] ,
46
46
} )
47
-
48
- /*export const otelSDK = new NodeSDK({
49
- spanProcessors: getProcessors(),
50
- metricReader: getMetricReader(),
51
- resource: resourceFromAttributes({
52
- [ATTR_SERVICE_NAME]: GlobalConfig.otlp.attrs.serviceName,
53
- [ATTR_SERVICE_VERSION]: GlobalConfig.otlp.attrs.serviceVersion,
54
- [SemanticResourceAttributes.DEPLOYMENT_ENVIRONMENT]: GlobalConfig.otlp.attrs.deploymentEnvironment,
55
- }),
56
- instrumentations: [new SocketIoInstrumentation(), new NestInstrumentation(), new PinoInstrumentation()],
57
- })
58
-
59
- function getProcessors(): SpanProcessor[] {
60
- return [
61
- new BatchSpanProcessor(
62
- GlobalConfig.otlp.debugInConsole
63
- ? new ConsoleSpanExporter()
64
- : new OTLPTraceExporter({
65
- url: `${GlobalConfig.otlp.rootUrl}/v1/traces`,
66
- headers: {},
67
- })
68
- ),
69
- ]
70
- }
71
-
72
- function getMetricReader(): IMetricReader {
73
- return new PeriodicExportingMetricReader({
74
- exporter: GlobalConfig.otlp.debugInConsole
75
- ? new ConsoleMetricExporter()
76
- : new OTLPMetricExporter({
77
- url: `${GlobalConfig.otlp.rootUrl}/v1/metrics`,
78
- }),
79
- })
80
- }
81
-
82
- let hostMetricsSDK: HostMetrics | undefined
83
- export function getHostMetricsSDK(): HostMetrics {
84
- if (hostMetricsSDK) {
85
- return hostMetricsSDK
86
- }
87
-
88
- hostMetricsSDK = new HostMetrics({
89
- meterProvider: metrics.getMeterProvider(),
90
- })
91
- return hostMetricsSDK
92
- }
93
-
94
- function shutdownSDK(): void {
95
- otelSDK
96
- .shutdown()
97
- .then(() => {
98
- console.log('OpenTelemetry SDK shutdown successfully.')
99
- process.exit(0)
100
- })
101
- .catch((error) => {
102
- console.error('Error shutting down OpenTelemetry SDK: ', error)
103
- process.exit(1)
104
- })
105
- }
106
-
107
- process.on('SIGTERM', (): void => shutdownSDK())
108
- process.on('SIGINT', (): void => shutdownSDK())*/
0 commit comments