Skip to content

Commit e30aabc

Browse files
committed
lack of config
1 parent 2b5e9de commit e30aabc

File tree

4 files changed

+24
-69
lines changed

4 files changed

+24
-69
lines changed

package-lock.json

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"@opentelemetry/instrumentation-document-load": "^0.48.0",
2828
"@opentelemetry/instrumentation-user-interaction": "^0.48.0",
2929
"@opentelemetry/instrumentation-xml-http-request": "^0.203.0",
30+
"@opentelemetry/opentelemetry-browser-detector": "^0.203.0",
3031
"@opentelemetry/resources": "^2.0.1",
3132
"@opentelemetry/sdk-trace-web": "^2.0.1",
3233
"@opentelemetry/semantic-conventions": "^1.36.0",

src/config/config.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@ export class Config {
6161
}
6262

6363
this.otlp = {
64-
rootUrl: process.env.OTEL_EXPORTER_OTLP_ENDPOINT || 'http://localhost:4318',
65-
debugInConsole: process.env.OTEL_DEBUG_IN_CONSOLE === 'true',
64+
rootUrl: 'http://localhost:4318',
65+
debugInConsole: 'true' === 'true',
6666
attrs: {
6767
serviceName: 'wsp-web-ui',
68-
serviceVersion: process.env.OTEL_SERVICE_VERSION || '0.0.1',
69-
deploymentEnvironment: process.env.OTEL_DEPLOYMENT_ENVIRONMENT || 'localhost',
68+
serviceVersion: '0.0.1',
69+
deploymentEnvironment: 'localhost',
7070
},
7171
}
7272
}

src/instrumentation.ts

Lines changed: 3 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,23 @@ import { DocumentLoadInstrumentation } from '@opentelemetry/instrumentation-docu
55
import { UserInteractionInstrumentation } from '@opentelemetry/instrumentation-user-interaction'
66
import { XMLHttpRequestInstrumentation } from '@opentelemetry/instrumentation-xml-http-request'
77
import { GlobalConfig } from './config/config.ts'
8-
import { resourceFromAttributes } from '@opentelemetry/resources'
8+
import { detectResources, resourceFromAttributes } from '@opentelemetry/resources'
99
import { ATTR_SERVICE_NAME, ATTR_SERVICE_VERSION, SemanticResourceAttributes } from '@opentelemetry/semantic-conventions'
1010
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http'
11+
import { browserDetector } from '@opentelemetry/opentelemetry-browser-detector'
1112

1213
/*
1314
Useful links:
1415
https://opentelemetry.io/docs/languages/js/getting-started/browser/
1516
https://opentelemetry.io/docs/concepts/semantic-conventions/
1617
*/
17-
1818
const provider = new WebTracerProvider({
1919
spanProcessors: getProcessors(),
2020
resource: resourceFromAttributes({
2121
[ATTR_SERVICE_NAME]: GlobalConfig.otlp.attrs.serviceName,
2222
[ATTR_SERVICE_VERSION]: GlobalConfig.otlp.attrs.serviceVersion,
2323
[SemanticResourceAttributes.DEPLOYMENT_ENVIRONMENT]: GlobalConfig.otlp.attrs.deploymentEnvironment,
24-
}),
24+
}).merge(detectResources({ detectors: [browserDetector] })),
2525
})
2626

2727
provider.register({
@@ -44,65 +44,3 @@ function getProcessors(): SpanProcessor[] {
4444
registerInstrumentations({
4545
instrumentations: [new UserInteractionInstrumentation(), new XMLHttpRequestInstrumentation(), new DocumentLoadInstrumentation()],
4646
})
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

Comments
 (0)