diff --git a/communication/src/main/java/datadog/communication/ddagent/DDAgentFeaturesDiscovery.java b/communication/src/main/java/datadog/communication/ddagent/DDAgentFeaturesDiscovery.java index 3956030d0f6..375b82ab0d5 100644 --- a/communication/src/main/java/datadog/communication/ddagent/DDAgentFeaturesDiscovery.java +++ b/communication/src/main/java/datadog/communication/ddagent/DDAgentFeaturesDiscovery.java @@ -59,7 +59,8 @@ public class DDAgentFeaturesDiscovery implements DroppingPolicy { public static final String DATADOG_AGENT_STATE = "Datadog-Agent-State"; - public static final String DEBUGGER_ENDPOINT = "debugger/v1/input"; + public static final String DEBUGGER_ENDPOINT_V1 = "debugger/v1/input"; + public static final String DEBUGGER_ENDPOINT_V2 = "debugger/v2/input"; public static final String DEBUGGER_DIAGNOSTICS_ENDPOINT = "debugger/v1/diagnostics"; public static final String TELEMETRY_PROXY_ENDPOINT = "telemetry/proxy/"; @@ -266,8 +267,15 @@ private boolean processInfoResponse(String response) { } } - if (containsEndpoint(endpoints, DEBUGGER_ENDPOINT)) { - debuggerEndpoint = DEBUGGER_ENDPOINT; + // both debugger endpoint v2 and diagnostics endpoint are forwarding events to the DEBUGGER + // intake + // because older agents support diagnostics, we fallback to it before falling back to v1 + if (containsEndpoint(endpoints, DEBUGGER_ENDPOINT_V2)) { + debuggerEndpoint = DEBUGGER_ENDPOINT_V2; + } else if (containsEndpoint(endpoints, DEBUGGER_DIAGNOSTICS_ENDPOINT)) { + debuggerEndpoint = DEBUGGER_DIAGNOSTICS_ENDPOINT; + } else if (containsEndpoint(endpoints, DEBUGGER_ENDPOINT_V1)) { + debuggerEndpoint = DEBUGGER_ENDPOINT_V1; } if (containsEndpoint(endpoints, DEBUGGER_DIAGNOSTICS_ENDPOINT)) { debuggerDiagnosticsEndpoint = DEBUGGER_DIAGNOSTICS_ENDPOINT; @@ -353,6 +361,10 @@ public boolean supportsDebugger() { return debuggerEndpoint != null; } + public String getDebuggerEndpoint() { + return debuggerEndpoint; + } + public boolean supportsDebuggerDiagnostics() { return debuggerDiagnosticsEndpoint != null; } diff --git a/communication/src/test/groovy/datadog/communication/ddagent/DDAgentFeaturesDiscoveryTest.groovy b/communication/src/test/groovy/datadog/communication/ddagent/DDAgentFeaturesDiscoveryTest.groovy index 5ac884e0814..a12a0ea79e3 100644 --- a/communication/src/test/groovy/datadog/communication/ddagent/DDAgentFeaturesDiscoveryTest.groovy +++ b/communication/src/test/groovy/datadog/communication/ddagent/DDAgentFeaturesDiscoveryTest.groovy @@ -66,6 +66,7 @@ class DDAgentFeaturesDiscoveryTest extends DDSpecification { features.state() == INFO_STATE features.getConfigEndpoint() == V7_CONFIG_ENDPOINT features.supportsDebugger() + features.getDebuggerEndpoint() == "debugger/v2/input" features.supportsDebuggerDiagnostics() features.supportsEvpProxy() features.supportsContentEncodingHeadersWithEvpProxy() @@ -412,6 +413,9 @@ class DDAgentFeaturesDiscoveryTest extends DDSpecification { then: 1 * client.newCall(_) >> { Request request -> infoResponse(request, INFO_WITH_TELEMETRY_PROXY_RESPONSE) } features.supportsTelemetryProxy() + features.supportsDebugger() + features.getDebuggerEndpoint() == "debugger/v1/input" + !features.supportsDebuggerDiagnostics() 0 * _ } @@ -428,6 +432,10 @@ class DDAgentFeaturesDiscoveryTest extends DDSpecification { features.supportsEvpProxy() features.getEvpProxyEndpoint() == "evp_proxy/v2/" // v3 is advertised, but the tracer should ignore it !features.supportsContentEncodingHeadersWithEvpProxy() + features.supportsDebugger() + features.getDebuggerEndpoint() == "debugger/v1/diagnostics" + features.supportsDebuggerDiagnostics() + 0 * _ } def "test parse /info response with peer tag back propagation"() { diff --git a/communication/src/test/resources/agent-features/agent-info.json b/communication/src/test/resources/agent-features/agent-info.json index a0483450c18..93b9f98f2d1 100644 --- a/communication/src/test/resources/agent-features/agent-info.json +++ b/communication/src/test/resources/agent-features/agent-info.json @@ -16,6 +16,7 @@ "/evp_proxy/v3/", "/evp_proxy/v4/", "/debugger/v1/input", + "/debugger/v2/input", "/debugger/v1/diagnostics", "/v0.7/config" ], diff --git a/dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/agent/DebuggerAgent.java b/dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/agent/DebuggerAgent.java index 4de8622576a..7b3cb57404d 100644 --- a/dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/agent/DebuggerAgent.java +++ b/dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/agent/DebuggerAgent.java @@ -117,7 +117,8 @@ private static void commonInit(Config config) { ProbeStatusSink probeStatusSink = new ProbeStatusSink( config, diagnosticEndpoint, ddAgentFeaturesDiscovery.supportsDebuggerDiagnostics()); - DebuggerSink debuggerSink = createDebuggerSink(config, probeStatusSink); + DebuggerSink debuggerSink = + createDebuggerSink(config, ddAgentFeaturesDiscovery, probeStatusSink); debuggerSink.start(); configurationUpdater = new ConfigurationUpdater( @@ -273,14 +274,19 @@ public static void stopDistributedDebugger() { LOGGER.info("Sopping Distributed Debugger"); } - private static DebuggerSink createDebuggerSink(Config config, ProbeStatusSink probeStatusSink) { + private static DebuggerSink createDebuggerSink( + Config config, + DDAgentFeaturesDiscovery ddAgentFeaturesDiscovery, + ProbeStatusSink probeStatusSink) { String tags = getDefaultTagsMergedWithGlobalTags(config); SnapshotSink snapshotSink = new SnapshotSink( config, tags, new BatchUploader( - config, config.getFinalDebuggerSnapshotUrl(), SnapshotSink.RETRY_POLICY)); + config, + getDebuggerEndpoint(config, ddAgentFeaturesDiscovery), + SnapshotSink.RETRY_POLICY)); SymbolSink symbolSink = new SymbolSink(config); return new DebuggerSink( config, @@ -314,6 +320,16 @@ public static String getDefaultTagsMergedWithGlobalTags(Config config) { return debuggerTags + "," + globalTags; } + private static String getDebuggerEndpoint( + Config config, DDAgentFeaturesDiscovery ddAgentFeaturesDiscovery) { + if (ddAgentFeaturesDiscovery.supportsDebugger()) { + return ddAgentFeaturesDiscovery + .buildUrl(ddAgentFeaturesDiscovery.getDebuggerEndpoint()) + .toString(); + } + return config.getFinalDebuggerSnapshotUrl(); + } + private static String getDiagnosticEndpoint( Config config, DDAgentFeaturesDiscovery ddAgentFeaturesDiscovery) { if (ddAgentFeaturesDiscovery.supportsDebuggerDiagnostics()) {