Skip to content

Commit 060e520

Browse files
authored
Merge branch 'master' into jb/liveheap_subsample
2 parents 8867b96 + 60ddc9e commit 060e520

67 files changed

Lines changed: 1568 additions & 221 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

dd-java-agent/agent-bootstrap/src/main/java/datadog/trace/bootstrap/Agent.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import java.util.EnumSet;
5454
import java.util.concurrent.TimeUnit;
5555
import java.util.concurrent.atomic.AtomicBoolean;
56+
import java.util.regex.PatternSyntaxException;
5657
import org.slf4j.Logger;
5758
import org.slf4j.LoggerFactory;
5859

@@ -204,6 +205,16 @@ public static void start(final Instrumentation inst, final URL agentJarURL, Stri
204205

205206
boolean dataJobsEnabled = isFeatureEnabled(AgentFeature.DATA_JOBS);
206207
if (dataJobsEnabled) {
208+
String javaCommand = System.getProperty("sun.java.command");
209+
String dataJobsCommandPattern = Config.get().getDataJobsCommandPattern();
210+
if (!isDataJobsSupported(javaCommand, dataJobsCommandPattern)) {
211+
log.warn(
212+
"Data Jobs Monitoring is not compatible with non-spark command {} based on command pattern {}. dd-trace-java will not be installed",
213+
javaCommand,
214+
dataJobsCommandPattern);
215+
return;
216+
}
217+
207218
log.info("Data Jobs Monitoring enabled, enabling spark integrations");
208219

209220
setSystemPropertyDefault(
@@ -1307,4 +1318,22 @@ private static boolean isJFRSupported() {
13071318
// tracer install
13081319
return BootstrapProxy.INSTANCE.getResource("jdk/jfr/Recording.class") != null;
13091320
}
1321+
1322+
private static boolean isDataJobsSupported(String javaCommand, String dataJobsCommandPattern) {
1323+
if (null == javaCommand || null == dataJobsCommandPattern) {
1324+
// if sun.java.command somehow is not set or data jobs command pattern is not
1325+
// set, assume it's supported due to lack of info.
1326+
return true;
1327+
}
1328+
1329+
try {
1330+
return javaCommand.matches(dataJobsCommandPattern);
1331+
} catch (PatternSyntaxException e) {
1332+
log.warn(
1333+
"Invalid data jobs command pattern {}. The value must be a valid regex",
1334+
dataJobsCommandPattern);
1335+
}
1336+
1337+
return true;
1338+
}
13101339
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package datadog.trace.bootstrap.instrumentation.jmx;
2+
3+
import java.util.concurrent.ConcurrentHashMap;
4+
import java.util.concurrent.ConcurrentMap;
5+
import javax.management.MBeanServer;
6+
7+
public class MBeanServerRegistry {
8+
private static final ConcurrentMap<String, MBeanServer> serverMap = new ConcurrentHashMap<>();
9+
10+
public static MBeanServer getServer(final String serverClass) {
11+
return serverMap.get(serverClass);
12+
}
13+
14+
public static void putServer(final String serverClass, final MBeanServer server) {
15+
serverMap.putIfAbsent(serverClass, server);
16+
}
17+
}

dd-java-agent/agent-bootstrap/src/main/java/datadog/trace/bootstrap/instrumentation/span_origin/EntrySpanOriginInfo.java

Lines changed: 0 additions & 36 deletions
This file was deleted.

dd-java-agent/agent-bootstrap/src/main/java/datadog/trace/bootstrap/instrumentation/span_origin/ExitSpanOriginInfo.java

Lines changed: 0 additions & 54 deletions
This file was deleted.

dd-java-agent/agent-bootstrap/src/main/java/datadog/trace/bootstrap/instrumentation/span_origin/FindFirstStackTraceElement.java

Lines changed: 0 additions & 25 deletions
This file was deleted.

dd-java-agent/agent-bootstrap/src/main/java/datadog/trace/bootstrap/instrumentation/span_origin/LineInfo.java

Lines changed: 0 additions & 31 deletions
This file was deleted.

dd-java-agent/agent-debugger/debugger-bootstrap/src/main/java/datadog/trace/bootstrap/debugger/DebuggerContext.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,17 @@ public interface ExceptionDebugger {
6767
void handleException(Throwable t, AgentSpan span);
6868
}
6969

70+
public interface SpanDebugger {
71+
String captureSnapshot(String signature);
72+
}
73+
7074
private static volatile ProbeResolver probeResolver;
7175
private static volatile ClassFilter classFilter;
7276
private static volatile MetricForwarder metricForwarder;
7377
private static volatile Tracer tracer;
7478
private static volatile ValueSerializer valueSerializer;
7579
private static volatile ExceptionDebugger exceptionDebugger;
80+
private static volatile SpanDebugger spanDebugger;
7681

7782
public static void initProbeResolver(ProbeResolver probeResolver) {
7883
DebuggerContext.probeResolver = probeResolver;
@@ -98,6 +103,10 @@ public static void initExceptionDebugger(ExceptionDebugger exceptionDebugger) {
98103
DebuggerContext.exceptionDebugger = exceptionDebugger;
99104
}
100105

106+
public static void initSpanDebugger(SpanDebugger spanDebugger) {
107+
DebuggerContext.spanDebugger = spanDebugger;
108+
}
109+
101110
/**
102111
* Returns the probe details based on the probe id provided. If no probe is found, try to
103112
* re-transform the class using the callingClass parameter No-op if no implementation available
@@ -333,6 +342,18 @@ public static void commit(
333342
}
334343
}
335344

345+
public static String captureSnapshot(String signature) {
346+
try {
347+
SpanDebugger debugger = spanDebugger;
348+
if (debugger != null) {
349+
return debugger.captureSnapshot(signature);
350+
}
351+
} catch (Exception ex) {
352+
LOGGER.debug("Error in addSnapshot: ", ex);
353+
}
354+
return null;
355+
}
356+
336357
public static void handleException(Throwable t, AgentSpan span) {
337358
try {
338359
ExceptionDebugger exDebugger = exceptionDebugger;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package datadog.trace.bootstrap.debugger.spanorigin;
2+
3+
import static datadog.trace.bootstrap.debugger.DebuggerContext.captureSnapshot;
4+
import static java.util.Arrays.stream;
5+
6+
import datadog.trace.api.InstrumenterConfig;
7+
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
8+
import java.lang.reflect.Method;
9+
import java.util.stream.Collectors;
10+
11+
public class SpanOriginInfo {
12+
public static void entry(AgentSpan span, Method method) {
13+
if (InstrumenterConfig.get().isSpanOriginEnabled()) {
14+
String signature =
15+
stream(method.getParameterTypes())
16+
.map(Class::getName)
17+
.collect(Collectors.joining(",", "(", ")"));
18+
captureSnapshot(signature);
19+
}
20+
}
21+
22+
public static void exit(AgentSpan span) {
23+
if (InstrumenterConfig.get().isSpanOriginEnabled()) {
24+
span.getLocalRootSpan().setMetaStruct(captureSnapshot(null), span);
25+
}
26+
}
27+
}

dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/agent/ConfigurationAcceptor.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
public interface ConfigurationAcceptor {
77
enum Source {
88
REMOTE_CONFIG,
9+
SPAN_DEBUG,
910
EXCEPTION
1011
}
1112

dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/agent/DebuggerAgent.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.datadog.debugger.sink.ProbeStatusSink;
1010
import com.datadog.debugger.sink.SnapshotSink;
1111
import com.datadog.debugger.sink.SymbolSink;
12+
import com.datadog.debugger.snapshot.DefaultSpanDebugger;
1213
import com.datadog.debugger.symbol.SymDBEnablement;
1314
import com.datadog.debugger.symbol.SymbolAggregator;
1415
import com.datadog.debugger.uploader.BatchUploader;
@@ -98,6 +99,10 @@ public static synchronized void run(
9899
config.getDebuggerMaxExceptionPerSecond());
99100
DebuggerContext.initExceptionDebugger(defaultExceptionDebugger);
100101
}
102+
if (config.isDebuggerSpanDebugEnabled()) {
103+
DebuggerContext.initSpanDebugger(
104+
new DefaultSpanDebugger(configurationUpdater, classNameFiltering));
105+
}
101106
if (config.isDebuggerInstrumentTheWorld()) {
102107
setupInstrumentTheWorldTransformer(
103108
config, instrumentation, debuggerSink, statsdMetricForwarder);

0 commit comments

Comments
 (0)