From c0fbd9f5b5d26bd265807140eb7a9f62549b3432 Mon Sep 17 00:00:00 2001 From: Hugh Simpson Date: Fri, 1 Dec 2023 11:10:37 +0000 Subject: [PATCH] pekko-grpc tests passing --- build.sbt | 2 +- .../pekko/grpc/PekkoGrpcServerInstrumentation.scala | 9 ++++++--- .../pekko/grpc/PekkoGrpcTracingSpec.scala | 10 +++------- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/build.sbt b/build.sbt index 77a99a2e6..e6e0eafd2 100644 --- a/build.sbt +++ b/build.sbt @@ -550,7 +550,7 @@ lazy val `kamon-pekko-grpc` = (project in file("instrumentation/kamon-pekko-grpc .settings(instrumentationSettings) .settings(Seq( PB.additionalDependencies := Seq.empty, - crossScalaVersions := Seq(`scala_2.12_version`, `scala_2.13_version`), + crossScalaVersions := Seq(`scala_2.12_version`, `scala_2.13_version`, scala_3_version), libraryDependencies ++= Seq( kanelaAgent % "provided", diff --git a/instrumentation/kamon-pekko-grpc/src/main/scala/kamon/instrumentation/pekko/grpc/PekkoGrpcServerInstrumentation.scala b/instrumentation/kamon-pekko-grpc/src/main/scala/kamon/instrumentation/pekko/grpc/PekkoGrpcServerInstrumentation.scala index a7cbbc7c2..61ae73d9c 100644 --- a/instrumentation/kamon-pekko-grpc/src/main/scala/kamon/instrumentation/pekko/grpc/PekkoGrpcServerInstrumentation.scala +++ b/instrumentation/kamon-pekko-grpc/src/main/scala/kamon/instrumentation/pekko/grpc/PekkoGrpcServerInstrumentation.scala @@ -20,6 +20,8 @@ import kamon.Kamon import kanela.agent.api.instrumentation.InstrumentationBuilder import kanela.agent.libs.net.bytebuddy.asm.Advice +import scala.annotation.static + class PekkoGrpcServerInstrumentation extends InstrumentationBuilder { /** @@ -33,18 +35,19 @@ class PekkoGrpcServerInstrumentation extends InstrumentationBuilder { * otherwise the span remains unchanged. Assumes no actual implementation of `pekko.grpc.internal.TelemetrySpi` is * configured. */ - onType("org.apache.pekko.grpc.internal.NoOpTelemetry$") - .advise(method("onRequest"), PekkoGRPCServerRequestHandler) + onType("org.apache.pekko.grpc.internal.TelemetrySpi") + .advise(method("onRequest"), classOf[PekkoGRPCServerRequestHandler]) onType("org.apache.pekko.grpc.scaladsl.GrpcMarshalling") .advise(method("unmarshal"), classOf[PekkoGRPCUnmarshallingContextPropagation]) } +class PekkoGRPCServerRequestHandler object PekkoGRPCServerRequestHandler { @Advice.OnMethodEnter() - def enter(@Advice.Argument(0) serviceName: String, @Advice.Argument(1) method: String): Unit = { + @static def enter(@Advice.Argument(0) serviceName: String, @Advice.Argument(1) method: String): Unit = { val fullSpanName = serviceName + "/" + method Kamon.currentSpan() .name(fullSpanName) diff --git a/instrumentation/kamon-pekko-grpc/src/test/scala/kamon/instrumentation/pekko/grpc/PekkoGrpcTracingSpec.scala b/instrumentation/kamon-pekko-grpc/src/test/scala/kamon/instrumentation/pekko/grpc/PekkoGrpcTracingSpec.scala index bcdcee56b..b09c69f72 100644 --- a/instrumentation/kamon-pekko-grpc/src/test/scala/kamon/instrumentation/pekko/grpc/PekkoGrpcTracingSpec.scala +++ b/instrumentation/kamon-pekko-grpc/src/test/scala/kamon/instrumentation/pekko/grpc/PekkoGrpcTracingSpec.scala @@ -26,13 +26,14 @@ import org.scalatest.concurrent.Eventually import org.scalatest.matchers.should.Matchers import org.scalatest.wordspec.AnyWordSpec +import scala.concurrent.ExecutionContextExecutor import scala.concurrent.duration._ class PekkoGrpcTracingSpec extends AnyWordSpec with InitAndStopKamonAfterAll with Matchers with Eventually with TestSpanReporter with OptionValues { - implicit val system = ActorSystem("pekko-grpc-instrumentation") - implicit val ec = system.dispatcher + implicit val system: ActorSystem = ActorSystem("pekko-grpc-instrumentation") + implicit val ec: ExecutionContextExecutor = system.dispatcher val greeterService = GreeterServiceHandler(new GreeterServiceImpl()) val serverBinding = Http() @@ -56,9 +57,4 @@ class PekkoGrpcTracingSpec extends AnyWordSpec with InitAndStopKamonAfterAll wit } } } - - override protected def beforeAll(): Unit = { - super.beforeAll() - enableFastSpanFlushing() - } }