fix(contrib/net/http): cannot use http.Request.PathValue before http.ServeMux.ServeHTTP is called#3853
Conversation
…HTTP is called Signed-off-by: Eliott Bouhana <[email protected]>
BenchmarksBenchmark execution time: 2025-08-06 15:51:00 Comparing candidate commit 7c8b2d9 in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 24 metrics, 0 unstable metrics. |
Signed-off-by: Eliott Bouhana <[email protected]>
Signed-off-by: Eliott Bouhana <[email protected]>
Signed-off-by: Eliott Bouhana <[email protected]>
Signed-off-by: Eliott Bouhana <[email protected]>
Signed-off-by: Eliott Bouhana <[email protected]>
| // Ignore the error: Something as gone wrong, but we are not eager to find out why. | ||
| // We will just log it as a telemetry logs warning (and Debug to the user-facing log). | ||
| log.Warn("instrumentation/net/http/pattern: failed to parse mux path pattern %q: %s", pattern, err.Error()) | ||
| internal.Instrumentation.Logger().Warn("instrumentation/net/http/pattern: failed to parse mux path pattern %q: %s", pattern, err.Error()) |
There was a problem hiding this comment.
I'm curious about why this file was moved to the internal package for net/http. It doesn't seem to break anything, so I'm fine with it. Is it for the sake of reducing the scope of the instrumentation package?
There was a problem hiding this comment.
Scope-wise this does not make sense for the pattern package to be alone in instrumentation while all other code related to net/http is in the contrib. Considering the PR doing this is one of the last we did on v1 I would say this is an artifact of how v1 was done and how this package was migrated last minute.
The instrumentation/net/http/pattern package was moved by #3853. The contribu/net/http/v2 module depends on that package at version v2.2.3. As a result, that verison of contrib/net/http/v2 won't be able to use newer versions of the main module. This is a breaking change. This commit restores the deleted package. While the current contrib/net/http/v2 package doesn't use it any more, this maintains compatibility with previous versions.
The instrumentation/net/http/pattern package was moved by #3853. The contribu/net/http/v2 module depends on that package at version v2.2.3. As a result, that verison of contrib/net/http/v2 won't be able to use newer versions of the main module. This is a breaking change. This commit restores the deleted package. While the current contrib/net/http/v2 package doesn't use it any more, this maintains compatibility with previous versions.
The instrumentation/net/http/pattern package was moved by #3853. The contribu/net/http/v2 module depends on that package at version v2.2.3. As a result, that verison of contrib/net/http/v2 won't be able to use newer versions of the main module. This is a breaking change. This commit restores the deleted package. While the current contrib/net/http/v2 package doesn't use it any more, this maintains compatibility with previous versions.
The instrumentation/net/http/pattern package was moved by #3853. The contribu/net/http/v2 module depends on that package at version v2.2.3. As a result, that verison of contrib/net/http/v2 won't be able to use newer versions of the main module. This is a breaking change. This commit restores the deleted package. While the current contrib/net/http/v2 package doesn't use it any more, this maintains compatibility with previous versions.
The instrumentation/net/http/pattern package was moved by #3853. The contribu/net/http/v2 module depends on that package at version v2.2.3. As a result, that verison of contrib/net/http/v2 won't be able to use newer versions of the main module. This is a breaking change. This commit restores the deleted package. While the current contrib/net/http/v2 package doesn't use it any more, this maintains compatibility with previous versions.
The instrumentation/net/http/pattern package was moved by #3853. The contribu/net/http/v2 module depends on that package at version v2.2.3. As a result, that verison of contrib/net/http/v2 won't be able to use newer versions of the main module. This is a breaking change. This commit restores the deleted package. While the current contrib/net/http/v2 package doesn't use it any more, this maintains compatibility with previous versions.
The instrumentation/net/http/pattern package was moved by #3853. The contrib/net/http/v2 module depends on that package at version v2.2.3. As a result, that verison of contrib/net/http/v2 won't be able to use newer versions of the main module. This is a breaking change. This commit restores the deleted package. While the current contrib/net/http/v2 package doesn't use it any more, this maintains compatibility with previous versions.
…backport) The instrumentation/net/http/pattern package was moved by #3853. The contrib/net/http/v2 module depends on that package at version v2.2.3. As a result, that verison of contrib/net/http/v2 won't be able to use newer versions of the main module. This is a breaking change. This commit restores the deleted package. While the current contrib/net/http/v2 package doesn't use it any more, this maintains compatibility with previous versions. In this backport, we don't have the NewSafeError functionality for telemetry logging. Rather than bring it back to this branch, this commit just uses the `%T` formatter to get roughly the same functionality. Backports #4017
Motivation
A system-test using path params to check for security event has been failing for a longtime already and we recently discovered that is was linked to the way the
net-httpsystem-tests weblog is done: usingcontrib/net/http.NewServeMuxinstead ofcontrib/net/http.WrapHandler. Both instrumentation works except one is before the routing of the router and one is after. Being before was okay before Go 1.22 introduced the pattern system that get's filled in the request from inside the call tohttp.ServeMux.ServeHTTPof which we have one instrumentation mode being before and one after. This means that calls tor.PathValueand access tor.Patternalways return a blank string before this happen even if the request object already existThis means that we need to move part of appsec processing always after the routing process happened. This PR does exactly this by taking advantage of the fact that when there is no data sent, the empty values sent earlier would be ignored later in the pipeline anyway.
What does this PR do?
patternpackage out of instrumentation like it should begetPatternfunction that is an artifact of when there was two versions of it before Go 1.22httpsec.RouteMatchedfunction that does the job of filling the gap left by not having access to route and path paramsServeMux.HandleandServeMux.HandleFuncto callhttpsec.RouteMatchedwhen necessary.Reviewer's Checklist
./scripts/lint.shlocally.Unsure? Have a question? Request a review!