Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,14 @@ public static void start(
remoteConfigEnabled = false;
telemetryEnabled = false;
// apply trace instrumentation, but skip other products at native-image build time
startDatadogAgent(initTelemetry, inst);
final Thread t = startDatadogAgent(initTelemetry, inst);
if (t != null) {
try {
t.join();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
StaticEventLogger.end("Agent.start");
return;
}
Expand Down Expand Up @@ -301,7 +308,7 @@ public static void start(
startCrashTracking();
StaticEventLogger.end("crashtracking");
}
startDatadogAgent(initTelemetry, inst);
final Thread agentLoadThread = startDatadogAgent(initTelemetry, inst);

final EnumSet<Library> libraries = detectLibraries(log);

Expand Down Expand Up @@ -384,6 +391,14 @@ public static void start(
StaticEventLogger.end("Profiling");
}

if (agentLoadThread != null) {
try {
agentLoadThread.join();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}

StaticEventLogger.end("Agent.start");
}

Expand Down Expand Up @@ -722,7 +737,7 @@ private static void maybeStartRemoteConfig(Class<?> scoClass, Object sco) {
StaticEventLogger.end("Remote Config");
}

private static synchronized void startDatadogAgent(
private static synchronized Thread startDatadogAgent(
final InitializationTelemetry initTelemetry, final Instrumentation inst) {
if (null != inst) {
StaticEventLogger.begin("BytebuddyAgent");
Expand All @@ -731,15 +746,16 @@ private static synchronized void startDatadogAgent(
final Class<?> agentInstallerClass =
AGENT_CLASSLOADER.loadClass(AGENT_INSTALLER_CLASS_NAME);
final Method agentInstallerMethod =
agentInstallerClass.getMethod("installBytebuddyAgent", Instrumentation.class);
agentInstallerMethod.invoke(null, inst);
agentInstallerClass.getMethod(
"installBytebuddyAgent", Instrumentation.class, InitializationTelemetry.class);
return (Thread) agentInstallerMethod.invoke(null, inst, initTelemetry);
} catch (final Throwable ex) {
log.error("Throwable thrown while installing the Datadog Agent", ex);
initTelemetry.onFatalError(ex);
} finally {
StaticEventLogger.end("BytebuddyAgent");
}
}
return null;
}

private static synchronized void installDatadogTracer(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import static datadog.trace.agent.tooling.ExtensionFinder.findExtensions;
import static datadog.trace.agent.tooling.ExtensionLoader.loadExtensions;
import static datadog.trace.agent.tooling.bytebuddy.matcher.GlobalIgnoresMatcher.globalIgnoresMatcher;
import static datadog.trace.util.AgentThreadFactory.AgentThread.AGENT_INIT_INSTRUMENTATION;
import static datadog.trace.util.AgentThreadFactory.newAgentThread;
import static net.bytebuddy.matcher.ElementMatchers.isDefaultFinalizer;

import datadog.environment.SystemProperties;
Expand All @@ -18,6 +20,8 @@
import datadog.trace.api.ProductActivation;
import datadog.trace.api.telemetry.IntegrationsCollector;
import datadog.trace.bootstrap.FieldBackedContextAccessor;
import datadog.trace.bootstrap.InitializationTelemetry;
import datadog.trace.bootstrap.benchmark.StaticEventLogger;
import datadog.trace.bootstrap.instrumentation.java.concurrent.ExcludeFilter;
import datadog.trace.util.AgentTaskScheduler;
import de.thetaphi.forbiddenapis.SuppressForbidden;
Expand Down Expand Up @@ -71,29 +75,44 @@ private static void circularityErrorWorkaround() {
}
}

public static void installBytebuddyAgent(final Instrumentation inst) {
public static Thread installBytebuddyAgent(
final Instrumentation inst, InitializationTelemetry initTelemetry) {
/*
* ByteBuddy agent is used by several systems which can be enabled independently;
* we need to install the agent whenever any of them is active.
*/
Set<InstrumenterModule.TargetSystem> enabledSystems = getEnabledSystems();
if (!enabledSystems.isEmpty()) {
installBytebuddyAgent(inst, false, enabledSystems);
if (DEBUG) {
log.debug("Instrumentation installed for {}", enabledSystems);
}
int poolCleaningInterval = InstrumenterConfig.get().getResolverResetInterval();
if (poolCleaningInterval > 0) {
AgentTaskScheduler.get()
.scheduleAtFixedRate(
SharedTypePools::clear,
poolCleaningInterval,
Math.max(poolCleaningInterval, 10),
TimeUnit.SECONDS);
}
} else if (DEBUG) {
log.debug("No target systems enabled, skipping instrumentation.");
}
final Thread ret =
newAgentThread(
AGENT_INIT_INSTRUMENTATION,
() -> {
try {
Set<InstrumenterModule.TargetSystem> enabledSystems = getEnabledSystems();
if (!enabledSystems.isEmpty()) {
installBytebuddyAgent(inst, false, enabledSystems);
if (DEBUG) {
log.debug("Instrumentation installed for {}", enabledSystems);
}
int poolCleaningInterval = InstrumenterConfig.get().getResolverResetInterval();
if (poolCleaningInterval > 0) {
AgentTaskScheduler.get()
.scheduleAtFixedRate(
SharedTypePools::clear,
poolCleaningInterval,
Math.max(poolCleaningInterval, 10),
TimeUnit.SECONDS);
}
} else if (DEBUG) {
log.debug("No target systems enabled, skipping instrumentation.");
}
} catch (Throwable ex) {
log.error("Throwable thrown while installing the Datadog Agent", ex);
initTelemetry.onFatalError(ex);
} finally {
StaticEventLogger.end("BytebuddyAgent");
}
});
ret.start();
return ret;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ public static void onEnter(@Advice.Argument(value = 0, readOnly = false) String[
+ "datadog.trace.logging.PrintStreamWrapper:build_time,"
+ "datadog.trace.util.CollectionUtils:build_time,"
+ "datadog.trace.util.TempLocationManager$SingletonHolder:run_time,"
+ "datadog.trace.util.AgentThreadFactory:build_time,"
+ "datadog.slf4j.helpers.NOPLoggerFactory:build_time,"
+ "datadog.slf4j.helpers.SubstituteLoggerFactory:build_time,"
+ "datadog.slf4j.impl.StaticLoggerBinder:build_time,"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ public enum AgentThread {

RETRANSFORMER("dd-retransformer"),

AGENT_INIT_INSTRUMENTATION("dd-agent-init-instrumentation"),

LOGS_INTAKE("dd-logs-intake"),

LLMOBS_EVALS_PROCESSOR("dd-llmobs-evals-processor");
Expand Down
Loading