Skip to content

Commit 8bcdeff

Browse files
jhayes2-chwyotelbot[bot]laurit
authored
Remove thread.name from metrics (#14061)
Co-authored-by: otelbot <[email protected]> Co-authored-by: Lauri Tulmin <[email protected]>
1 parent 58afc90 commit 8bcdeff

File tree

8 files changed

+57
-230
lines changed

8 files changed

+57
-230
lines changed

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import io.opentelemetry.api.metrics.MeterBuilder;
1111
import io.opentelemetry.instrumentation.api.internal.EmbeddedInstrumentationProperties;
1212
import io.opentelemetry.instrumentation.runtimemetrics.java17.internal.RecordedEventHandler;
13-
import io.opentelemetry.instrumentation.runtimemetrics.java17.internal.ThreadGrouper;
1413
import io.opentelemetry.instrumentation.runtimemetrics.java17.internal.buffer.DirectBufferStatisticsHandler;
1514
import io.opentelemetry.instrumentation.runtimemetrics.java17.internal.classes.ClassesLoadedHandler;
1615
import io.opentelemetry.instrumentation.runtimemetrics.java17.internal.container.ContainerConfigurationHandler;
@@ -84,17 +83,16 @@ static List<RecordedEventHandler> getHandlers(
8483
}
8584
}
8685

87-
ThreadGrouper grouper = new ThreadGrouper();
8886
List<RecordedEventHandler> basicHandlers =
8987
List.of(
90-
new ObjectAllocationInNewTlabHandler(meter, grouper),
91-
new ObjectAllocationOutsideTlabHandler(meter, grouper),
92-
new NetworkReadHandler(meter, grouper),
93-
new NetworkWriteHandler(meter, grouper),
88+
new ObjectAllocationInNewTlabHandler(meter),
89+
new ObjectAllocationOutsideTlabHandler(meter),
90+
new NetworkReadHandler(meter),
91+
new NetworkWriteHandler(meter),
9492
new ContextSwitchRateHandler(meter),
9593
new OverallCpuLoadHandler(meter),
9694
new ContainerConfigurationHandler(meter),
97-
new LongLockHandler(meter, grouper),
95+
new LongLockHandler(meter),
9896
new ThreadCountHandler(meter),
9997
new ClassesLoadedHandler(meter),
10098
new MetaspaceSummaryHandler(meter),

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

Lines changed: 0 additions & 38 deletions
This file was deleted.

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

Lines changed: 0 additions & 27 deletions
This file was deleted.

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

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,34 @@
99
import io.opentelemetry.api.metrics.DoubleHistogram;
1010
import io.opentelemetry.api.metrics.Meter;
1111
import io.opentelemetry.instrumentation.runtimemetrics.java17.JfrFeature;
12-
import io.opentelemetry.instrumentation.runtimemetrics.java17.internal.AbstractThreadDispatchingHandler;
1312
import io.opentelemetry.instrumentation.runtimemetrics.java17.internal.Constants;
1413
import io.opentelemetry.instrumentation.runtimemetrics.java17.internal.DurationUtil;
15-
import io.opentelemetry.instrumentation.runtimemetrics.java17.internal.ThreadGrouper;
14+
import io.opentelemetry.instrumentation.runtimemetrics.java17.internal.RecordedEventHandler;
1615
import java.time.Duration;
1716
import java.util.Optional;
18-
import java.util.function.Consumer;
1917
import jdk.jfr.consumer.RecordedEvent;
2018

2119
/**
2220
* This class is internal and is hence not for public use. Its APIs are unstable and can change at
2321
* any time.
2422
*/
25-
public final class LongLockHandler extends AbstractThreadDispatchingHandler {
23+
public final class LongLockHandler implements RecordedEventHandler {
2624
private static final String METRIC_NAME = "jvm.cpu.longlock";
2725
private static final String METRIC_DESCRIPTION = "Long lock times";
2826
private static final String EVENT_NAME = "jdk.JavaMonitorWait";
2927

3028
private final DoubleHistogram histogram;
29+
private final Attributes attributes;
3130

32-
public LongLockHandler(Meter meter, ThreadGrouper grouper) {
33-
super(grouper);
31+
public LongLockHandler(Meter meter) {
3432
histogram =
3533
meter
3634
.histogramBuilder(METRIC_NAME)
3735
.setDescription(METRIC_DESCRIPTION)
3836
.setUnit(Constants.SECONDS)
3937
.build();
38+
39+
attributes = Attributes.empty();
4040
}
4141

4242
@Override
@@ -50,34 +50,17 @@ public JfrFeature getFeature() {
5050
}
5151

5252
@Override
53-
public Consumer<RecordedEvent> createPerThreadSummarizer(String threadName) {
54-
return new PerThreadLongLockHandler(histogram, threadName);
53+
public void accept(RecordedEvent recordedEvent) {
54+
histogram.record(DurationUtil.toSeconds(recordedEvent.getDuration()), attributes);
55+
// What about the class name in MONITOR_CLASS ?
56+
// We can get a stack trace from the thread on the event
57+
// if (recordedEvent.hasField("eventThread")) {
58+
// var eventThread = recordedEvent.getThread("eventThread");
59+
// }
5560
}
5661

5762
@Override
5863
public Optional<Duration> getThreshold() {
5964
return Optional.empty();
6065
}
61-
62-
private static class PerThreadLongLockHandler implements Consumer<RecordedEvent> {
63-
private static final String EVENT_THREAD = "eventThread";
64-
65-
private final DoubleHistogram histogram;
66-
private final Attributes attributes;
67-
68-
public PerThreadLongLockHandler(DoubleHistogram histogram, String threadName) {
69-
this.histogram = histogram;
70-
this.attributes = Attributes.of(Constants.ATTR_THREAD_NAME, threadName);
71-
}
72-
73-
@Override
74-
public void accept(RecordedEvent recordedEvent) {
75-
if (recordedEvent.hasField(EVENT_THREAD)) {
76-
histogram.record(DurationUtil.toSeconds(recordedEvent.getDuration()), attributes);
77-
}
78-
// What about the class name in MONITOR_CLASS ?
79-
// We can get a stack trace from the thread on the event
80-
// var eventThread = recordedEvent.getThread(EVENT_THREAD);
81-
}
82-
}
8366
}

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

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@
99
import io.opentelemetry.api.metrics.LongHistogram;
1010
import io.opentelemetry.api.metrics.Meter;
1111
import io.opentelemetry.instrumentation.runtimemetrics.java17.JfrFeature;
12-
import io.opentelemetry.instrumentation.runtimemetrics.java17.internal.AbstractThreadDispatchingHandler;
1312
import io.opentelemetry.instrumentation.runtimemetrics.java17.internal.Constants;
14-
import io.opentelemetry.instrumentation.runtimemetrics.java17.internal.ThreadGrouper;
15-
import java.util.function.Consumer;
13+
import io.opentelemetry.instrumentation.runtimemetrics.java17.internal.RecordedEventHandler;
1614
import jdk.jfr.consumer.RecordedEvent;
1715

1816
/**
@@ -22,20 +20,22 @@
2220
* <p>This class is internal and is hence not for public use. Its APIs are unstable and can change
2321
* at any time.
2422
*/
25-
public final class ObjectAllocationInNewTlabHandler extends AbstractThreadDispatchingHandler {
23+
public final class ObjectAllocationInNewTlabHandler implements RecordedEventHandler {
2624
private static final String EVENT_NAME = "jdk.ObjectAllocationInNewTLAB";
25+
private static final String TLAB_SIZE = "tlabSize";
2726

2827
private final LongHistogram histogram;
28+
private final Attributes attributes;
2929

30-
public ObjectAllocationInNewTlabHandler(Meter meter, ThreadGrouper grouper) {
31-
super(grouper);
30+
public ObjectAllocationInNewTlabHandler(Meter meter) {
3231
histogram =
3332
meter
3433
.histogramBuilder(Constants.METRIC_NAME_MEMORY_ALLOCATION)
3534
.setDescription(Constants.METRIC_DESCRIPTION_MEMORY_ALLOCATION)
3635
.setUnit(Constants.BYTES)
3736
.ofLongs()
3837
.build();
38+
attributes = Attributes.of(Constants.ATTR_ARENA_NAME, "TLAB");
3939
}
4040

4141
@Override
@@ -49,29 +49,9 @@ public JfrFeature getFeature() {
4949
}
5050

5151
@Override
52-
public Consumer<RecordedEvent> createPerThreadSummarizer(String threadName) {
53-
return new PerThreadObjectAllocationInNewTlabHandler(histogram, threadName);
54-
}
55-
56-
/** This class aggregates all TLAB allocation JFR events for a single thread */
57-
private static class PerThreadObjectAllocationInNewTlabHandler
58-
implements Consumer<RecordedEvent> {
59-
private static final String TLAB_SIZE = "tlabSize";
60-
61-
private final LongHistogram histogram;
62-
private final Attributes attributes;
63-
64-
public PerThreadObjectAllocationInNewTlabHandler(LongHistogram histogram, String threadName) {
65-
this.histogram = histogram;
66-
this.attributes =
67-
Attributes.of(Constants.ATTR_THREAD_NAME, threadName, Constants.ATTR_ARENA_NAME, "TLAB");
68-
}
69-
70-
@Override
71-
public void accept(RecordedEvent ev) {
72-
histogram.record(ev.getLong(TLAB_SIZE), attributes);
73-
// Probably too high a cardinality
74-
// ev.getClass("objectClass").getName();
75-
}
52+
public void accept(RecordedEvent ev) {
53+
histogram.record(ev.getLong(TLAB_SIZE), attributes);
54+
// Probably too high a cardinality
55+
// ev.getClass("objectClass").getName();
7656
}
7757
}

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

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@
99
import io.opentelemetry.api.metrics.LongHistogram;
1010
import io.opentelemetry.api.metrics.Meter;
1111
import io.opentelemetry.instrumentation.runtimemetrics.java17.JfrFeature;
12-
import io.opentelemetry.instrumentation.runtimemetrics.java17.internal.AbstractThreadDispatchingHandler;
1312
import io.opentelemetry.instrumentation.runtimemetrics.java17.internal.Constants;
14-
import io.opentelemetry.instrumentation.runtimemetrics.java17.internal.ThreadGrouper;
15-
import java.util.function.Consumer;
13+
import io.opentelemetry.instrumentation.runtimemetrics.java17.internal.RecordedEventHandler;
1614
import jdk.jfr.consumer.RecordedEvent;
1715

1816
/**
@@ -22,20 +20,23 @@
2220
* <p>This class is internal and is hence not for public use. Its APIs are unstable and can change
2321
* at any time.
2422
*/
25-
public final class ObjectAllocationOutsideTlabHandler extends AbstractThreadDispatchingHandler {
23+
public final class ObjectAllocationOutsideTlabHandler implements RecordedEventHandler {
2624
private static final String EVENT_NAME = "jdk.ObjectAllocationOutsideTLAB";
25+
private static final String ALLOCATION_SIZE = "allocationSize";
2726

2827
private final LongHistogram histogram;
28+
private final Attributes attributes;
2929

30-
public ObjectAllocationOutsideTlabHandler(Meter meter, ThreadGrouper grouper) {
31-
super(grouper);
30+
public ObjectAllocationOutsideTlabHandler(Meter meter) {
3231
histogram =
3332
meter
3433
.histogramBuilder(Constants.METRIC_NAME_MEMORY_ALLOCATION)
3534
.setDescription(Constants.METRIC_DESCRIPTION_MEMORY_ALLOCATION)
3635
.setUnit(Constants.BYTES)
3736
.ofLongs()
3837
.build();
38+
39+
attributes = Attributes.of(Constants.ATTR_ARENA_NAME, "Main");
3940
}
4041

4142
@Override
@@ -49,29 +50,9 @@ public JfrFeature getFeature() {
4950
}
5051

5152
@Override
52-
public Consumer<RecordedEvent> createPerThreadSummarizer(String threadName) {
53-
return new PerThreadObjectAllocationOutsideTlabHandler(histogram, threadName);
54-
}
55-
56-
/** This class aggregates all non-TLAB allocation JFR events for a single thread */
57-
private static class PerThreadObjectAllocationOutsideTlabHandler
58-
implements Consumer<RecordedEvent> {
59-
private static final String ALLOCATION_SIZE = "allocationSize";
60-
61-
private final LongHistogram histogram;
62-
private final Attributes attributes;
63-
64-
public PerThreadObjectAllocationOutsideTlabHandler(LongHistogram histogram, String threadName) {
65-
this.histogram = histogram;
66-
this.attributes =
67-
Attributes.of(Constants.ATTR_THREAD_NAME, threadName, Constants.ATTR_ARENA_NAME, "Main");
68-
}
69-
70-
@Override
71-
public void accept(RecordedEvent ev) {
72-
histogram.record(ev.getLong(ALLOCATION_SIZE), attributes);
73-
// Probably too high a cardinality
74-
// ev.getClass("objectClass").getName();
75-
}
53+
public void accept(RecordedEvent ev) {
54+
histogram.record(ev.getLong(ALLOCATION_SIZE), attributes);
55+
// Probably too high a cardinality
56+
// ev.getClass("objectClass").getName();
7657
}
7758
}

0 commit comments

Comments
 (0)