Skip to content

Commit

Permalink
fix: don't throw on invalid URL (#1771)
Browse files Browse the repository at this point in the history
Fixes #1769

Co-authored-by: Vignesh Shanmugam <vignesh.shanmugam22@gmail.com>
  • Loading branch information
watson and vigneshshanmugam committed Jul 22, 2020
1 parent 94acd33 commit ec61513
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
11 changes: 10 additions & 1 deletion lib/instrumentation/http-shared.js
Expand Up @@ -209,7 +209,16 @@ exports.traceOutgoingRequest = function (agent, moduleName, method) {
url
})

span.setDestinationContext(getHTTPDestination(url, span.type))
// The `getHTTPDestination` function might throw in case an
// invalid URL is given to the `URL()` function. Until we can
// be 100% sure this doesn't happen, we better catch it here.
// For details, see:
// https://github.com/elastic/apm-agent-nodejs/issues/1769
try {
span.setDestinationContext(getHTTPDestination(url, span.type))
} catch (e) {
agent.logger.error('Could not set destination context:', e.message)
}

span.end()
}
Expand Down
11 changes: 10 additions & 1 deletion lib/instrumentation/modules/http2.js
Expand Up @@ -179,7 +179,16 @@ module.exports = function (http2, agent, { enabled }) {
url
})

span.setDestinationContext(getHTTPDestination(url, span.type))
// The `getHTTPDestination` function might throw in case an
// invalid URL is given to the `URL()` function. Until we can
// be 100% sure this doesn't happen, we better catch it here.
// For details, see:
// https://github.com/elastic/apm-agent-nodejs/issues/1769
try {
span.setDestinationContext(getHTTPDestination(url, span.type))
} catch (e) {
agent.logger.error('Could not set destination context:', e.message)
}

span.end()
})
Expand Down

0 comments on commit ec61513

Please sign in to comment.