Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: span url hostname not ip #2039

Merged
merged 16 commits into from
Apr 15, 2021

Conversation

astorm
Copy link
Contributor

@astorm astorm commented Apr 10, 2021

Fixes #2035

This PR add a getUrlFromRequestAndOptions function to the lib/instrumentation/http-shared.js module. The http-shared module also uses this new function in place of the old http-request-to-url module to set the url property on a span.

The getUrlFromRequestAndOptions function accepts a ClientRequest object and a generic options object and uses the information from those objects to return the same final URL that the ClientRequest will use. The options object is either

  1. The options object passed to the request method

     http.request(options)
    
  2. Or, in the case of http.request's second form

     http.request(url, options)
    

    the options object is merged with the URL information from url to create a new object.

In addition to the usual test suite, this was tested across all supported node versions with the following sludge-hammer of a bash script.

@astorm astorm marked this pull request as draft April 10, 2021 00:12
@github-actions github-actions bot added the agent-nodejs Make available for APM Agents project planning. label Apr 10, 2021
@apmmachine
Copy link
Contributor

apmmachine commented Apr 10, 2021

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview

Expand to view the summary

Build stats

  • Build Cause: Pull request #2039 updated

  • Start Time: 2021-04-15T23:14:08.067+0000

  • Duration: 17 min 17 sec

  • Commit: a2c4777

Test stats 🧪

Test Results
Failed 0
Passed 17136
Skipped 0
Total 17136

Trends 🧪

Image of Build Times

Image of Tests

@astorm
Copy link
Contributor Author

astorm commented Apr 10, 2021

Tests failing in test/instrumentation/modules/http/outgoing.js for nodes 12.0 and 14.0, but passing in v14.14 or v12.22.1. Likely due to some subtly of localhost vs. 127.0.0.1. Will investigate.

@astorm astorm closed this Apr 10, 2021
@astorm astorm reopened this Apr 12, 2021
@astorm astorm marked this pull request as ready for review April 13, 2021 00:37
lib/instrumentation/http-shared.js Outdated Show resolved Hide resolved
lib/instrumentation/http-shared.js Outdated Show resolved Hide resolved
lib/instrumentation/http-shared.js Outdated Show resolved Hide resolved
lib/instrumentation/http-shared.js Outdated Show resolved Hide resolved
@astorm
Copy link
Contributor Author

astorm commented Apr 14, 2021

Per discussions, we've removed the "pass everything through a URL object to sanitize" in order to simplify the function (and adjusted the final return value to use local variables instead of properties from that URL object). We've also added a parameter to the function that lets us pass in the moduleName to use as a fallback protocol. In tests we've moved the username:password to the auth section of the options and added some test assertions that check for the presence of either string in the final URL. We've also added a test to ensure that port 80, if supplied, is represented in the URL.

@astorm astorm requested a review from trentm April 15, 2021 19:19
Comment on lines 292 to 297
// let url
// try {
// url = new URL(`${protocol}//${host}${port}${req.path}`)
// } catch (e) {
// return undefined
// }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drop these.

lib/instrumentation/http-shared.js Outdated Show resolved Hide resolved
@astorm astorm merged commit 0be8103 into master Apr 15, 2021
@astorm astorm deleted the astorm-span-url-hostname-not-ip-issue-2035-x branch April 15, 2021 23:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
agent-nodejs Make available for APM Agents project planning.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Hostname to IP Address Resolution in http-request-to-url can Overwhelm Service Maps
3 participants