44import static datadog .communication .http .OkHttpUtils .msgpackRequestBodyOf ;
55import static datadog .communication .http .OkHttpUtils .prepareRequest ;
66import static datadog .communication .serialization .msgpack .MsgPackWriter .FIXARRAY ;
7+ import static datadog .trace .api .ProtocolVersion .V0_4 ;
78import static java .util .Collections .emptyMap ;
89import static java .util .Collections .emptySet ;
910import static java .util .Collections .singletonList ;
1718import datadog .metrics .api .Recording ;
1819import datadog .metrics .impl .statsd .DDAgentStatsDClientManager ;
1920import datadog .trace .api .BaseHash ;
21+ import datadog .trace .api .ProtocolVersion ;
2022import datadog .trace .api .telemetry .LogCollector ;
2123import datadog .trace .util .Strings ;
2224import java .nio .ByteBuffer ;
23- import java .security .NoSuchAlgorithmException ;
2425import java .util .HashSet ;
2526import java .util .List ;
2627import java .util .Map ;
@@ -50,6 +51,7 @@ public class DDAgentFeaturesDiscovery implements DroppingPolicy {
5051 public static final String V03_ENDPOINT = "v0.3/traces" ;
5152 public static final String V04_ENDPOINT = "v0.4/traces" ;
5253 public static final String V05_ENDPOINT = "v0.5/traces" ;
54+ public static final String V1_ENDPOINT = "v1.0/traces" ;
5355
5456 public static final String V06_METRICS_ENDPOINT = "v0.6/stats" ;
5557 public static final String V07_CONFIG_ENDPOINT = "v0.7/config" ;
@@ -72,7 +74,7 @@ public class DDAgentFeaturesDiscovery implements DroppingPolicy {
7274 private final OkHttpClient client ;
7375 private final HttpUrl agentBaseUrl ;
7476 private final Recording discoveryTimer ;
75- private final String [] traceEndpoints ;
77+ private final ProtocolVersion protocolVersion ;
7678 private final String [] metricsEndpoints = {V06_METRICS_ENDPOINT };
7779 private final String [] configEndpoints = {V07_CONFIG_ENDPOINT };
7880 private final boolean metricsEnabled ;
@@ -107,15 +109,12 @@ public DDAgentFeaturesDiscovery(
107109 OkHttpClient client ,
108110 Monitoring monitoring ,
109111 HttpUrl agentUrl ,
110- boolean enableV05Traces ,
112+ ProtocolVersion protocolVersion ,
111113 boolean metricsEnabled ) {
112114 this .client = client ;
113115 this .agentBaseUrl = agentUrl ;
114116 this .metricsEnabled = metricsEnabled ;
115- this .traceEndpoints =
116- enableV05Traces
117- ? new String [] {V05_ENDPOINT , V04_ENDPOINT , V03_ENDPOINT }
118- : new String [] {V04_ENDPOINT , V03_ENDPOINT };
117+ this .protocolVersion = protocolVersion != null ? protocolVersion : V0_4 ;
119118 this .discoveryTimer = monitoring .newTimer ("trace.agent.discovery.time" );
120119 this .discoveryState = new State ();
121120 }
@@ -173,10 +172,10 @@ private void doDiscovery(State newState) {
173172
174173 // don't want to rewire the traces pipeline
175174 if (null == newState .traceEndpoint ) {
176- newState .traceEndpoint = probeTracesEndpoint (newState , traceEndpoints );
175+ newState .traceEndpoint = probeTracesEndpoint (newState , protocolVersion . endpointsToProbe () );
177176 } else if (newState .state == null || newState .state .isEmpty ()) {
178177 // Still need to probe so that state is correctly assigned
179- probeTracesEndpoint (newState , new String [] { newState .traceEndpoint } );
178+ probeTracesEndpoint (newState , singletonList ( newState .traceEndpoint ) );
180179 }
181180 }
182181
@@ -194,7 +193,7 @@ private void doDiscovery(State newState) {
194193 }
195194 }
196195
197- private String probeTracesEndpoint (State newState , String [] endpoints ) {
196+ private String probeTracesEndpoint (State newState , List < String > endpoints ) {
198197 for (String candidate : endpoints ) {
199198 try (Response response =
200199 client
@@ -253,7 +252,7 @@ private boolean processInfoResponse(State newState, String response) {
253252 // This is done outside of the loop to set metricsEndpoint to null if not found
254253 newState .metricsEndpoint = foundMetricsEndpoint ;
255254
256- for (String endpoint : traceEndpoints ) {
255+ for (String endpoint : protocolVersion . endpointsToProbe () ) {
257256 if (containsEndpoint (endpoints , endpoint )) {
258257 newState .traceEndpoint = endpoint ;
259258 break ;
@@ -311,7 +310,7 @@ private boolean processInfoResponse(State newState, String response) {
311310 }
312311 try {
313312 newState .state = Strings .sha256 (response );
314- } catch (NoSuchAlgorithmException ex ) {
313+ } catch (Throwable ex ) {
315314 log .debug (
316315 "Failed to hash trace agent /info response. Will probe {}" , newState .traceEndpoint , ex );
317316 }
0 commit comments