Skip to content

Commit a8508fe

Browse files
committed
feat: improve ThreadGrouper grouping logic
See: [#14047](#14047)
1 parent 1106d44 commit a8508fe

File tree

1 file changed

+7
-2
lines changed
  • instrumentation/runtime-telemetry/runtime-telemetry-java17/library/src/main/java/io/opentelemetry/instrumentation/runtimemetrics/java17/internal

1 file changed

+7
-2
lines changed

instrumentation/runtime-telemetry/runtime-telemetry-java17/library/src/main/java/io/opentelemetry/instrumentation/runtimemetrics/java17/internal/ThreadGrouper.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
package io.opentelemetry.instrumentation.runtimemetrics.java17.internal;
77

8+
import java.util.regex.Pattern;
89
import javax.annotation.Nullable;
910
import jdk.jfr.consumer.RecordedEvent;
1011
import jdk.jfr.consumer.RecordedThread;
@@ -14,13 +15,17 @@
1415
* any time.
1516
*/
1617
public final class ThreadGrouper {
18+
private static final Pattern SIMILAR_THREAD_NAME_PATTERN = Pattern.compile("\\d+");
1719

18-
// FIXME doesn't actually do any grouping, but should be safe for now
20+
// FIXME only handles substrings of contiguous digits -> a single `x`, but should be good
21+
// enough for now
1922
@Nullable
2023
public String groupedName(RecordedEvent ev) {
2124
Object thisField = ev.getValue("eventThread");
2225
if (thisField instanceof RecordedThread) {
23-
return ((RecordedThread) thisField).getJavaName();
26+
return SIMILAR_THREAD_NAME_PATTERN
27+
.matcher(((RecordedThread) thisField).getJavaName())
28+
.replaceAll("x");
2429
}
2530
return null;
2631
}

0 commit comments

Comments
 (0)