Fix race condition on loading SDK (#142)
This commit is contained in:
parent
7599e2f0c9
commit
a20b444d49
|
@ -10,6 +10,7 @@ import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||||
import static net.bytebuddy.matcher.ElementMatchers.none;
|
import static net.bytebuddy.matcher.ElementMatchers.none;
|
||||||
import static net.bytebuddy.matcher.ElementMatchers.not;
|
import static net.bytebuddy.matcher.ElementMatchers.not;
|
||||||
|
|
||||||
|
import io.opentelemetry.OpenTelemetry;
|
||||||
import io.opentelemetry.auto.config.Config;
|
import io.opentelemetry.auto.config.Config;
|
||||||
import java.lang.instrument.Instrumentation;
|
import java.lang.instrument.Instrumentation;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -52,6 +53,13 @@ public class AgentInstaller {
|
||||||
*/
|
*/
|
||||||
public static ResettableClassFileTransformer installBytebuddyAgent(
|
public static ResettableClassFileTransformer installBytebuddyAgent(
|
||||||
final Instrumentation inst, final AgentBuilder.Listener... listeners) {
|
final Instrumentation inst, final AgentBuilder.Listener... listeners) {
|
||||||
|
|
||||||
|
// need to trigger loading of OpenTelemetry SDK before instrumentation can possibly cause
|
||||||
|
// io.opentelemetry.OpenTelemetry to be loaded, since as soon as io.opentelemetry.OpenTelemetry,
|
||||||
|
// it looks up implementation via SPI, and if it doesn't find one, it loads the No-op
|
||||||
|
// implementation and it cannot be replaced later
|
||||||
|
OpenTelemetry.getTracerFactory();
|
||||||
|
|
||||||
INSTRUMENTATION = inst;
|
INSTRUMENTATION = inst;
|
||||||
|
|
||||||
AgentBuilder agentBuilder =
|
AgentBuilder agentBuilder =
|
||||||
|
|
Loading…
Reference in New Issue