-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix(node): Ensure correct URL is passed to ignoreIncomingRequests
callback
#12929
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
Changes from 2 commits
63f1af9
7cbfd34
9348717
4b5d587
757120e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
const { loggingTransport } = require('@sentry-internal/node-integration-tests'); | ||
const Sentry = require('@sentry/node'); | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
release: '1.0', | ||
tracesSampleRate: 1.0, | ||
transport: loggingTransport, | ||
|
||
integrations: [ | ||
Sentry.httpIntegration({ | ||
ignoreIncomingRequests: url => { | ||
return url.includes('/liveness'); | ||
}, | ||
}), | ||
], | ||
}); | ||
|
||
// express must be required after Sentry is initialized | ||
const express = require('express'); | ||
const cors = require('cors'); | ||
const { startExpressServerAndSendPortToRunner } = require('@sentry-internal/node-integration-tests'); | ||
|
||
const app = express(); | ||
|
||
app.use(cors()); | ||
|
||
app.get('/test', (_req, res) => { | ||
res.send({ response: 'response 1' }); | ||
}); | ||
|
||
app.get('/liveness', (_req, res) => { | ||
res.send({ response: 'liveness' }); | ||
}); | ||
|
||
Sentry.setupExpressErrorHandler(app); | ||
|
||
startExpressServerAndSendPortToRunner(app); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
const { loggingTransport } = require('@sentry-internal/node-integration-tests'); | ||
const Sentry = require('@sentry/node'); | ||
const http = require('http'); | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
release: '1.0', | ||
tracesSampleRate: 1.0, | ||
transport: loggingTransport, | ||
|
||
integrations: [ | ||
Sentry.httpIntegration({ | ||
ignoreOutgoingRequests: url => { | ||
return url.includes('example.com'); | ||
|
||
}, | ||
}), | ||
], | ||
}); | ||
|
||
// express must be required after Sentry is initialized | ||
const express = require('express'); | ||
const cors = require('cors'); | ||
const { startExpressServerAndSendPortToRunner } = require('@sentry-internal/node-integration-tests'); | ||
|
||
const app = express(); | ||
|
||
app.use(cors()); | ||
|
||
app.get('/test', (_req, response) => { | ||
http | ||
.request('http://example.com/', res => { | ||
res.on('data', () => {}); | ||
res.on('end', () => { | ||
response.send({ response: 'done' }); | ||
}); | ||
}) | ||
.end(); | ||
}); | ||
|
||
Sentry.setupExpressErrorHandler(app); | ||
|
||
startExpressServerAndSendPortToRunner(app); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,7 +103,7 @@ export const instrumentHttp = Object.assign( | |
}, | ||
|
||
ignoreIncomingRequestHook: request => { | ||
const url = getRequestUrl(request); | ||
const url = request.url; | ||
Lms24 marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just checking to be sure, is the url here the full URL, including protocol? so e.g. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mydea the
So all that to say, sadly it's difficult to reconstruct the full url. Thoughts? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mydea sorry i saw you moved your comment, so I just moved mine before I saw you replied 😅 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Sounds reasonable to me but sadly this is a breaking change, no? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just changing the name of the variable is fine. Will make the change and update JSDoc and docs to reflect it. "Luckily" this never worked in v8 in the first place (afaict) so we're likely not behaviourally breaking folks. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Regarding docs update: I'll do this in combination with the changes from #12930 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sounds good to me 🚀 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done: 9348717 |
||
|
||
const method = request.method?.toUpperCase(); | ||
// We do not capture OPTIONS/HEAD requests as transactions | ||
|
@@ -112,7 +112,7 @@ export const instrumentHttp = Object.assign( | |
} | ||
|
||
const _ignoreIncomingRequests = _httpOptions.ignoreIncomingRequests; | ||
if (_ignoreIncomingRequests && _ignoreIncomingRequests(url)) { | ||
if (url && _ignoreIncomingRequests && _ignoreIncomingRequests(url)) { | ||
return true; | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
small adjustment to our node integration tests framework: In the express apps, we can not optionally pass a fixed port which makes running the app locally a lot less painful 😅