Skip to content

Commit

Permalink
refactor(instrumentation-http): fix eslint warnings
Browse files Browse the repository at this point in the history
```
/home/runner/work/opentelemetry-js/opentelemetry-js/experimental/packages/opentelemetry-instrumentation-http/src/http.ts
  1051:15  warning  Don't use `Function` as a type            @typescript-eslint/ban-types
```

Be explict about what type of functions we are expecting here.

Ref open-telemetry#5365
  • Loading branch information
chancancode committed Jan 29, 2025
1 parent de724a6 commit 83ad899
Showing 1 changed file with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ import type * as http from 'http';
import type * as https from 'https';
import { Socket } from 'net';
import * as url from 'url';
import { HttpInstrumentationConfig } from './types';
import {
HttpInstrumentationConfig,
StartOutgoingSpanCustomAttributeFunction,
} from './types';
import { VERSION } from './version';
import {
InstrumentationBase,
Expand Down Expand Up @@ -89,6 +92,7 @@ import {
Https,
SemconvStability,
} from './internal-types';
import { StartIncomingSpanCustomAttributeFunction } from './types';

/**
* This is by no means general-purpose nor completely safe, but for the purpose
Expand Down Expand Up @@ -1064,13 +1068,24 @@ export class HttpInstrumentation extends InstrumentationBase<HttpInstrumentation
}
}

private _callStartSpanHook(
request: http.IncomingMessage,
hookFunc: StartIncomingSpanCustomAttributeFunction | undefined
): Attributes;
private _callStartSpanHook(
request: http.RequestOptions,
hookFunc: StartOutgoingSpanCustomAttributeFunction | undefined
): Attributes;
private _callStartSpanHook(
request: http.IncomingMessage | http.RequestOptions,
hookFunc: Function | undefined
) {
hookFunc:
| StartIncomingSpanCustomAttributeFunction
| StartOutgoingSpanCustomAttributeFunction
| undefined
): Attributes | void {
if (typeof hookFunc === 'function') {
return safeExecuteInTheMiddle(
() => hookFunc(request),
() => hookFunc(request as http.IncomingMessage & http.RequestOptions),
() => {},
true
);
Expand Down

0 comments on commit 83ad899

Please sign in to comment.