Skip to content

Commit

Permalink
refactor(api): fix eslint warnings
Browse files Browse the repository at this point in the history
    /home/runner/work/opentelemetry-js/opentelemetry-js/api/src/diag/ComponentLogger.ts
      36:25  warning  Unexpected any. Specify a different type  @typescript-eslint/no-explicit-any
      40:25  warning  Unexpected any. Specify a different type  @typescript-eslint/no-explicit-any
      44:24  warning  Unexpected any. Specify a different type  @typescript-eslint/no-explicit-any
      48:24  warning  Unexpected any. Specify a different type  @typescript-eslint/no-explicit-any
      52:27  warning  Unexpected any. Specify a different type  @typescript-eslint/no-explicit-any
      60:9   warning  Unexpected any. Specify a different type  @typescript-eslint/no-explicit-any

    /home/runner/work/opentelemetry-js/opentelemetry-js/api/src/experimental/trace/SugaredTracer.ts
      80:5  warning  'context' is already declared in the upper scope on line 17 column 10  @typescript-eslint/no-shadow
      129:5  warning  'context' is already declared in the upper scope on line 17 column 10  @typescript-eslint/no-shadow
      135:5  warning  'context' is already declared in the upper scope on line 17 column 10  @typescript-eslint/no-shadow

    /home/runner/work/opentelemetry-js/opentelemetry-js/api/src/trace/NoopTracer.ts
      102:37  warning  Unexpected any. Specify a different type  @typescript-eslint/no-explicit-any

Ref open-telemetry#5365
  • Loading branch information
chancancode committed Jan 24, 2025
1 parent 0ae25f1 commit 8e768ac
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
15 changes: 7 additions & 8 deletions api/src/diag/ComponentLogger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,38 +33,37 @@ export class DiagComponentLogger implements DiagLogger {
this._namespace = props.namespace || 'DiagComponentLogger';
}

public debug(...args: any[]): void {
public debug(...args: unknown[]): void {
return logProxy('debug', this._namespace, args);
}

public error(...args: any[]): void {
public error(...args: unknown[]): void {
return logProxy('error', this._namespace, args);
}

public info(...args: any[]): void {
public info(...args: unknown[]): void {
return logProxy('info', this._namespace, args);
}

public warn(...args: any[]): void {
public warn(...args: unknown[]): void {
return logProxy('warn', this._namespace, args);
}

public verbose(...args: any[]): void {
public verbose(...args: unknown[]): void {
return logProxy('verbose', this._namespace, args);
}
}

function logProxy(
funcName: keyof DiagLogger,
namespace: string,
args: any
args: unknown[]
): void {
const logger = getGlobal('diag');
// shortcut if logger not set
if (!logger) {
return;
}

args.unshift(namespace);
return logger[funcName](...(args as Parameters<DiagLogFunction>));
return logger[funcName](namespace, ...args);
}
10 changes: 8 additions & 2 deletions api/src/experimental/trace/SugaredTracer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@
* limitations under the License.
*/
import { SugaredSpanOptions } from './SugaredOptions';
import { context, Context, Span, SpanStatusCode, Tracer } from '../../';
import {
context as contextApi,
Context,
Span,
SpanStatusCode,
Tracer,
} from '../../';

const defaultOnException = (e: Error, span: Span) => {
span.recordException(e);
Expand Down Expand Up @@ -174,7 +180,7 @@ function massageParams<F extends (span: Span) => ReturnType<F>>(
fn = arg3 as F;
}
opts = opts ?? {};
ctx = ctx ?? context.active();
ctx = ctx ?? contextApi.active();

return { opts, ctx, fn };
}
Expand Down
6 changes: 5 additions & 1 deletion api/src/trace/NoopTracer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,15 @@ export class NoopTracer implements Tracer {
}
}

function isSpanContext(spanContext: any): spanContext is SpanContext {
function isSpanContext(spanContext: unknown): spanContext is SpanContext {
return (
spanContext !== null &&
typeof spanContext === 'object' &&
'spanId' in spanContext &&
typeof spanContext['spanId'] === 'string' &&
'traceId' in spanContext &&
typeof spanContext['traceId'] === 'string' &&
'traceFlags' in spanContext &&
typeof spanContext['traceFlags'] === 'number'
);
}

0 comments on commit 8e768ac

Please sign in to comment.