elastic / elastic/apm-agent-java
trace_methods needs some definition at startup or redefining later fails
- Vorherrschende Sprache
- Java
- Sterne
- 594
- Forks
- 338
- Ø Merge
- 1 T. 13 Std.
- Gemergte PRs (30 T.)
- 25
Beschreibung
## Describe the bug
[trace_methods](https://www.elastic.co/guide/en/apm/agent/java/current/config-core.html#config-trace-methods) is dynamic, but it looks like it needs to be defined with SOMETHING at startup, then it can successfully be redefined. But if not defined at all at startup, the redefinition fails with mapping errors
```
java.lang.IllegalStateException: There's no mapping for key co.elastic.apm.agent.tracemethods.TraceMethodInstrumentation$TraceMethodAdvice
```
## Steps to reproduce
Do NOT define trace_methods at startup (ie it should be absent from properties and config files), then sometime after startup define it, eg
```
new Thread(() -> {
try {Thread.sleep(30_000L);} catch (InterruptedException e) {}
System.setProperty("elastic.apm.trace_methods", "somepackage.*");
}).start();
```
## Expected behavior
For that example, all methods in `somepackage` should produce no transactions until about 30 seconds after startup, when it should start producing transactions for any method executed in `somepackage`
## Debug logs
```
2023-08-21 14:48:06,614 [Thread-16] ERROR co.elastic.apm.agent.bci.IndyBootstrap - There's no mapping for key co.elastic.apm.agent.tracemethods.TraceMethodInstrumentation$TraceMethodAdvice
java.lang.IllegalStateException: There's no mapping for key co.elastic.apm.agent.tracemethods.TraceMethodInstrumentation$TraceMethodAdvice
at co.elastic.apm.agent.bci.ElasticApmAgent.getInstrumentationClassLoader(ElasticApmAgent.java:946) ~[elastic-apm-agent-1.38.1-SNAPSHOT.jar:1.38.1-SNAPSHOT]
at co.elastic.apm.agent.bci.IndyBootstrap.internalBootstrap(IndyBootstrap.java:416) ~[elastic-apm-agent-1.38.1-SNAPSHOT.jar:1.38.1-SNAPSHOT]
at co.elastic.apm.agent.bci.IndyBootstrap.bootstrap(IndyBootstrap.java:389) ~[elastic-apm-agent-1.38.1-SNAPSHOT.jar:1.38.1-SNAPSHOT]
at jdk.internal.reflect.GeneratedMethodAccessor16.invoke(Unknown Source) ~[?:?]
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
at java.lang.reflect.Method.invoke(Method.java:568) ~[?:?]
at java.lang.IndyBootstrapDispatcher.bootstrap(IndyBootstrapDispatcher.java:61) ~[?:?]
at java.lang.invoke.BootstrapMethodInvoker.invoke(BootstrapMethodInvoker.java:147) ~[?:?]
at java.lang.invoke.CallSite.makeSite(CallSite.java:315) ~[?:?]
at java.lang.invoke.MethodHandleNatives.linkCallSiteImpl(MethodHandleNatives.java:281) ~[?:?]
at java.lang.invoke.MethodHandleNatives.linkCallSite(MethodHandleNatives.java:271) ~[?:?]
at wimtjgf.ScoreUI.getGcTime(ScoreUI.java:215) ~[bin/:?]
at wimtjgf.ScoreUI.lambda$2(Unknown Source) ~[bin/:?]
at java.lang.Thread.run(Thread.java:833) [?:?]
```
## Workaround
Add a dummy trace_methods definition at startup, eg `-Delastic.apm.trace_methods=nothing.at.all` then redefine dynamically as desired
Beitragsleitfaden
Rechercherichtung
Beginne mit TraceMethodInstrumentation$TraceMethodAdvice und verfolge den Fehler durch IndyBootstrap.java und ElasticApmAgent.java, insbesondere die im Stacktrace gezeigte Zuordnungssuche. Reproduziere das Problem, wenn trace_methods beim Start fehlt, und setze anschließend nach 30 Sekunden elastic.apm.trace_methods. Als abgeschlossen gilt die Aufgabe, wenn die dynamische Konfiguration ohne einen Platzhalter beim Start funktioniert und Methoden im ausgewählten Paket nach der Neudefinition beginnen, Transaktionen zu erzeugen.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- java
- Bereich
- observability-sre
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100