Skip to content

Commit

Permalink
fix(sdk-node): extract JaegerExporter creation to named static method
Browse files Browse the repository at this point in the history
  • Loading branch information
pichlermarc committed Apr 18, 2023
1 parent 25b34ba commit 13ee66b
Showing 1 changed file with 16 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()],
]);

Expand Down

0 comments on commit 13ee66b

Please sign in to comment.