Skip to content

Commit

Permalink
Fix race condition on loading SDK (#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
trask authored Feb 7, 2020
1 parent 7599e2f commit a20b444
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
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;
Expand Down Expand Up @@ -52,6 +53,13 @@ public static void installBytebuddyAgent(final Instrumentation inst) {
*/
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 =
Expand Down

0 comments on commit a20b444

Please sign in to comment.