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

instrumentation-http: Parse URL instead of relying on pathname #169

Merged
merged 5 commits into from
Nov 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions packages/opencensus-instrumentation-http/src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,11 @@ export class HttpPlugin extends BasePlugin {
}

// Makes sure the url is an url object
let pathname = '';
if (typeof (options) === 'string') {
options = url.parse(options);
arguments[0] = options;
pathname = options.pathname;
} else {
// Do not trace ourselves
if (options.headers &&
Expand All @@ -209,6 +211,11 @@ export class HttpPlugin extends BasePlugin {
'header with "x-opencensus-outgoing-request" - do not trace');
return original.apply(this, arguments);
}

try {
pathname = options.pathname || url.parse(options.path).pathname;
} catch (e) {
}
}

const request = original.apply(this, arguments);
Expand All @@ -217,8 +224,7 @@ export class HttpPlugin extends BasePlugin {

plugin.logger.debug('%s plugin outgoingRequest', plugin.moduleName);
const traceOptions = {
name:
`${request.method ? request.method : 'GET'} ${options.pathname}`,
name: `${request.method ? request.method : 'GET'} ${pathname}`,
kind: 'CLIENT',
};

Expand Down