diff --git a/autoinstrumentation/nodejs/package.json b/autoinstrumentation/nodejs/package.json index 39dcd58d68..e31710f035 100644 --- a/autoinstrumentation/nodejs/package.json +++ b/autoinstrumentation/nodejs/package.json @@ -4,8 +4,6 @@ "private": true, "scripts": { "clean": "rimraf build/*", - "prepare": "npm run compile", - "compile": "tsc -p .", "postcompile": "copyfiles -f 'build/src/**' build/workspace/ && copyfiles 'node_modules/**' package.json build/workspace/ && npm -C build/workspace prune --omit=dev --no-package-lock" }, "devDependencies": { diff --git a/autoinstrumentation/nodejs/src/autoinstrumentation.ts b/autoinstrumentation/nodejs/src/autoinstrumentation.ts deleted file mode 100644 index 5b3388f69d..0000000000 --- a/autoinstrumentation/nodejs/src/autoinstrumentation.ts +++ /dev/null @@ -1,84 +0,0 @@ -import { getNodeAutoInstrumentations, getResourceDetectors } from '@opentelemetry/auto-instrumentations-node'; -import { OTLPTraceExporter as OTLPProtoTraceExporter } from '@opentelemetry/exporter-trace-otlp-proto'; -import { OTLPTraceExporter as OTLPHttpTraceExporter } from '@opentelemetry/exporter-trace-otlp-http'; -import { OTLPTraceExporter as OTLPGrpcTraceExporter } from '@opentelemetry/exporter-trace-otlp-grpc'; -import { OTLPMetricExporter } from '@opentelemetry/exporter-metrics-otlp-grpc'; -import { PrometheusExporter } from '@opentelemetry/exporter-prometheus'; -import { PeriodicExportingMetricReader } from '@opentelemetry/sdk-metrics'; -import { diag, DiagConsoleLogger } from '@opentelemetry/api'; - -import { NodeSDK, core } from '@opentelemetry/sdk-node'; - -diag.setLogger( - new DiagConsoleLogger(), - core.getEnv().OTEL_LOG_LEVEL -); - - -function getTraceExporter() { - let protocol = process.env.OTEL_EXPORTER_OTLP_PROTOCOL; - switch (protocol) { - case undefined: - case '': - case 'grpc': - return new OTLPGrpcTraceExporter(); - case 'http/json': - return new OTLPHttpTraceExporter(); - case 'http/protobuf': - return new OTLPProtoTraceExporter(); - default: - throw Error(`Creating traces exporter based on "${protocol}" protocol (configured via environment variable OTEL_EXPORTER_OTLP_PROTOCOL) is not implemented!`); - } -} - -function getMetricReader() { - switch (process.env.OTEL_METRICS_EXPORTER) { - case undefined: - case '': - case 'otlp': - diag.info('using otel metrics exporter'); - return new PeriodicExportingMetricReader({ - exporter: new OTLPMetricExporter(), - }); - case 'prometheus': - diag.info('using prometheus metrics exporter'); - return new PrometheusExporter({}); - case 'none': - diag.info('disabling metrics reader'); - return undefined; - default: - throw Error(`no valid option for OTEL_METRICS_EXPORTER: ${process.env.OTEL_METRICS_EXPORTER}`) - } -} - -const sdk = new NodeSDK({ - autoDetectResources: true, - instrumentations: getNodeAutoInstrumentations(), - traceExporter: getTraceExporter(), - metricReader: getMetricReader(), - resourceDetectors: getResourceDetectors() -}); - -try { - sdk.start(); - diag.info('OpenTelemetry automatic instrumentation started successfully'); -} catch (error) { - diag.error( - 'Error initializing OpenTelemetry SDK. Your application is not instrumented and will not produce telemetry', - error - ); -} - -async function shutdown(): Promise { - try { - await sdk.shutdown(); - diag.debug('OpenTelemetry SDK terminated'); - } catch (error) { - diag.error('Error terminating OpenTelemetry SDK', error); - } -} - -// Gracefully shutdown SDK if a SIGTERM is received -process.on('SIGTERM', shutdown); -// Gracefully shutdown SDK if Node.js is exiting normally -process.once('beforeExit', shutdown); diff --git a/pkg/instrumentation/nodejs.go b/pkg/instrumentation/nodejs.go index a3d02ea53d..889bb70936 100644 --- a/pkg/instrumentation/nodejs.go +++ b/pkg/instrumentation/nodejs.go @@ -22,7 +22,7 @@ import ( const ( envNodeOptions = "NODE_OPTIONS" - nodeRequireArgument = " --require /otel-auto-instrumentation-nodejs/autoinstrumentation.js" + nodeRequireArgument = " --require /otel-auto-instrumentation-nodejs/node_modules/@opentelemetry/auto-instrumentations-node/build/src/register.js" nodejsInitContainerName = initContainerName + "-nodejs" nodejsVolumeName = volumeName + "-nodejs" nodejsInstrMountPath = "/otel-auto-instrumentation-nodejs" diff --git a/pkg/instrumentation/nodejs_test.go b/pkg/instrumentation/nodejs_test.go index 7ed4fcd6d3..c4d29df7cd 100644 --- a/pkg/instrumentation/nodejs_test.go +++ b/pkg/instrumentation/nodejs_test.go @@ -76,7 +76,7 @@ func TestInjectNodeJSSDK(t *testing.T) { Env: []corev1.EnvVar{ { Name: "NODE_OPTIONS", - Value: " --require /otel-auto-instrumentation-nodejs/autoinstrumentation.js", + Value: " --require /otel-auto-instrumentation-nodejs/node_modules/@opentelemetry/auto-instrumentations-node/build/src/register.js", }, }, }, @@ -137,7 +137,7 @@ func TestInjectNodeJSSDK(t *testing.T) { Env: []corev1.EnvVar{ { Name: "NODE_OPTIONS", - Value: "-Dbaz=bar" + " --require /otel-auto-instrumentation-nodejs/autoinstrumentation.js", + Value: "-Dbaz=bar" + " --require /otel-auto-instrumentation-nodejs/node_modules/@opentelemetry/auto-instrumentations-node/build/src/register.js"", }, }, }, diff --git a/tests/e2e-instrumentation/instrumentation-nodejs-multicontainer/01-assert.yaml b/tests/e2e-instrumentation/instrumentation-nodejs-multicontainer/01-assert.yaml index 7da5c15637..d268417e1e 100644 --- a/tests/e2e-instrumentation/instrumentation-nodejs-multicontainer/01-assert.yaml +++ b/tests/e2e-instrumentation/instrumentation-nodejs-multicontainer/01-assert.yaml @@ -21,7 +21,7 @@ spec: - name: NODE_PATH value: /usr/local/lib/node_modules - name: NODE_OPTIONS - value: ' --require /otel-auto-instrumentation-nodejs/autoinstrumentation.js' + value: ' --require /otel-auto-instrumentation-nodejs/node_modules/@opentelemetry/auto-instrumentations-node/build/src/register.js' - name: OTEL_TRACES_EXPORTER value: otlp - name: OTEL_EXPORTER_OTLP_ENDPOINT @@ -65,7 +65,7 @@ spec: fieldRef: fieldPath: status.podIP - name: NODE_OPTIONS - value: ' --require /otel-auto-instrumentation-nodejs/autoinstrumentation.js' + value: ' --require /otel-auto-instrumentation-nodejs/node_modules/@opentelemetry/auto-instrumentations-node/build/src/register.js' - name: OTEL_TRACES_EXPORTER value: otlp - name: OTEL_EXPORTER_OTLP_ENDPOINT diff --git a/tests/e2e-instrumentation/instrumentation-nodejs-multicontainer/02-assert.yaml b/tests/e2e-instrumentation/instrumentation-nodejs-multicontainer/02-assert.yaml index 0738786abd..32265deea4 100644 --- a/tests/e2e-instrumentation/instrumentation-nodejs-multicontainer/02-assert.yaml +++ b/tests/e2e-instrumentation/instrumentation-nodejs-multicontainer/02-assert.yaml @@ -32,7 +32,7 @@ spec: - name: NODE_PATH value: /usr/local/lib/node_modules - name: NODE_OPTIONS - value: ' --require /otel-auto-instrumentation-nodejs/autoinstrumentation.js' + value: ' --require /otel-auto-instrumentation-nodejs/node_modules/@opentelemetry/auto-instrumentations-node/build/src/register.js' - name: OTEL_TRACES_EXPORTER value: otlp - name: OTEL_EXPORTER_OTLP_ENDPOINT diff --git a/tests/e2e-instrumentation/instrumentation-nodejs-volume/01-assert.yaml b/tests/e2e-instrumentation/instrumentation-nodejs-volume/01-assert.yaml index 83e32efc3a..d05d36b784 100644 --- a/tests/e2e-instrumentation/instrumentation-nodejs-volume/01-assert.yaml +++ b/tests/e2e-instrumentation/instrumentation-nodejs-volume/01-assert.yaml @@ -22,7 +22,7 @@ spec: - name: OTEL_NODEJS_DEBUG value: "true" - name: NODE_OPTIONS - value: " --require /otel-auto-instrumentation-nodejs/autoinstrumentation.js" + value: " --require /otel-auto-instrumentation-nodejs/node_modules/@opentelemetry/auto-instrumentations-node/build/src/register.js" - name: OTEL_TRACES_EXPORTER value: otlp - name: OTEL_EXPORTER_OTLP_ENDPOINT diff --git a/tests/e2e-instrumentation/instrumentation-nodejs/01-assert.yaml b/tests/e2e-instrumentation/instrumentation-nodejs/01-assert.yaml index 719727ca68..b8ae547ad6 100644 --- a/tests/e2e-instrumentation/instrumentation-nodejs/01-assert.yaml +++ b/tests/e2e-instrumentation/instrumentation-nodejs/01-assert.yaml @@ -22,7 +22,7 @@ spec: - name: OTEL_NODEJS_DEBUG value: "true" - name: NODE_OPTIONS - value: ' --require /otel-auto-instrumentation-nodejs/autoinstrumentation.js' + value: ' --require /otel-auto-instrumentation-nodejs/node_modules/@opentelemetry/auto-instrumentations-node/build/src/register.js' - name: OTEL_TRACES_EXPORTER value: otlp - name: OTEL_EXPORTER_OTLP_ENDPOINT diff --git a/tests/e2e-multi-instrumentation/instrumentation-multi-multicontainer/01-assert.yaml b/tests/e2e-multi-instrumentation/instrumentation-multi-multicontainer/01-assert.yaml index 3ba921ada1..41e950418b 100644 --- a/tests/e2e-multi-instrumentation/instrumentation-multi-multicontainer/01-assert.yaml +++ b/tests/e2e-multi-instrumentation/instrumentation-multi-multicontainer/01-assert.yaml @@ -131,7 +131,7 @@ spec: - name: OTEL_SERVICE_NAME value: nodejsapp - name: NODE_OPTIONS - value: ' --require /otel-auto-instrumentation-nodejs/autoinstrumentation.js' + value: ' --require /otel-auto-instrumentation-nodejs/node_modules/@opentelemetry/auto-instrumentations-node/build/src/register.js' - name: OTEL_TRACES_SAMPLER value: parentbased_traceidratio - name: OTEL_TRACES_SAMPLER_ARG diff --git a/tests/e2e-multi-instrumentation/instrumentation-single-instr-first-container/01-assert.yaml b/tests/e2e-multi-instrumentation/instrumentation-single-instr-first-container/01-assert.yaml index 704e8b12a7..7edd414732 100644 --- a/tests/e2e-multi-instrumentation/instrumentation-single-instr-first-container/01-assert.yaml +++ b/tests/e2e-multi-instrumentation/instrumentation-single-instr-first-container/01-assert.yaml @@ -22,7 +22,7 @@ spec: - name: OTEL_SERVICE_NAME value: nodejsapp - name: NODE_OPTIONS - value: ' --require /otel-auto-instrumentation-nodejs/autoinstrumentation.js' + value: ' --require /otel-auto-instrumentation-nodejs/node_modules/@opentelemetry/auto-instrumentations-node/build/src/register.js' - name: OTEL_TRACES_SAMPLER value: parentbased_traceidratio - name: OTEL_TRACES_SAMPLER_ARG diff --git a/tests/e2e-openshift/must-gather/assert-install-app.yaml b/tests/e2e-openshift/must-gather/assert-install-app.yaml index 719727ca68..b8ae547ad6 100644 --- a/tests/e2e-openshift/must-gather/assert-install-app.yaml +++ b/tests/e2e-openshift/must-gather/assert-install-app.yaml @@ -22,7 +22,7 @@ spec: - name: OTEL_NODEJS_DEBUG value: "true" - name: NODE_OPTIONS - value: ' --require /otel-auto-instrumentation-nodejs/autoinstrumentation.js' + value: ' --require /otel-auto-instrumentation-nodejs/node_modules/@opentelemetry/auto-instrumentations-node/build/src/register.js' - name: OTEL_TRACES_EXPORTER value: otlp - name: OTEL_EXPORTER_OTLP_ENDPOINT