You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
node http integration: ignoreIncomingRequests() option does not work #12913
One option: can we return the full request object back to the user in the ignoreIncomingRequests() user supplied hook?
This lets the user decide what criteria they want to use for requests that isn't just URL (eg. they could check the headers or body for something and ignore a request that way).
Alternatively: is it acceptable to pass just request.url (it does not include protocol, hostname, etc. - just the path and maybe params) instead of trying to parse more info out?
Then you could do const url = request.url; instead of getRequestUrl(request).
I don't see anywhere to get the extra bits of protocol, hostname, etc. in the IncomingMessage type.
Hey @bruno-dasilva thanks for writing in and for the excellent detective work! I'll take a look at this today and respond to your suggestions a bit later.
I can confirm that currently, ignoreIncomingRequests only receives /// instead of usable URLs.
To fix this, I think the best option is to take request.url and pass it to the callback as you suggested. We cannot change the signature of ignoreIncomingRequests within the v8 major as it's a breaking change and to me this just looks like a bug/something we copied from ignoreOutgoingRequests where we do indeed get RequestOptions and the url works as expected. Though I really wonder why TypeScript doesn't flag the types mismatch 🤔
If this is enough, we're good. Otherwise, we can still let users overwrite the Otel's ignoreIncomingRequestHook just like we do with some other constructor options of Otel's HttpInstrumentation.
Hey @Lms24 thanks for jumping on this so quickly :)
To fix this, I think the best option is to take request.url and pass it to the callback as you suggested.
yup that sounds reasonable to me.
Though I really wonder why TypeScript doesn't flag the types mismatch 🤔
May be worth a deeper look. Seems it'd be prone to future mistakes in general if we're somehow disabling type checks inadvertently here. I don't have the sdk setup locally to run any typescript builds atm.
Otherwise, we can still let users overwrite the Otel's ignoreIncomingRequestHook just like we do with some other constructor options of Otel's HttpInstrumentation.
I was unsure if this is possible here. Are you referring to passing in the experimentalConfig?
The issue with that is the ..._experimentalConfig expansion happens before the sentry-default ones, so don't the sentry-default ones override any same-keys we specify in _experimentalConfig?
eg. if I set _experimentalConfig.ignoreIncomingRequestHook() to a custom hook, won't sentry's override mine?
I'll admit I haven't tried it so instead i'm relying on a patch-package config instead. If the above is true, do we want to move _experimentalConfig below the sentry-defined parameters so they can act as overrides? That could be a breaking change if people are adding some ineffective hooks lol (though I suppose the interface marks it as can-break-at-any-time)
you're totally right. I also noticed that _experimentalConfig is spread too early/not applicable like this for the two ignore.. hooks. Gonna tag @mydea who implemented _experimentalConfig: Did we do this on purpose? I see a lot of default logic is added to our implementation of these two hooks but maybe it's fine for users to entirely overwrite it?
Hey, yes it is on purpose that we override this, we do not allow to override this because we depend on our custom functionality. The idea was that it should be enough to look at the URL we pass into the proper options we have, if that is incorrect we def. should fix this! Also we could think about adding the request as a second argument to the callback, I guess, this should be non-breaking I believe? Would be an escape hatch at least!
Also we could think about adding the request as a second argument to the callback, I guess, this should be non-breaking I believe? Would be an escape hatch at least!
that's a good idea! I opened #12929 to fix the url param. Will look into adding the second param as a follow-up!
Also we could think about adding the request as a second argument to the callback, I guess, this should be non-breaking I believe? Would be an escape hatch at least!
I like this idea; you get the full benefit creating your own hook (access to the request arg and influence on the return) without totally overriding the sentry one.
Then the sentry built-in function becomes more of a wrapper/middleware around the user's custom function. I like that generally to allow power users as much extensibility as possible :)
Activity
bruno-dasilva commentedon Jul 15, 2024
After some digging I found that the issue was introduced in this PR: #10443
Basically, the code assumes that
ignoreOutgoingRequestHookandignoreIncomingRequestHookotel hooks supply the samerequestobject type:RequestOptions. However,ignoreIncomingRequestHookactually passes an IncomingMessage object which has a totally different signature:https://github.com/open-telemetry/opentelemetry-js/blob/54b14fbbe33e0cf38115ee8c5c934a4e27786186/experimental/packages/opentelemetry-instrumentation-http/src/types.ts#L59-L65
As a result, when we call getRequestUrl(request):
sentry-javascript/packages/node/src/integrations/http.ts
Line 106 in eaf6055
which expects a RequestOptions object:
sentry-javascript/packages/node/src/utils/getRequestUrl.ts
Line 4 in eaf6055
all of the params it tries to access are undefined:
sentry-javascript/packages/node/src/utils/getRequestUrl.ts
Lines 4 to 15 in eaf6055
leading to the method returning
"///".bruno-dasilva commentedon Jul 15, 2024
One option: can we return the full request object back to the user in the ignoreIncomingRequests() user supplied hook?
This lets the user decide what criteria they want to use for requests that isn't just URL (eg. they could check the headers or body for something and ignore a request that way).
bruno-dasilva commentedon Jul 15, 2024
Alternatively: is it acceptable to pass just
request.url(it does not include protocol, hostname, etc. - just the path and maybe params) instead of trying to parse more info out?Then you could do
const url = request.url;instead ofgetRequestUrl(request).I don't see anywhere to get the extra bits of protocol, hostname, etc. in the IncomingMessage type.
Lms24 commentedon Jul 15, 2024
Hey @bruno-dasilva thanks for writing in and for the excellent detective work! I'll take a look at this today and respond to your suggestions a bit later.
Lms24 commentedon Jul 15, 2024
I can confirm that currently,
ignoreIncomingRequestsonly receives///instead of usable URLs.To fix this, I think the best option is to take
request.urland pass it to the callback as you suggested. We cannot change the signature ofignoreIncomingRequestswithin the v8 major as it's a breaking change and to me this just looks like a bug/something we copied fromignoreOutgoingRequestswhere we do indeed getRequestOptionsand the url works as expected. Though I really wonder why TypeScript doesn't flag the types mismatch 🤔If this is enough, we're good. Otherwise, we can still let users overwrite the Otel's
ignoreIncomingRequestHookjust like we do with some other constructor options of Otel's HttpInstrumentation.bruno-dasilva commentedon Jul 16, 2024
Hey @Lms24 thanks for jumping on this so quickly :)
yup that sounds reasonable to me.
May be worth a deeper look. Seems it'd be prone to future mistakes in general if we're somehow disabling type checks inadvertently here. I don't have the sdk setup locally to run any typescript builds atm.
I was unsure if this is possible here. Are you referring to passing in the experimentalConfig?
sentry-javascript/packages/node/src/integrations/http.ts
Line 85 in eaf6055
The issue with that is the

..._experimentalConfigexpansion happens before the sentry-default ones, so don't the sentry-default ones override any same-keys we specify in _experimentalConfig?eg. if I set
_experimentalConfig.ignoreIncomingRequestHook()to a custom hook, won't sentry's override mine?I'll admit I haven't tried it so instead i'm relying on a patch-package config instead. If the above is true, do we want to move _experimentalConfig below the sentry-defined parameters so they can act as overrides? That could be a breaking change if people are adding some ineffective hooks lol (though I suppose the interface marks it as can-break-at-any-time)
Lms24 commentedon Jul 16, 2024
you're totally right. I also noticed that
_experimentalConfigis spread too early/not applicable like this for the twoignore..hooks. Gonna tag @mydea who implemented_experimentalConfig: Did we do this on purpose? I see a lot of default logic is added to our implementation of these two hooks but maybe it's fine for users to entirely overwrite it?mydea commentedon Jul 16, 2024
Hey, yes it is on purpose that we override this, we do not allow to override this because we depend on our custom functionality. The idea was that it should be enough to look at the URL we pass into the proper options we have, if that is incorrect we def. should fix this! Also we could think about adding the request as a second argument to the callback, I guess, this should be non-breaking I believe? Would be an escape hatch at least!
Lms24 commentedon Jul 16, 2024
that's a good idea! I opened #12929 to fix the
urlparam. Will look into adding the second param as a follow-up!bruno-dasilva commentedon Jul 16, 2024
I like this idea; you get the full benefit creating your own hook (access to the request arg and influence on the return) without totally overriding the sentry one.
Then the sentry built-in function becomes more of a wrapper/middleware around the user's custom function. I like that generally to allow power users as much extensibility as possible :)
Lms24 commentedon Jul 16, 2024
Hey, the initial fix for the
urlparam was released with v8.18.0Adding the second
requestparameter was just merged (#12930) but will only be released with the next version of the SDK.bruno-dasilva commentedon Jul 16, 2024
damn, y'all move fast! Thanks so much for jumping on this quickly and with care @Lms24 @mydea. 🙏
Lms24 commentedon Jul 22, 2024
The second
requestparameter was released with version 8.19.0 last friday. I also just merged the documentation. It should be available in the next hours at https://docs.sentry.io/platforms/javascript/guides/node/configuration/integrations/http/bruno-dasilva commentedon Jul 22, 2024
Wooo!!! thank you @Lms24 <3