Fix race condition on loading SDK (#142)

This commit is contained in:
Trask Stalnaker 2020-02-06 19:05:34 -08:00 committed by GitHub
parent 7599e2f0c9
commit a20b444d49
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 0 deletions

View File

@ -10,6 +10,7 @@ import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.none;
import static net.bytebuddy.matcher.ElementMatchers.not;
import io.opentelemetry.OpenTelemetry;
import io.opentelemetry.auto.config.Config;
import java.lang.instrument.Instrumentation;
import java.util.ArrayList;
@ -52,6 +53,13 @@ public class AgentInstaller {
*/
public static ResettableClassFileTransformer installBytebuddyAgent(
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;
AgentBuilder agentBuilder =