From a05c944787e0b1a972c17871ffc368742a90eb63 Mon Sep 17 00:00:00 2001 From: Ivan Topolnjak Date: Fri, 21 Jun 2019 13:35:46 +0200 Subject: [PATCH] automatically create a group for sharing actors --- .../akka/remote/ShardingInstrumentation.scala | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/kamon-akka-remote/src/main/scala/kamon/instrumentation/akka/remote/ShardingInstrumentation.scala b/kamon-akka-remote/src/main/scala/kamon/instrumentation/akka/remote/ShardingInstrumentation.scala index 77ba09e..0c0692c 100644 --- a/kamon-akka-remote/src/main/scala/kamon/instrumentation/akka/remote/ShardingInstrumentation.scala +++ b/kamon-akka-remote/src/main/scala/kamon/instrumentation/akka/remote/ShardingInstrumentation.scala @@ -4,7 +4,9 @@ import java.util.concurrent.atomic.AtomicLong import akka.actor.Actor import kamon.instrumentation.akka.AkkaClusterShardingMetrics.ShardingInstruments +import kamon.instrumentation.akka.AkkaInstrumentation import kamon.instrumentation.akka.instrumentations.VersionFiltering +import kamon.util.Filter import kanela.agent.api.instrumentation.InstrumentationBuilder import kanela.agent.libs.net.bytebuddy.asm.Advice @@ -77,8 +79,15 @@ object HasShardCounters { object InitializeShardRegionAdvice { @Advice.OnMethodExit - def exit(@Advice.This region: Actor with HasShardingInstruments, @Advice.Argument(0) typeName: String): Unit = + def exit(@Advice.This region: Actor with HasShardingInstruments, @Advice.Argument(0) typeName: String): Unit = { region.setShardingInstruments(new ShardingInstruments(region.context.system.name, typeName)) + + val system = region.context.system + val shardingGuardian = system.settings.config.getString("akka.cluster.sharding.guardian-name") + val entitiesPath = s"${system.name}/system/$shardingGuardian/$typeName/*/*" + + AkkaInstrumentation.defineActorGroup(s"shardRegion/$typeName", Filter.fromGlob(entitiesPath)) + } } object InitializeShardAdvice {