Skip to content
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

fix RequestContextImpl.copy instrumentation issue with pekko-http 1.1.+ #1372

Merged
merged 1 commit into from
Oct 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ class PekkoHttpServerInstrumentation extends InstrumentationBuilder {
* The rest of these sections are just about making sure that we can generate an appropriate operation name (i.e. free
* of variables) and take a Sampling Decision in case none has been taken so far.
*/
onType("org.apache.pekko.http.scaladsl.server.RequestContextImpl")
.mixin(classOf[HasMatchingContext.Mixin])
.intercept(method("copy"), RequestContextCopyInterceptor)
Try(Class.forName("org.apache.pekko.http.scaladsl.server.RequestContext")).toOption
.foldLeft(
onType("org.apache.pekko.http.scaladsl.server.RequestContextImpl").mixin(classOf[HasMatchingContext.Mixin])
)((advice, klass) => advice.intercept(withReturnTypes(klass), RequestContextCopyInterceptor))

onType("org.apache.pekko.http.scaladsl.server.directives.PathDirectives")
.intercept(method("rawPathPrefix"), classOf[PathDirectivesRawPathPrefixInterceptor])
Expand Down Expand Up @@ -262,7 +263,7 @@ object RequestContextCopyInterceptor {
@RuntimeType
def copy(@This context: RequestContext, @SuperCall copyCall: Callable[RequestContext]): RequestContext = {
val copiedRequestContext = copyCall.call()
copiedRequestContext.asInstanceOf[HasMatchingContext].setMatchingContext(
if (copiedRequestContext ne context) copiedRequestContext.asInstanceOf[HasMatchingContext].setMatchingContext(
context.asInstanceOf[HasMatchingContext].matchingContext
)
copiedRequestContext
Expand Down