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

Commit

Permalink
Fix a TypeError of url.parse
Browse files Browse the repository at this point in the history
  • Loading branch information
StoneDot committed Aug 21, 2019
1 parent b272634 commit 41c043f
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions packages/opencensus-instrumentation-http2/src/http2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export class Http2Plugin extends HttpPlugin {
return (original: ConnectFunction): Func<http2.ClientHttp2Session> => {
return function patchedConnect(
this: Http2Plugin,
authority: string
authority: string | url.URL
): http2.ClientHttp2Session {
const client = original.apply(this, arguments);
shimmer.wrap(client, 'request', original =>
Expand All @@ -96,7 +96,7 @@ export class Http2Plugin extends HttpPlugin {
const plugin = this;
return (
original: RequestFunction,
authority: string
authority: string | url.URL
): Func<http2.ClientHttp2Stream> => {
return function patchedRequest(
this: http2.Http2Session,
Expand Down Expand Up @@ -148,7 +148,7 @@ export class Http2Plugin extends HttpPlugin {
private getMakeHttp2RequestTraceFunction(
request: http2.ClientHttp2Stream,
headers: http2.OutgoingHttpHeaders,
authority: string,
authority: string | url.URL,
plugin: Http2Plugin
): Func<http2.ClientHttp2Stream> {
return (span: Span): http2.ClientHttp2Stream => {
Expand Down Expand Up @@ -178,7 +178,10 @@ export class Http2Plugin extends HttpPlugin {
const userAgent =
headers['user-agent'] || headers['User-Agent'] || null;

const host = url.parse(authority).host;
const host = (authority instanceof url.URL
? authority
: url.parse(authority)
).host;
if (host) {
span.addAttribute(Http2Plugin.ATTRIBUTE_HTTP_HOST, host);
}
Expand Down

0 comments on commit 41c043f

Please sign in to comment.