Skip to content

Commit 655fa6d

Browse files
authored
fix RequestContextImpl.copy instrumentation issue with pekko-http 1.1.+ (#1372)
1 parent a478d3b commit 655fa6d

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

instrumentation/kamon-pekko-http/src/main/scala/kamon/instrumentation/pekko/http/PekkoHttpServerInstrumentation.scala

+5-4
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,10 @@ class PekkoHttpServerInstrumentation extends InstrumentationBuilder {
5555
* The rest of these sections are just about making sure that we can generate an appropriate operation name (i.e. free
5656
* of variables) and take a Sampling Decision in case none has been taken so far.
5757
*/
58-
onType("org.apache.pekko.http.scaladsl.server.RequestContextImpl")
59-
.mixin(classOf[HasMatchingContext.Mixin])
60-
.intercept(method("copy"), RequestContextCopyInterceptor)
58+
Try(Class.forName("org.apache.pekko.http.scaladsl.server.RequestContext")).toOption
59+
.foldLeft(
60+
onType("org.apache.pekko.http.scaladsl.server.RequestContextImpl").mixin(classOf[HasMatchingContext.Mixin])
61+
)((advice, klass) => advice.intercept(withReturnTypes(klass), RequestContextCopyInterceptor))
6162

6263
onType("org.apache.pekko.http.scaladsl.server.directives.PathDirectives")
6364
.intercept(method("rawPathPrefix"), classOf[PathDirectivesRawPathPrefixInterceptor])
@@ -262,7 +263,7 @@ object RequestContextCopyInterceptor {
262263
@RuntimeType
263264
def copy(@This context: RequestContext, @SuperCall copyCall: Callable[RequestContext]): RequestContext = {
264265
val copiedRequestContext = copyCall.call()
265-
copiedRequestContext.asInstanceOf[HasMatchingContext].setMatchingContext(
266+
if (copiedRequestContext ne context) copiedRequestContext.asInstanceOf[HasMatchingContext].setMatchingContext(
266267
context.asInstanceOf[HasMatchingContext].matchingContext
267268
)
268269
copiedRequestContext

0 commit comments

Comments
 (0)