Skip to content

Commit

Permalink
fix RequestContextImpl.copy instrumentation issue with pekko-http 1.1.+
Browse files Browse the repository at this point in the history
  • Loading branch information
hughsimpson committed Oct 10, 2024
1 parent a478d3b commit 0159cc5
Showing 1 changed file with 5 additions and 4 deletions.
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

0 comments on commit 0159cc5

Please sign in to comment.