Skip to content

Commit

Permalink
fix(opentelemetry-instrumentation-http): handle null port in options
Browse files Browse the repository at this point in the history
See the issue for details

Closes issue #2947
  • Loading branch information
danielgblanco committed May 3, 2022
1 parent ddb0775 commit 4b21ec3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions experimental/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ All notable changes to experimental packages in this project will be documented
### :rocket: (Enhancement)

### :bug: (Bug Fix)
* fix(opentelemetry-instrumentation-http): handle null ports in options #2948 @danielgblanco

### :books: (Refine Doc)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,8 @@ export const getRequestInfo = (
pathname = url.parse(optionsParsed.path).pathname || '/';
}
origin = `${optionsParsed.protocol || 'http:'}//${
optionsParsed.host || `${optionsParsed.hostname}:${optionsParsed.port}`
optionsParsed.host ||
`${optionsParsed.hostname}${optionsParsed.port ? `:${optionsParsed.port}` : ''}`
}`;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,23 @@ describe('Utility', () => {
...urlParsed,
pathname: undefined,
};
const urlParsedWithUndefinedHostAndPort = {
...urlParsed,
host: undefined,
port: undefined,
};
const urlParsedWithUndefinedHostAndNullPort = {
...urlParsed,
host: undefined,
port: null,
};
const whatWgUrl = new url.URL(webUrl);
for (const param of [
webUrl,
urlParsed,
urlParsedWithoutPathname,
urlParsedWithUndefinedHostAndPort,
urlParsedWithUndefinedHostAndNullPort,
whatWgUrl,
]) {
const result = utils.getRequestInfo(param);
Expand Down

0 comments on commit 4b21ec3

Please sign in to comment.