diff --git a/packages/opentelemetry-sdk-trace-base/src/BasicTracerProvider.ts b/packages/opentelemetry-sdk-trace-base/src/BasicTracerProvider.ts index e72e6b0cfb..4c028448b4 100644 --- a/packages/opentelemetry-sdk-trace-base/src/BasicTracerProvider.ts +++ b/packages/opentelemetry-sdk-trace-base/src/BasicTracerProvider.ts @@ -96,6 +96,7 @@ export class BasicTracerProvider implements TracerProvider { this._tracers.set(key, new Tracer({ name, version }, this._config, this)); } + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion return this._tracers.get(key)!; } @@ -133,7 +134,7 @@ export class BasicTracerProvider implements TracerProvider { * * @param config Configuration object for SDK registration */ - register(config: SDKRegistrationConfig = {}) { + register(config: SDKRegistrationConfig = {}): void { trace.setGlobalTracerProvider(this); if (config.propagator === undefined) { config.propagator = this._buildPropagatorFromEnv(); @@ -197,7 +198,7 @@ export class BasicTracerProvider implements TracerProvider { }); } - shutdown() { + shutdown(): Promise { return this.activeSpanProcessor.shutdown(); } diff --git a/packages/opentelemetry-sdk-trace-base/src/Span.ts b/packages/opentelemetry-sdk-trace-base/src/Span.ts index 32226332dc..429bf06e8d 100644 --- a/packages/opentelemetry-sdk-trace-base/src/Span.ts +++ b/packages/opentelemetry-sdk-trace-base/src/Span.ts @@ -188,7 +188,7 @@ export class Span implements api.Span, ReadableSpan { return this._ended === false; } - recordException(exception: api.Exception, time: api.TimeInput = hrTime()) { + recordException(exception: api.Exception, time: api.TimeInput = hrTime()): void { const attributes: api.SpanAttributes = {}; if (typeof exception === 'string') { attributes[SemanticAttributes.EXCEPTION_MESSAGE] = exception; diff --git a/packages/opentelemetry-sdk-trace-base/src/Tracer.ts b/packages/opentelemetry-sdk-trace-base/src/Tracer.ts index 446e944189..f39d55d9fd 100644 --- a/packages/opentelemetry-sdk-trace-base/src/Tracer.ts +++ b/packages/opentelemetry-sdk-trace-base/src/Tracer.ts @@ -27,6 +27,7 @@ import { BasicTracerProvider } from './BasicTracerProvider'; import { Span } from './Span'; import { SpanLimits, TracerConfig } from './types'; import { mergeConfig } from './utility'; +import { SpanProcessor } from './SpanProcessor'; /** * This class represents a basic tracer. @@ -216,7 +217,7 @@ export class Tracer implements api.Tracer { return this._spanLimits; } - getActiveSpanProcessor() { + getActiveSpanProcessor(): SpanProcessor { return this._tracerProvider.getActiveSpanProcessor(); } } diff --git a/packages/opentelemetry-sdk-trace-base/src/config.ts b/packages/opentelemetry-sdk-trace-base/src/config.ts index 042427d04a..7ed67c2b12 100644 --- a/packages/opentelemetry-sdk-trace-base/src/config.ts +++ b/packages/opentelemetry-sdk-trace-base/src/config.ts @@ -48,12 +48,12 @@ export const DEFAULT_CONFIG = { /** * Based on environment, builds a sampler, complies with specification. - * @param env optional, by default uses getEnv(), but allows passing a value to reuse parsed environment + * @param environment optional, by default uses getEnv(), but allows passing a value to reuse parsed environment */ export function buildSamplerFromEnv( - env: Required = getEnv() + environment: Required = getEnv() ): Sampler { - switch (env.OTEL_TRACES_SAMPLER) { + switch (environment.OTEL_TRACES_SAMPLER) { case TracesSamplerValues.AlwaysOn: return new AlwaysOnSampler(); case TracesSamplerValues.AlwaysOff: @@ -67,25 +67,25 @@ export function buildSamplerFromEnv( root: new AlwaysOffSampler(), }); case TracesSamplerValues.TraceIdRatio: - return new TraceIdRatioBasedSampler(getSamplerProbabilityFromEnv(env)); + return new TraceIdRatioBasedSampler(getSamplerProbabilityFromEnv(environment)); case TracesSamplerValues.ParentBasedTraceIdRatio: return new ParentBasedSampler({ - root: new TraceIdRatioBasedSampler(getSamplerProbabilityFromEnv(env)), + root: new TraceIdRatioBasedSampler(getSamplerProbabilityFromEnv(environment)), }); default: diag.error( - `OTEL_TRACES_SAMPLER value "${env.OTEL_TRACES_SAMPLER} invalid, defaulting to ${FALLBACK_OTEL_TRACES_SAMPLER}".` + `OTEL_TRACES_SAMPLER value "${environment.OTEL_TRACES_SAMPLER} invalid, defaulting to ${FALLBACK_OTEL_TRACES_SAMPLER}".` ); return new AlwaysOnSampler(); } } function getSamplerProbabilityFromEnv( - env: Required + environment: Required ): number | undefined { if ( - env.OTEL_TRACES_SAMPLER_ARG === undefined || - env.OTEL_TRACES_SAMPLER_ARG === '' + environment.OTEL_TRACES_SAMPLER_ARG === undefined || + environment.OTEL_TRACES_SAMPLER_ARG === '' ) { diag.error( `OTEL_TRACES_SAMPLER_ARG is blank, defaulting to ${DEFAULT_RATIO}.` @@ -93,18 +93,18 @@ function getSamplerProbabilityFromEnv( return DEFAULT_RATIO; } - const probability = Number(env.OTEL_TRACES_SAMPLER_ARG); + const probability = Number(environment.OTEL_TRACES_SAMPLER_ARG); if (isNaN(probability)) { diag.error( - `OTEL_TRACES_SAMPLER_ARG=${env.OTEL_TRACES_SAMPLER_ARG} was given, but it is invalid, defaulting to ${DEFAULT_RATIO}.` + `OTEL_TRACES_SAMPLER_ARG=${environment.OTEL_TRACES_SAMPLER_ARG} was given, but it is invalid, defaulting to ${DEFAULT_RATIO}.` ); return DEFAULT_RATIO; } if (probability < 0 || probability > 1) { diag.error( - `OTEL_TRACES_SAMPLER_ARG=${env.OTEL_TRACES_SAMPLER_ARG} was given, but it is out of range ([0..1]), defaulting to ${DEFAULT_RATIO}.` + `OTEL_TRACES_SAMPLER_ARG=${environment.OTEL_TRACES_SAMPLER_ARG} was given, but it is out of range ([0..1]), defaulting to ${DEFAULT_RATIO}.` ); return DEFAULT_RATIO; } diff --git a/packages/opentelemetry-sdk-trace-base/src/export/InMemorySpanExporter.ts b/packages/opentelemetry-sdk-trace-base/src/export/InMemorySpanExporter.ts index 4a49892899..c7c17d80c1 100644 --- a/packages/opentelemetry-sdk-trace-base/src/export/InMemorySpanExporter.ts +++ b/packages/opentelemetry-sdk-trace-base/src/export/InMemorySpanExporter.ts @@ -51,7 +51,7 @@ export class InMemorySpanExporter implements SpanExporter { return Promise.resolve(); } - reset() { + reset(): void { this._finishedSpans = []; } diff --git a/packages/opentelemetry-sdk-trace-base/src/utility.ts b/packages/opentelemetry-sdk-trace-base/src/utility.ts index 88ac69701c..542c26925e 100644 --- a/packages/opentelemetry-sdk-trace-base/src/utility.ts +++ b/packages/opentelemetry-sdk-trace-base/src/utility.ts @@ -14,14 +14,15 @@ * limitations under the License. */ +import { Sampler } from '@opentelemetry/api'; import { buildSamplerFromEnv, DEFAULT_CONFIG } from './config'; -import { TracerConfig } from './types'; +import { SpanLimits, TracerConfig } from './types'; /** * Function to merge Default configuration (as specified in './config') with * user provided configurations. */ -export function mergeConfig(userConfig: TracerConfig) { +export function mergeConfig(userConfig: TracerConfig): TracerConfig & { sampler: Sampler; spanLimits: SpanLimits } { const perInstanceDefaults: Partial = { sampler: buildSamplerFromEnv(), }; diff --git a/packages/opentelemetry-sdk-trace-base/test/common/BasicTracerProvider.test.ts b/packages/opentelemetry-sdk-trace-base/test/common/BasicTracerProvider.test.ts index 220b71d6cf..581a30f855 100644 --- a/packages/opentelemetry-sdk-trace-base/test/common/BasicTracerProvider.test.ts +++ b/packages/opentelemetry-sdk-trace-base/test/common/BasicTracerProvider.test.ts @@ -46,7 +46,7 @@ import { } from '../../src'; describe('BasicTracerProvider', () => { - let removeEvent: Function | undefined; + let removeEvent: (() => void) | undefined; const envSource = (typeof window !== 'undefined' ? window : process.env) as any; @@ -267,7 +267,7 @@ describe('BasicTracerProvider', () => { provider.register(); assert.ok( errorStub.getCall(0).args[0] === - 'Exporter "missing-exporter" requested through environment variable is unavailable.' + 'Exporter "missing-exporter" requested through environment variable is unavailable.' ); errorStub.restore(); }); diff --git a/packages/opentelemetry-sdk-trace-base/test/common/MultiSpanProcessor.test.ts b/packages/opentelemetry-sdk-trace-base/test/common/MultiSpanProcessor.test.ts index 5c263caa4f..7412a121ca 100644 --- a/packages/opentelemetry-sdk-trace-base/test/common/MultiSpanProcessor.test.ts +++ b/packages/opentelemetry-sdk-trace-base/test/common/MultiSpanProcessor.test.ts @@ -45,7 +45,7 @@ class TestProcessor implements SpanProcessor { } describe('MultiSpanProcessor', () => { - let removeEvent: Function | undefined; + let removeEvent: (() => void) | undefined; afterEach(() => { if (removeEvent) { removeEvent();