-
Notifications
You must be signed in to change notification settings - Fork 1k
Remove thread.name from metrics
#14061
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
1106d44
a8508fe
6f666c2
b762c33
f9b198d
960e102
28bd154
ce515b0
409a69e
adc293b
504ce8e
8835eb4
4d0e52a
29ee2b4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,34 +9,37 @@ | |
| import io.opentelemetry.api.metrics.DoubleHistogram; | ||
| import io.opentelemetry.api.metrics.Meter; | ||
| import io.opentelemetry.instrumentation.runtimemetrics.java17.JfrFeature; | ||
| import io.opentelemetry.instrumentation.runtimemetrics.java17.internal.AbstractThreadDispatchingHandler; | ||
| import io.opentelemetry.instrumentation.runtimemetrics.java17.internal.Constants; | ||
| import io.opentelemetry.instrumentation.runtimemetrics.java17.internal.DurationUtil; | ||
| import io.opentelemetry.instrumentation.runtimemetrics.java17.internal.ThreadGrouper; | ||
| import io.opentelemetry.instrumentation.runtimemetrics.java17.internal.RecordedEventHandler; | ||
| import java.time.Duration; | ||
| import java.util.Optional; | ||
| import java.util.function.Consumer; | ||
| import jdk.jfr.consumer.RecordedEvent; | ||
|
|
||
| /** | ||
| * This class is internal and is hence not for public use. Its APIs are unstable and can change at | ||
| * any time. | ||
| */ | ||
| public final class LongLockHandler extends AbstractThreadDispatchingHandler { | ||
| public final class LongLockHandler implements RecordedEventHandler { | ||
| private static final String METRIC_NAME = "jvm.cpu.longlock"; | ||
| private static final String METRIC_DESCRIPTION = "Long lock times"; | ||
| private static final String EVENT_NAME = "jdk.JavaMonitorWait"; | ||
|
|
||
| private static final String EVENT_THREAD = "eventThread"; | ||
|
|
||
| private final DoubleHistogram histogram; | ||
| private final Attributes attributes; | ||
|
|
||
| public LongLockHandler(Meter meter, ThreadGrouper grouper) { | ||
| super(grouper); | ||
| public LongLockHandler(Meter meter) { | ||
| super(); | ||
| histogram = | ||
| meter | ||
| .histogramBuilder(METRIC_NAME) | ||
| .setDescription(METRIC_DESCRIPTION) | ||
| .setUnit(Constants.SECONDS) | ||
| .build(); | ||
|
|
||
| attributes = Attributes.empty(); | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -50,34 +53,17 @@ public JfrFeature getFeature() { | |
| } | ||
|
|
||
| @Override | ||
| public Consumer<RecordedEvent> createPerThreadSummarizer(String threadName) { | ||
| return new PerThreadLongLockHandler(histogram, threadName); | ||
| public void accept(RecordedEvent recordedEvent) { | ||
| if (recordedEvent.hasField(EVENT_THREAD)) { | ||
|
||
| histogram.record(DurationUtil.toSeconds(recordedEvent.getDuration()), attributes); | ||
| } | ||
| // What about the class name in MONITOR_CLASS ? | ||
| // We can get a stack trace from the thread on the event | ||
| // var eventThread = recordedEvent.getThread(EVENT_THREAD); | ||
| } | ||
|
|
||
| @Override | ||
| public Optional<Duration> getThreshold() { | ||
| return Optional.empty(); | ||
| } | ||
|
|
||
| private static class PerThreadLongLockHandler implements Consumer<RecordedEvent> { | ||
| private static final String EVENT_THREAD = "eventThread"; | ||
|
|
||
| private final DoubleHistogram histogram; | ||
| private final Attributes attributes; | ||
|
|
||
| public PerThreadLongLockHandler(DoubleHistogram histogram, String threadName) { | ||
| this.histogram = histogram; | ||
| this.attributes = Attributes.of(Constants.ATTR_THREAD_NAME, threadName); | ||
| } | ||
|
|
||
| @Override | ||
| public void accept(RecordedEvent recordedEvent) { | ||
| if (recordedEvent.hasField(EVENT_THREAD)) { | ||
| histogram.record(DurationUtil.toSeconds(recordedEvent.getDuration()), attributes); | ||
| } | ||
| // What about the class name in MONITOR_CLASS ? | ||
| // We can get a stack trace from the thread on the event | ||
| // var eventThread = recordedEvent.getThread(EVENT_THREAD); | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.