Skip to content

Commit fa172d4

Browse files
authored
add start.async property for startup tuning (#2454)
* add start.async property for startup tuning * add changelog, version introduced, and fix typo
1 parent b130627 commit fa172d4

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

CHANGELOG.asciidoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ endif::[]
5353
* Added support for Java/Jakarta WebSocket ServerEndpoint - {pull}2281[#2281]
5454
* Added support for setting the service name on Log4j2's EcsLayout - {pull}2296[#2296]
5555
* Print the used instrumentation groups when the application stops - {pull}2448[#2448]
56+
* Add `elastic.apm.start_async` property that makes the agent start on a non-premain/main thread - {pull}2454[#2454]
5657
5758
[float]
5859
===== Bug fixes

elastic-apm-agent/src/main/java/co/elastic/apm/agent/premain/AgentMain.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,12 @@ public synchronized static void init(String agentArguments, Instrumentation inst
9090
if (delayAgentInitMs > 0) {
9191
delayAndInitAgentAsync(agentArguments, instrumentation, premain, delayAgentInitMs);
9292
} else {
93-
loadAndInitializeAgent(agentArguments, instrumentation, premain);
93+
String startAgentAsyncProperty = System.getProperty("elastic.apm.start_async");
94+
if (startAgentAsyncProperty != null) {
95+
delayAndInitAgentAsync(agentArguments, instrumentation, premain, 0);
96+
} else {
97+
loadAndInitializeAgent(agentArguments, instrumentation, premain);
98+
}
9499
}
95100
}
96101

@@ -119,7 +124,9 @@ private static void delayAndInitAgentAsync(final String agentArguments, final In
119124
public void run() {
120125
try {
121126
synchronized (AgentMain.class) {
122-
Thread.sleep(delayAgentInitMs);
127+
if (delayAgentInitMs > 0) {
128+
Thread.sleep(delayAgentInitMs);
129+
}
123130
loadAndInitializeAgent(agentArguments, instrumentation, premain);
124131
}
125132
} catch (InterruptedException e) {

elastic-apm-agent/src/main/java/co/elastic/apm/agent/premain/package-info.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@
2929
* </li>
3030
* <li>
3131
* load the {@code co.elastic.apm.agent.bci.ElasticApmAgent} class and execute the agent initialization process
32-
* <b>through reflection</b>. This can be done synchronously, blocking the bootstrapping thread, or
33-
* asynchronously on a different thread after some delay, that may be configured through the
34-
* {@code elastic.apm.delay_agent_premain_ms} System property.
32+
* <b>through reflection</b>. This can be done synchronously, blocking the bootstrapping thread (default); or
33+
* asynchronously on a different thread with the {@code elastic.apm.start_async} System property (since 1.29.0);
34+
* or asynchronously on a different thread after some delay, by configuring the
35+
* {@code elastic.apm.delay_agent_premain_ms} System property with some positive value.
3536
* </li>
3637
* </ul>
3738
*/

0 commit comments

Comments
 (0)