-
Notifications
You must be signed in to change notification settings - Fork 518
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
feat(instrumentation-express): Support non-string routes #2008
feat(instrumentation-express): Support non-string routes #2008
Conversation
const port = server.address().port; | ||
|
||
await new Promise(resolve => { | ||
http.get(`http://localhost:${port}/test/arr/requiredPath/optionalPath/lastParam`, (res) => { |
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.
Can we table test more regex scenarios to see if it works? good to help against regression
next(); | ||
}); | ||
|
||
app.get(['/test/arr/:id', /\/test\/arr[0-9]*\/required(path)?(\/optionalPath)?\/(lastParam)?/], (_req, res) => { |
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.
can we have a test for some simpler regex like we do here? https://github.com/getsentry/sentry-javascript/blob/78797919819f6427d667e3955c439ff8e99eeab2/dev-packages/node-integration-tests/suites/express/tracing-experimental/server.js#L25-L31
3522c4a
to
c0b8441
Compare
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.
Thanks for this! Overall I think this looks good - I am trying to confirm if there is specific guidance on when to approve the workflows. In the meantime I think this will also require an npm run lint:fix
. Can you update that on your side and push, along with an explicit return type for the getLayerPath
function?
plugins/node/opentelemetry-instrumentation-express/src/utils.ts
Outdated
Show resolved
Hide resolved
FWIW, I've tended to "Approve and run" after a sanity check that the PR doesn't add a bitcoin miner, credentials exfil or somethign like that. :) |
@JamieDanielson, thanks for reviewing. I updated the PR. |
465180f
to
0c1f5a0
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2008 +/- ##
==========================================
- Coverage 90.97% 90.36% -0.62%
==========================================
Files 146 147 +1
Lines 7492 7687 +195
Branches 1502 1576 +74
==========================================
+ Hits 6816 6946 +130
- Misses 676 741 +65
|
8a92001
to
6f53b7f
Compare
That's also my strategy |
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.
Overall looks ok to me but I have a little bit of concern that getLayerPath is not resilient to strings and regexes that have the same stringified represenation.
plugins/node/opentelemetry-instrumentation-express/src/utils.ts
Outdated
Show resolved
Hide resolved
plugins/node/opentelemetry-instrumentation-express/src/utils.ts
Outdated
Show resolved
Hide resolved
* @param args - Arguments of the route | ||
* @returns The layer path | ||
*/ | ||
export const getLayerPath = (args: unknown[]): string | undefined => { |
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.
This seems a bit fragile to me in the sense that it would be pretty easy to get the same output from a regexp that it would be to get from a string path with a trailing slash. Is there any guardrail against this situation, is this an acceptable risk, or is this not actually an issue if it happens? I'm not an expert in this instrumentation and I'm not 100% sure what the layer path is used for.
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.
IMHO it would be an acceptable risk. I'm not sure how to work around this without breaking the path pattern.
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.
Is this still an open question? I'm not sure I'm following the specific concern here, can you provide an example of what we are considering guarding against?
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.
My understanding is, that as this PR converts regexp path definitions to a string representation, it may collide with an exact string path which can make both end up under the same transaction name.
Something like:
/\/test\/regex/
and/test/regex/
can end up as/test/regex/
This seems possible, but l don't think it is a common pattern when people define routes.
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.
Just a thought since I am also following this PR: There is always the possibility for collisions when coercing anything into a string. In my opinion this is worth it. If we want to reduce the likelihood of collisions, we could transform regular expressions like const re = /\/test\/regex\/
with const coerced = `RegEx(${re.toString()})`;
. 🤔
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.
Hmm... I think I'm in agreement here that this is an acceptable risk as-is, as we are otherwise guarding against edge cases that are unlikely to occur, and if it does occur it is a fairly minimal impact. Especially compared to the current state, this gets us to a much better place. If we find ourselves getting issues related to this we can reconsider, but it might even just end up being a documentation thing at that point.
Co-authored-by: Jamie Danielson <[email protected]>
fd16275
to
83558f0
Compare
@dyladan @JamieDanielson could you take another look at this when you get the time? Thanks! |
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.
Thank you for the details and adding all the tests. I'm curious if anyone has final objections we haven't addressed but this looks good to me.
Which problem is this PR solving?
This came up while migrating
@sentry/node
to OpenTelemetry. (Related issue: getsentry/sentry-javascript#10168).This PR adds support for:
The current behaviour falls back to
/
as thelayerPath
when the Express route argument is not a string, which does not cover all uses (Express docs).@sentry/node
already has a test suite to cover these uses, so this PR migrates them to OpenTelemetry for validation.Short description of the changes
getLayerPath
utility to extract multiple route arguments, including regular expressions.sentry-javascript
)