From 921900f868c3d7c56d678787a8177fab73eae516 Mon Sep 17 00:00:00 2001 From: Marc Pichler Date: Tue, 18 Apr 2023 09:59:02 +0200 Subject: [PATCH 1/4] fix(sdk-node): lazy require @opentelemetry/exporter-jaeger --- .../src/TracerProviderWithEnvExporter.ts | 19 +++++++++++++++++-- .../opentelemetry-exporter-jaeger/README.md | 2 ++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/experimental/packages/opentelemetry-sdk-node/src/TracerProviderWithEnvExporter.ts b/experimental/packages/opentelemetry-sdk-node/src/TracerProviderWithEnvExporter.ts index add81c7c91..5e7d163e75 100644 --- a/experimental/packages/opentelemetry-sdk-node/src/TracerProviderWithEnvExporter.ts +++ b/experimental/packages/opentelemetry-sdk-node/src/TracerProviderWithEnvExporter.ts @@ -32,7 +32,6 @@ import { OTLPTraceExporter as OTLPProtoTraceExporter } from '@opentelemetry/expo import { OTLPTraceExporter as OTLPHttpTraceExporter } from '@opentelemetry/exporter-trace-otlp-http'; import { OTLPTraceExporter as OTLPGrpcTraceExporter } from '@opentelemetry/exporter-trace-otlp-grpc'; import { ZipkinExporter } from '@opentelemetry/exporter-zipkin'; -import { JaegerExporter } from '@opentelemetry/exporter-jaeger'; export class TracerProviderWithEnvExporters extends NodeTracerProvider { private _configuredExporters: SpanExporter[] = []; @@ -74,7 +73,23 @@ export class TracerProviderWithEnvExporters extends NodeTracerProvider { >([ ['otlp', () => this.configureOtlp()], ['zipkin', () => new ZipkinExporter()], - ['jaeger', () => new JaegerExporter()], + [ + 'jaeger', + () => { + // The JaegerExporter does not support being required in bundled + // environments. By delaying the require statement to here, we only crash when + // the exporter is actually used in such an environment. + try { + // eslint-disable-next-line @typescript-eslint/no-var-requires + const { JaegerExporter } = require('@opentelemetry/exporter-jaeger'); + return new JaegerExporter(); + } catch (e) { + throw new Error( + `Could not instantiate JaegerExporter. This could be due to the JaegerExporter's lack of support for bundling. If possible, use @opentelemetry/exporter-trace-otlp-proto instead. Original Error: ${e}` + ); + } + }, + ], ['console', () => new ConsoleSpanExporter()], ]); diff --git a/packages/opentelemetry-exporter-jaeger/README.md b/packages/opentelemetry-exporter-jaeger/README.md index 4adceb9b74..7e662a345e 100644 --- a/packages/opentelemetry-exporter-jaeger/README.md +++ b/packages/opentelemetry-exporter-jaeger/README.md @@ -9,6 +9,8 @@ - `@opentelemetry/exporter-trace-otlp-grpc` - `@opentelemetry/exporter-trace-otlp-http` +**NOTE: Bundling (with e.g. `webpack`, `rollup`, `esbuild`, ...) is not supported by this package. Please use `@opentelemetry/exporter-trace-otlp-proto` instead.** + OpenTelemetry Jaeger Trace Exporter allows the user to send collected traces to Jaeger. [Jaeger](https://jaeger.readthedocs.io/en/latest/), inspired by [Dapper](https://research.google.com/pubs/pub36356.html) and [OpenZipkin](http://zipkin.io/), is a distributed tracing system released as open source by [Uber Technologies](http://uber.github.io/). It is used for monitoring and troubleshooting microservices-based distributed systems, including: From fc3128a2c81ebad181088c53af76b7304512880f Mon Sep 17 00:00:00 2001 From: Marc Pichler Date: Tue, 18 Apr 2023 10:09:47 +0200 Subject: [PATCH 2/4] fix(changlog): add changelog entry --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 55f17b5742..7e67880a58 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,8 @@ For experimental package changes, see the [experimental CHANGELOG](experimental/ ### :bug: (Bug Fix) +* fix(sdk-node): lazy require @opentelemetry/exporter-jaeger [#3739](https://github.com/open-telemetry/opentelemetry-js/pull/3739) @pichlermarc + ### :books: (Refine Doc) ### :house: (Internal) From 13ee66b81d4730dbc4cce36685e02ac3313d4209 Mon Sep 17 00:00:00 2001 From: Marc Pichler Date: Tue, 18 Apr 2023 13:20:58 +0200 Subject: [PATCH 3/4] fix(sdk-node): extract JaegerExporter creation to named static method --- .../src/TracerProviderWithEnvExporter.ts | 33 +++++++++---------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/experimental/packages/opentelemetry-sdk-node/src/TracerProviderWithEnvExporter.ts b/experimental/packages/opentelemetry-sdk-node/src/TracerProviderWithEnvExporter.ts index 5e7d163e75..a4b9ee1286 100644 --- a/experimental/packages/opentelemetry-sdk-node/src/TracerProviderWithEnvExporter.ts +++ b/experimental/packages/opentelemetry-sdk-node/src/TracerProviderWithEnvExporter.ts @@ -67,29 +67,28 @@ export class TracerProviderWithEnvExporters extends NodeTracerProvider { ); } + private static configureJaeger() { + // The JaegerExporter does not support being required in bundled + // environments. By delaying the require statement to here, we only crash when + // the exporter is actually used in such an environment. + try { + // eslint-disable-next-line @typescript-eslint/no-var-requires + const { JaegerExporter } = require('@opentelemetry/exporter-jaeger'); + return new JaegerExporter(); + } catch (e) { + throw new Error( + `Could not instantiate JaegerExporter. This could be due to the JaegerExporter's lack of support for bundling. If possible, use @opentelemetry/exporter-trace-otlp-proto instead. Original Error: ${e}` + ); + } + } + protected static override _registeredExporters = new Map< string, () => SpanExporter >([ ['otlp', () => this.configureOtlp()], ['zipkin', () => new ZipkinExporter()], - [ - 'jaeger', - () => { - // The JaegerExporter does not support being required in bundled - // environments. By delaying the require statement to here, we only crash when - // the exporter is actually used in such an environment. - try { - // eslint-disable-next-line @typescript-eslint/no-var-requires - const { JaegerExporter } = require('@opentelemetry/exporter-jaeger'); - return new JaegerExporter(); - } catch (e) { - throw new Error( - `Could not instantiate JaegerExporter. This could be due to the JaegerExporter's lack of support for bundling. If possible, use @opentelemetry/exporter-trace-otlp-proto instead. Original Error: ${e}` - ); - } - }, - ], + ['jaeger', () => this.configureJaeger()], ['console', () => new ConsoleSpanExporter()], ]); From 93c2ef3e91d375f5b9524501ae2975df356a82ca Mon Sep 17 00:00:00 2001 From: Marc Pichler Date: Mon, 24 Apr 2023 10:39:03 +0200 Subject: [PATCH 4/4] fix(changelog): reword changelog entry Co-authored-by: Daniel Dyla --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e67880a58..9c4b2f297a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,7 +13,7 @@ For experimental package changes, see the [experimental CHANGELOG](experimental/ ### :bug: (Bug Fix) -* fix(sdk-node): lazy require @opentelemetry/exporter-jaeger [#3739](https://github.com/open-telemetry/opentelemetry-js/pull/3739) @pichlermarc +* fix(sdk-node): fix initialization in bundled environments by not loading @opentelemetry/exporter-jaeger [#3739](https://github.com/open-telemetry/opentelemetry-js/pull/3739) @pichlermarc ### :books: (Refine Doc)