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

Commit

Permalink
instrumentation-http: Parse URL instead of relying on pathname (#169)
Browse files Browse the repository at this point in the history
* instrumentation-http: Parse URL instead of relying on pathname
* Run gts
* Only parse .path
* http: Added more failsafe to pathname detection
  • Loading branch information
whs authored and isaikevych committed Nov 16, 2018
1 parent 55e0dbe commit d4b3d80
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
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

0 comments on commit d4b3d80

Please sign in to comment.