Skip to content

Commit 3438726

Browse files
authored
Correctly support Pekko HTTP in PlayServerInstrumentation (#1402)
1 parent 4fb0167 commit 3438726

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

instrumentation/kamon-play/src/main/scala/kamon/instrumentation/play/PlayServerInstrumentation.scala

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ import io.netty.handler.codec.http.{HttpRequest, HttpResponse}
2525
import io.netty.util.concurrent.GenericFutureListener
2626
import kamon.{ClassLoading, Kamon}
2727
import kamon.context.Storage
28-
import kamon.instrumentation.akka.http.ServerFlowWrapper
28+
import kamon.instrumentation.akka.http.{ServerFlowWrapper => AkkaHttpServerFlowWrapper}
29+
import kamon.instrumentation.pekko.http.{ServerFlowWrapper => PekkoHttpServerFlowWrapper}
2930
import kamon.instrumentation.context.{CaptureCurrentTimestampOnExit, HasTimestamp}
3031
import kamon.instrumentation.http.HttpServerInstrumentation.RequestHandler
3132
import kamon.instrumentation.http.{HttpMessage, HttpServerInstrumentation}
@@ -52,7 +53,18 @@ class PlayServerInstrumentation extends InstrumentationBuilder {
5253
.when(classIsPresent("play.core.server.AkkaHttpServerProvider"))
5354
.advise(
5455
anyMethods("createServerBinding", "play$core$server$AkkaHttpServer$$createServerBinding"),
55-
CreateServerBindingAdvice
56+
CreateAkkaHttpServerBindingAdvice
57+
)
58+
59+
/**
60+
* When using the Pekko HTTP server, we will use the exact same instrumentation that comes from the Pekko HTTP module,
61+
* the only difference here is that we will change the component name.
62+
*/
63+
onType("play.core.server.PekkoHttpServer")
64+
.when(classIsPresent("play.core.server.PekkoHttpServerProvider"))
65+
.advise(
66+
anyMethods("createServerBinding", "play$core$server$PekkoHttpServer$$createServerBinding"),
67+
CreatePekkoHttpServerBindingAdvice
5668
)
5769

5870
/**
@@ -87,15 +99,27 @@ class PlayServerInstrumentation extends InstrumentationBuilder {
8799

88100
}
89101

90-
object CreateServerBindingAdvice {
102+
object CreateAkkaHttpServerBindingAdvice {
103+
104+
@Advice.OnMethodEnter
105+
def enter(): Unit =
106+
AkkaHttpServerFlowWrapper.changeSettings("play.server.akka-http", "kamon.instrumentation.play.http.server")
107+
108+
@Advice.OnMethodExit
109+
def exit(): Unit =
110+
AkkaHttpServerFlowWrapper.resetSettings()
111+
112+
}
113+
114+
object CreatePekkoHttpServerBindingAdvice {
91115

92116
@Advice.OnMethodEnter
93117
def enter(): Unit =
94-
ServerFlowWrapper.changeSettings("play.server.akka-http", "kamon.instrumentation.play.http.server")
118+
PekkoHttpServerFlowWrapper.changeSettings("play.server.pekko-http", "kamon.instrumentation.play.http.server")
95119

96120
@Advice.OnMethodExit
97121
def exit(): Unit =
98-
ServerFlowWrapper.resetSettings()
122+
PekkoHttpServerFlowWrapper.resetSettings()
99123

100124
}
101125

instrumentation/kamon-play/src/test-common/scala/kamon/instrumentation/play/RequestInstrumentationSpec.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class AkkaHTTPRequestHandlerInstrumentationSpec extends {
5353
} else {
5454
(
5555
"/instrumentation/kamon-play/src/test-common/resources/conf/application-pekko-http.conf",
56-
"pekko.http.server"
56+
"play.server.pekko-http"
5757
)
5858
}
5959
}

0 commit comments

Comments
 (0)