Skip to content

Commit 54e4787

Browse files
authored
fix: set async-profiler timeout for OTLP recordings (#353)
Signed-off-by: Arnab Nandy <arnab_nandy7@yahoo.com>
1 parent 07f81c0 commit 54e4787

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

agent/src/main/java/io/pyroscope/javaagent/AsyncProfilerDelegate.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public synchronized void stop() {
7474
try {
7575
instance.stop();
7676
} catch (IllegalStateException e) {
77-
// async-profiler throws when stop is called after the JFR timeout has already elapsed.
77+
// async-profiler throws when stop is called after the recording timeout has already elapsed.
7878
if (!PROFILER_NOT_ACTIVE.equals(e.getMessage())) {
7979
throw e;
8080
}
@@ -110,8 +110,10 @@ static String createStartCommand(Config config, Format format, File tempJFRFile)
110110
}
111111
sb.append(",interval=").append(config.profilingInterval.toNanos());
112112
if (format == Format.JFR) {
113-
sb.append(",file=").append(tempJFRFile.toString())
114-
.append(",timeout=").append(asyncProfilerTimeoutSeconds(config.uploadInterval));
113+
sb.append(",file=").append(tempJFRFile.toString());
114+
}
115+
if (format == Format.JFR || format == Format.OTLP) {
116+
sb.append(",timeout=").append(asyncProfilerTimeoutSeconds(config.uploadInterval));
115117
}
116118
if (config.APLogLevel != null) {
117119
sb.append(",loglevel=").append(config.APLogLevel);

agent/src/test/java/io/pyroscope/javaagent/AsyncProfilerDelegateCommandTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import io.pyroscope.javaagent.config.Config;
55
import org.junit.jupiter.api.Test;
66

7+
import java.time.Duration;
8+
79
import static org.junit.jupiter.api.Assertions.assertFalse;
810
import static org.junit.jupiter.api.Assertions.assertTrue;
911

@@ -15,13 +17,15 @@ void otlpStartCommandIncludesConfiguredOptionsWithoutJfrFile() {
1517
.setJavaStackDepthMax(1024)
1618
.setAPLogLevel("debug")
1719
.setAPExtraArguments("threads")
20+
.setUploadInterval(Duration.ofSeconds(10))
1821
.build();
1922

2023
String command = AsyncProfilerDelegate.createStartCommand(config, Format.OTLP, null);
2124

2225
assertTrue(command.contains("jstackdepth=1024"));
2326
assertTrue(command.contains("loglevel=debug"));
2427
assertTrue(command.contains(",threads"));
28+
assertTrue(command.contains("timeout=11"));
2529
assertFalse(command.contains("file="));
2630
}
2731
}

0 commit comments

Comments
 (0)