Skip to content

Commit

Permalink
fix(test-utils): Migrate away from deprecated addSpanProcessor
Browse files Browse the repository at this point in the history
This migrates from the deprecated `addSpanProcessor` method to the
constructor option in preparation for the upcoming SDK 2.0 release.

This commit migrates the runtime code in the test-utils package and
should be included in the package's CHANGELOG.

Ref #2645
  • Loading branch information
chancancode committed Jan 17, 2025
1 parent e57f3e4 commit 31dd654
Showing 1 changed file with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,23 @@ import {
export const registerInstrumentationTestingProvider = (
config?: NodeTracerConfig
): NodeTracerProvider => {
const otelTestingProvider = new NodeTracerProvider(config);
const spanProcessors = config?.spanProcessors
? [...config.spanProcessors]
: [];

setTestMemoryExporter(new InMemorySpanExporter());
otelTestingProvider.addSpanProcessor(
new SimpleSpanProcessor(getTestMemoryExporter()!)
);

spanProcessors.push(new SimpleSpanProcessor(getTestMemoryExporter()!));

if (process.env.OTEL_EXPORTER_JAEGER_AGENT_HOST) {
otelTestingProvider.addSpanProcessor(
new SimpleSpanProcessor(new JaegerExporter())
);
spanProcessors.push(new SimpleSpanProcessor(new JaegerExporter()));
}

const otelTestingProvider = new NodeTracerProvider({
...config,
spanProcessors,
});

otelTestingProvider.register();
return otelTestingProvider;
};

0 comments on commit 31dd654

Please sign in to comment.