Skip to content
This repository was archived by the owner on Oct 3, 2023. It is now read-only.

Commit 10401e3

Browse files
committed
Fix a TypeError of url.parse
1 parent b272634 commit 10401e3

File tree

1 file changed

+4
-4
lines changed
  • packages/opencensus-instrumentation-http2/src

1 file changed

+4
-4
lines changed

packages/opencensus-instrumentation-http2/src/http2.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export class Http2Plugin extends HttpPlugin {
7878
return (original: ConnectFunction): Func<http2.ClientHttp2Session> => {
7979
return function patchedConnect(
8080
this: Http2Plugin,
81-
authority: string
81+
authority: string | url.URL
8282
): http2.ClientHttp2Session {
8383
const client = original.apply(this, arguments);
8484
shimmer.wrap(client, 'request', original =>
@@ -96,7 +96,7 @@ export class Http2Plugin extends HttpPlugin {
9696
const plugin = this;
9797
return (
9898
original: RequestFunction,
99-
authority: string
99+
authority: string | url.URL
100100
): Func<http2.ClientHttp2Stream> => {
101101
return function patchedRequest(
102102
this: http2.Http2Session,
@@ -148,7 +148,7 @@ export class Http2Plugin extends HttpPlugin {
148148
private getMakeHttp2RequestTraceFunction(
149149
request: http2.ClientHttp2Stream,
150150
headers: http2.OutgoingHttpHeaders,
151-
authority: string,
151+
authority: string | url.URL,
152152
plugin: Http2Plugin
153153
): Func<http2.ClientHttp2Stream> {
154154
return (span: Span): http2.ClientHttp2Stream => {
@@ -178,7 +178,7 @@ export class Http2Plugin extends HttpPlugin {
178178
const userAgent =
179179
headers['user-agent'] || headers['User-Agent'] || null;
180180

181-
const host = url.parse(authority).host;
181+
const host = (authority instanceof url.URL ? authority : url.parse(authority)).host;
182182
if (host) {
183183
span.addAttribute(Http2Plugin.ATTRIBUTE_HTTP_HOST, host);
184184
}

0 commit comments

Comments
 (0)