Skip to content

Commit

Permalink
Merge branch 'main' into upgrade-semconv
Browse files Browse the repository at this point in the history
  • Loading branch information
vmarchaud authored Sep 4, 2021
2 parents 6e44de2 + 7b01cfa commit 5a892a3
Show file tree
Hide file tree
Showing 19 changed files with 54 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class CollectorMetricExporter
);
}

getDefaultUrl(config: CollectorExporterConfigBase) {
getDefaultUrl(config: CollectorExporterConfigBase): string {
return typeof config.url === 'string'
? config.url
: getEnv().OTEL_EXPORTER_OTLP_METRICS_ENDPOINT.length > 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export abstract class CollectorExporterNodeBase<

constructor(config: CollectorExporterNodeConfigBase = {}) {
super(config);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
if ((config as any).metadata) {
diag.warn('Metadata cannot be set when using http');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class CollectorMetricExporter
);
}

getDefaultUrl(config: CollectorExporterNodeConfigBase) {
getDefaultUrl(config: CollectorExporterNodeConfigBase): string {
return typeof config.url === 'string'
? config.url
: getEnv().OTEL_EXPORTER_OTLP_METRICS_ENDPOINT.length > 0
Expand Down
1 change: 1 addition & 0 deletions packages/opentelemetry-exporter-collector/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ export namespace opentelemetryProto {
droppedAttributesCount: number;
}

// eslint-disable-next-line @typescript-eslint/no-shadow
export enum SpanKind {
SPAN_KIND_UNSPECIFIED,
SPAN_KIND_INTERNAL,
Expand Down
14 changes: 6 additions & 8 deletions packages/opentelemetry-instrumentation-fetch/src/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export class FetchInstrumentation extends InstrumentationBase<
);
}

init() {}
init(): void {}

private _getConfig(): FetchInstrumentationConfig {
return this._config;
Expand Down Expand Up @@ -326,11 +326,9 @@ export class FetchInstrumentation extends InstrumentationBase<
}
function onSuccess(
span: api.Span,
resolve: (
value?: Response | PromiseLike<Response> | undefined
) => void,
resolve: (value: Response | PromiseLike<Response>) => void,
response: Response
) {
): void {
try {
const resClone = response.clone();
const body = resClone.body;
Expand Down Expand Up @@ -381,7 +379,7 @@ export class FetchInstrumentation extends InstrumentationBase<
return original
.apply(this, options instanceof Request ? [options] : [url, options])
.then(
(onSuccess as any).bind(this, createdSpan, resolve),
onSuccess.bind(this, createdSpan, resolve),
onError.bind(this, createdSpan, reject)
);
}
Expand Down Expand Up @@ -447,7 +445,7 @@ export class FetchInstrumentation extends InstrumentationBase<
/**
* implements enable function
*/
override enable() {
override enable(): void {
if (isWrapped(window.fetch)) {
this._unwrap(window, 'fetch');
this._diag.debug('removing previous patch for constructor');
Expand All @@ -458,7 +456,7 @@ export class FetchInstrumentation extends InstrumentationBase<
/**
* implements unpatch function
*/
override disable() {
override disable(): void {
this._unwrap(window, 'fetch');
this._usedResources = new WeakSet<PerformanceResourceTiming>();
}
Expand Down
12 changes: 6 additions & 6 deletions packages/opentelemetry-instrumentation-http/src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ export class HttpInstrumentation extends InstrumentationBase<Http> {
return this._config;
}

override setConfig(config: HttpInstrumentationConfig & InstrumentationConfig = {}) {
override setConfig(config: HttpInstrumentationConfig & InstrumentationConfig = {}): void {
this._config = Object.assign({}, config);
}

init() {
init(): [InstrumentationNodeModuleDefinition<Https>, InstrumentationNodeModuleDefinition<Http>] {
return [this._getHttpsInstrumentation(), this._getHttpInstrumentation()];
}

Expand Down Expand Up @@ -169,7 +169,7 @@ export class HttpInstrumentation extends InstrumentationBase<Http> {
* Creates spans for incoming requests, restoring spans' context if applied.
*/
protected _getPatchIncomingRequestFunction(component: 'http' | 'https') {
return (original: (event: string, ...args: unknown[]) => boolean) => {
return (original: (event: string, ...args: unknown[]) => boolean): (this: unknown, event: string, ...args: unknown[]) => boolean => {
return this._incomingRequestFunction(component, original);
};
}
Expand Down Expand Up @@ -305,7 +305,7 @@ export class HttpInstrumentation extends InstrumentationBase<Http> {
if (response.aborted && !response.complete) {
status = { code: SpanStatusCode.ERROR };
} else {
status = utils.parseResponseStatus(response.statusCode!);
status = utils.parseResponseStatus(response.statusCode);
}

span.setStatus(status);
Expand Down Expand Up @@ -351,7 +351,7 @@ export class HttpInstrumentation extends InstrumentationBase<Http> {
) {
const instrumentation = this;
return function incomingRequest(
this: {},
this: unknown,
event: string,
...args: unknown[]
): boolean {
Expand Down Expand Up @@ -488,7 +488,7 @@ export class HttpInstrumentation extends InstrumentationBase<Http> {
): Func<http.ClientRequest> {
const instrumentation = this;
return function outgoingRequest(
this: {},
this: unknown,
options: url.URL | http.RequestOptions | string,
...args: unknown[]
): http.ClientRequest {
Expand Down
10 changes: 5 additions & 5 deletions packages/opentelemetry-instrumentation-http/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export const setSpanWithError = (
span: Span,
error: Err,
obj?: IncomingMessage | ClientRequest
) => {
): void => {
const message = error.message;

span.setAttributes({
Expand All @@ -176,7 +176,7 @@ export const setSpanWithError = (

let status: SpanStatus;
if ((obj as IncomingMessage).statusCode) {
status = parseResponseStatus((obj as IncomingMessage).statusCode!);
status = parseResponseStatus((obj as IncomingMessage).statusCode);
} else if ((obj as ClientRequest).aborted) {
status = { code: SpanStatusCode.ERROR };
} else {
Expand All @@ -196,7 +196,7 @@ export const setSpanWithError = (
export const setRequestContentLengthAttribute = (
request: IncomingMessage,
attributes: SpanAttributes
) => {
): void => {
const length = getContentLength(request.headers);
if (length === null) return;

Expand All @@ -217,7 +217,7 @@ export const setRequestContentLengthAttribute = (
export const setResponseContentLengthAttribute = (
response: IncomingMessage,
attributes: SpanAttributes
) => {
): void => {
const length = getContentLength(response.headers);
if (length === null) return;

Expand Down Expand Up @@ -259,7 +259,7 @@ export const isCompressed = (
export const getRequestInfo = (
options: url.URL | RequestOptions | string,
extraOptions?: RequestOptions
) => {
): { origin: string; pathname: string; method: string; optionsParsed: RequestOptions; } => {
let pathname = '/';
let origin = '';
let optionsParsed: RequestOptions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ describe('Packages', () => {
);
const result = await httpPackage.get(urlparsed.href!);
if (!resHeaders) {
const res = result as AxiosResponse<{}>;
const res = result as AxiosResponse<unknown>;
resHeaders = res.headers;
}
const spans = memoryExporter.getFinishedSpans();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ describe('Packages', () => {
);
const result = await httpPackage.get(urlparsed.href!);
if (!resHeaders) {
const res = result as AxiosResponse<{}>;
const res = result as AxiosResponse<unknown>;
resHeaders = res.headers;
}
const spans = memoryExporter.getFinishedSpans();
Expand Down
10 changes: 5 additions & 5 deletions packages/opentelemetry-sdk-node/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export class NodeSDK {
spanProcessor: SpanProcessor,
contextManager?: ContextManager,
textMapPropagator?: TextMapPropagator
) {
): void {
this._tracerProviderConfig = {
tracerConfig,
spanProcessor,
Expand All @@ -121,12 +121,12 @@ export class NodeSDK {
}

/** Set configurations needed to register a MeterProvider */
public configureMeterProvider(config: MeterConfig) {
public configureMeterProvider(config: MeterConfig): void {
this._meterProviderConfig = config;
}

/** Detect resource attributes */
public async detectResources(config?: ResourceDetectionConfig) {
public async detectResources(config?: ResourceDetectionConfig): Promise<void> {
const internalConfig: ResourceDetectionConfig = {
detectors: [awsEc2Detector, gcpDetector, envDetector, processDetector],
...config,
Expand All @@ -136,14 +136,14 @@ export class NodeSDK {
}

/** Manually add a resource */
public addResource(resource: Resource) {
public addResource(resource: Resource): void {
this._resource = this._resource.merge(resource);
}

/**
* Once the SDK has been configured, call this method to construct SDK components and register them with the OpenTelemetry API.
*/
public async start() {
public async start(): Promise<void> {
if (this._autoDetectResources) {
await this.detectResources();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)!;
}

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -197,7 +198,7 @@ export class BasicTracerProvider implements TracerProvider {
});
}

shutdown() {
shutdown(): Promise<void> {
return this.activeSpanProcessor.shutdown();
}

Expand Down
2 changes: 1 addition & 1 deletion packages/opentelemetry-sdk-trace-base/src/Span.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion packages/opentelemetry-sdk-trace-base/src/Tracer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -216,7 +217,7 @@ export class Tracer implements api.Tracer {
return this._spanLimits;
}

getActiveSpanProcessor() {
getActiveSpanProcessor(): SpanProcessor {
return this._tracerProvider.getActiveSpanProcessor();
}
}
Expand Down
24 changes: 12 additions & 12 deletions packages/opentelemetry-sdk-trace-base/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ENVIRONMENT> = getEnv()
environment: Required<ENVIRONMENT> = getEnv()
): Sampler {
switch (env.OTEL_TRACES_SAMPLER) {
switch (environment.OTEL_TRACES_SAMPLER) {
case TracesSamplerValues.AlwaysOn:
return new AlwaysOnSampler();
case TracesSamplerValues.AlwaysOff:
Expand All @@ -67,44 +67,44 @@ 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>
environment: Required<ENVIRONMENT>
): 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}.`
);
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class InMemorySpanExporter implements SpanExporter {
return Promise.resolve();
}

reset() {
reset(): void {
this._finishedSpans = [];
}

Expand Down
5 changes: 3 additions & 2 deletions packages/opentelemetry-sdk-trace-base/src/utility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<TracerConfig> = {
sampler: buildSamplerFromEnv(),
};
Expand Down
Loading

0 comments on commit 5a892a3

Please sign in to comment.