Skip to content

Commit

Permalink
feat: allow for extending BasicTracerProvider with custom registered …
Browse files Browse the repository at this point in the history
…components
  • Loading branch information
rauno56 committed Jun 14, 2022
1 parent 4a9ec4d commit b7c5ea2
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions packages/opentelemetry-sdk-trace-base/src/BasicTracerProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,23 @@ export class BasicTracerProvider implements TracerProvider {
return this.activeSpanProcessor.shutdown();
}

/**
* TS cannot yet infer the type of this.constructor:
* https://github.com/Microsoft/TypeScript/issues/3841#issuecomment-337560146
* There is no need to override either of the getters in your child class.
* The type of the registered component maps should be the same across all
* classes in the inheritance tree.
*/
protected _getPropagator(name: string): TextMapPropagator | undefined {
return BasicTracerProvider._registeredPropagators.get(name)?.();
return (
(this.constructor as typeof BasicTracerProvider)._registeredPropagators
).get(name)?.();
}

protected _getSpanExporter(name: string): SpanExporter | undefined {
return BasicTracerProvider._registeredExporters.get(name)?.();
return (
(this.constructor as typeof BasicTracerProvider)._registeredExporters
).get(name)?.();
}

protected _buildPropagatorFromEnv(): TextMapPropagator | undefined {
Expand Down

0 comments on commit b7c5ea2

Please sign in to comment.