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 ;
@@ -50,6 +52,7 @@ public class DDAgentFeaturesDiscovery implements DroppingPolicy {
5052 public static final String V03_ENDPOINT = "v0.3/traces" ;
5153 public static final String V04_ENDPOINT = "v0.4/traces" ;
5254 public static final String V05_ENDPOINT = "v0.5/traces" ;
55+ public static final String V1_ENDPOINT = "v1.0/traces" ;
5356
5457 public static final String V06_METRICS_ENDPOINT = "v0.6/stats" ;
5558 public static final String V07_CONFIG_ENDPOINT = "v0.7/config" ;
@@ -72,7 +75,7 @@ public class DDAgentFeaturesDiscovery implements DroppingPolicy {
7275 private final OkHttpClient client ;
7376 private final HttpUrl agentBaseUrl ;
7477 private final Recording discoveryTimer ;
75- private final String [] traceEndpoints ;
78+ private final ProtocolVersion protocolVersion ;
7679 private final String [] metricsEndpoints = {V06_METRICS_ENDPOINT };
7780 private final String [] configEndpoints = {V07_CONFIG_ENDPOINT };
7881 private final boolean metricsEnabled ;
@@ -107,15 +110,12 @@ public DDAgentFeaturesDiscovery(
107110 OkHttpClient client ,
108111 Monitoring monitoring ,
109112 HttpUrl agentUrl ,
110- boolean enableV05Traces ,
113+ ProtocolVersion protocolVersion ,
111114 boolean metricsEnabled ) {
112115 this .client = client ;
113116 this .agentBaseUrl = agentUrl ;
114117 this .metricsEnabled = metricsEnabled ;
115- this .traceEndpoints =
116- enableV05Traces
117- ? new String [] {V05_ENDPOINT , V04_ENDPOINT , V03_ENDPOINT }
118- : new String [] {V04_ENDPOINT , V03_ENDPOINT };
118+ this .protocolVersion = protocolVersion != null ? protocolVersion : V0_4 ;
119119 this .discoveryTimer = monitoring .newTimer ("trace.agent.discovery.time" );
120120 this .discoveryState = new State ();
121121 }
@@ -173,10 +173,10 @@ private void doDiscovery(State newState) {
173173
174174 // don't want to rewire the traces pipeline
175175 if (null == newState .traceEndpoint ) {
176- newState .traceEndpoint = probeTracesEndpoint (newState , traceEndpoints );
176+ newState .traceEndpoint = probeTracesEndpoint (newState , protocolVersion . endpointsToProbe () );
177177 } else if (newState .state == null || newState .state .isEmpty ()) {
178178 // Still need to probe so that state is correctly assigned
179- probeTracesEndpoint (newState , new String [] { newState .traceEndpoint } );
179+ probeTracesEndpoint (newState , singletonList ( newState .traceEndpoint ) );
180180 }
181181 }
182182
@@ -194,7 +194,7 @@ private void doDiscovery(State newState) {
194194 }
195195 }
196196
197- private String probeTracesEndpoint (State newState , String [] endpoints ) {
197+ private String probeTracesEndpoint (State newState , List < String > endpoints ) {
198198 for (String candidate : endpoints ) {
199199 try (Response response =
200200 client
@@ -253,7 +253,7 @@ private boolean processInfoResponse(State newState, String response) {
253253 // This is done outside of the loop to set metricsEndpoint to null if not found
254254 newState .metricsEndpoint = foundMetricsEndpoint ;
255255
256- for (String endpoint : traceEndpoints ) {
256+ for (String endpoint : protocolVersion . endpointsToProbe () ) {
257257 if (containsEndpoint (endpoints , endpoint )) {
258258 newState .traceEndpoint = endpoint ;
259259 break ;
0 commit comments