-
what am i doingi am currently using OpenTelemetry record something metrics about akka. like mailbox size. but actor model will create thousands of objects. my extension(instrumentation) will record them all. what is the problemeverything is correcttly when running my dev laptop. but when i deploy to server and created more than 2000 actor, something happend. It seems to be related to this pr: #3831
how the code look likesMetrics public class MailboxMetrics {
private static Meter meter = GlobalOpenTelemetry.getMeter("some name");
private static Map<ActorPath, Long> mailboxSizeMap = new ConcurrentHashMap<>();
@SuppressWarnings("unused")
private static ObservableLongGauge mailboxSize =
meter.gaugeBuilder("mailbox_size")
.setDescription("Mailbox Size")
.ofLongs()
.buildWithCallback(
c -> {
Set<ActorPath> allKey = mailboxSizeMap.keySet();
for (ActorPath key : allKey) {
c.record(mailboxSizeMap.get(key), getAttributes(key));
}
});
public static void registerActor(ActorPath path) {
mailboxSizeMap.putIfAbsent(path, 0L);
}
public static void setActorMailboxSize(ActorPath path, int size) {
mailboxSizeMap.putIfAbsent(path, Long.valueOf(size));
}
private static Attributes getAttributes(ActorPath path) {
ArrayList<String> elements = new ArrayList<>();
path.getElements().forEach(elements::add);
String type =
elements.stream()
.findFirst()
.orElse("system");
String name = path.name();
String pathStr = path.toStringWithoutAddress();
return Attributes.builder()
.put("type", type)
.put("path", pathStr)
.put("name", name)
.build();
}
} Advice public static class DequeueAdvice {
@Advice.OnMethodEnter
public static void onMessage(@Advice.This Object object) {
if (!(object instanceof Mailbox)) {
return;
}
Mailbox obj = (Mailbox) object;
int size = obj.numberOfMessages();
ActorRef self = obj.actor().getSelf();
if (Objects.isNull(obj.actor()) || Objects.isNull(obj.actor().getSelf())) {
return;
}
ActorPath path = self.path();
MailboxMetrics.setActorMailboxSize(path, size);
}
} questionDid I using this wrong code? what is the best practice for mesuring application code ? why Metric cardinality limit is constant? Thank you for taking the time to answer. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
seem like i open this on the wrong repo. i found same issue on: open-telemetry/opentelemetry-java#4647 i got the answer, this discussions should be ignore. |
Beta Was this translation helpful? Give feedback.
seem like i open this on the wrong repo.
i found same issue on: open-telemetry/opentelemetry-java#4647
i got the answer, this discussions should be ignore.