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

Commit d4b3d80

Browse files
whsisaikevych
authored andcommitted
instrumentation-http: Parse URL instead of relying on pathname (#169)
* instrumentation-http: Parse URL instead of relying on pathname * Run gts * Only parse .path * http: Added more failsafe to pathname detection
1 parent 55e0dbe commit d4b3d80

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,11 @@ export class HttpPlugin extends BasePlugin {
198198
}
199199

200200
// Makes sure the url is an url object
201+
let pathname = '';
201202
if (typeof (options) === 'string') {
202203
options = url.parse(options);
203204
arguments[0] = options;
205+
pathname = options.pathname;
204206
} else {
205207
// Do not trace ourselves
206208
if (options.headers &&
@@ -209,6 +211,11 @@ export class HttpPlugin extends BasePlugin {
209211
'header with "x-opencensus-outgoing-request" - do not trace');
210212
return original.apply(this, arguments);
211213
}
214+
215+
try {
216+
pathname = options.pathname || url.parse(options.path).pathname;
217+
} catch (e) {
218+
}
212219
}
213220

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

218225
plugin.logger.debug('%s plugin outgoingRequest', plugin.moduleName);
219226
const traceOptions = {
220-
name:
221-
`${request.method ? request.method : 'GET'} ${options.pathname}`,
227+
name: `${request.method ? request.method : 'GET'} ${pathname}`,
222228
kind: 'CLIENT',
223229
};
224230

0 commit comments

Comments
 (0)