From 13ee66b81d4730dbc4cce36685e02ac3313d4209 Mon Sep 17 00:00:00 2001 From: Marc Pichler Date: Tue, 18 Apr 2023 13:20:58 +0200 Subject: [PATCH] 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()], ]);