Skip to content

Commit 9c74a41

Browse files
authored
Use Daemon Threads In Trace Snapshot Profiler (#2283)
* Use daemon thread ExecutorService in AsyncStackTraceExporter. * Use daemon thread ScheduledExecutorService in ScheduledExecutorStackTraceSampler.
1 parent 8746383 commit 9c74a41

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

profiler/src/main/java/com/splunk/opentelemetry/profiler/snapshot/AsyncStackTraceExporter.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,19 @@
1919
import com.splunk.opentelemetry.profiler.InstrumentationSource;
2020
import com.splunk.opentelemetry.profiler.exporter.CpuEventExporter;
2121
import com.splunk.opentelemetry.profiler.exporter.PprofCpuEventExporter;
22+
import com.splunk.opentelemetry.profiler.util.HelpfulExecutors;
2223
import io.opentelemetry.api.logs.Logger;
2324
import java.time.Duration;
2425
import java.util.List;
2526
import java.util.concurrent.ExecutorService;
26-
import java.util.concurrent.Executors;
2727
import java.util.logging.Level;
2828

2929
class AsyncStackTraceExporter implements StackTraceExporter {
3030
private static final java.util.logging.Logger logger =
3131
java.util.logging.Logger.getLogger(AsyncStackTraceExporter.class.getName());
3232

33-
private final ExecutorService executor = Executors.newSingleThreadExecutor();
33+
private final ExecutorService executor =
34+
HelpfulExecutors.newSingleThreadExecutor("async-stack-trace-exporter");
3435
private final Logger otelLogger;
3536
private final Duration samplingPeriod;
3637
private final int maxDepth;

profiler/src/main/java/com/splunk/opentelemetry/profiler/snapshot/ScheduledExecutorStackTraceSampler.java

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

1717
package com.splunk.opentelemetry.profiler.snapshot;
1818

19+
import com.splunk.opentelemetry.profiler.util.HelpfulExecutors;
1920
import io.opentelemetry.api.trace.SpanContext;
2021
import java.lang.management.ManagementFactory;
2122
import java.lang.management.ThreadInfo;
@@ -24,7 +25,6 @@
2425
import java.time.Instant;
2526
import java.util.concurrent.ConcurrentHashMap;
2627
import java.util.concurrent.ConcurrentMap;
27-
import java.util.concurrent.Executors;
2828
import java.util.concurrent.ScheduledExecutorService;
2929
import java.util.concurrent.TimeUnit;
3030
import java.util.function.Supplier;
@@ -70,11 +70,14 @@ public void stop(SpanContext spanContext) {
7070
}
7171

7272
private class ThreadSampler {
73-
private final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
73+
private final ScheduledExecutorService scheduler;
7474
private final SpanContext spanContext;
7575

7676
ThreadSampler(SpanContext spanContext, Duration samplingPeriod) {
7777
this.spanContext = spanContext;
78+
scheduler =
79+
HelpfulExecutors.newSingleThreadedScheduledExecutor(
80+
"stack-trace-sampler-" + spanContext.getTraceId());
7881
scheduler.scheduleAtFixedRate(
7982
new StackTraceGatherer(samplingPeriod, spanContext.getTraceId(), Thread.currentThread()),
8083
SCHEDULER_INITIAL_DELAY,

0 commit comments

Comments
 (0)