2121
2222package com .microsoft .applicationinsights .web .internal .correlation ;
2323
24+ import com .google .common .base .Charsets ;
2425import com .microsoft .applicationinsights .TelemetryConfiguration ;
2526import com .microsoft .applicationinsights .internal .util .PeriodicTaskPool ;
2627import com .microsoft .applicationinsights .internal .util .SSLOptionsUtil ;
3738import org .slf4j .Logger ;
3839import org .slf4j .LoggerFactory ;
3940
41+ import java .io .ByteArrayOutputStream ;
4042import java .io .Closeable ;
4143import java .io .IOException ;
42- import java .net .MalformedURLException ;
43- import java .net .URL ;
44+ import java .net .URI ;
4445import java .util .concurrent .ConcurrentHashMap ;
4546import java .util .concurrent .ConcurrentMap ;
4647import java .util .concurrent .ExecutionException ;
@@ -52,7 +53,6 @@ public class CdsProfileFetcher implements ApplicationIdResolver, Closeable {
5253 private static final Logger logger = LoggerFactory .getLogger (CdsProfileFetcher .class );
5354
5455 private CloseableHttpAsyncClient httpClient ;
55- private String endpointAddress = null ;
5656 private static final String PROFILE_QUERY_ENDPOINT_APP_ID_FORMAT = "%s/api/profiles/%s/appId" ;
5757
5858 // cache of tasks per ikey
@@ -143,7 +143,14 @@ private ProfileFetcherResult internalFetchAppProfile(String instrumentationKey,
143143 try {
144144 HttpResponse response = currentTask .get ();
145145
146- if (response .getStatusLine ().getStatusCode () != 200 ) {
146+ int statusCode = response .getStatusLine ().getStatusCode ();
147+ if (statusCode != 200 ) {
148+ URI uri = configuration .getEndpointProvider ().getAppIdEndpointURL (instrumentationKey );
149+ ByteArrayOutputStream baos = new ByteArrayOutputStream ();
150+ response .getEntity ().writeTo (baos );
151+ String responseBody = new String (baos .toByteArray (), Charsets .UTF_8 );
152+ // logging the URL to make it easy to diagnose the issue (e.g. in case of local firewall/routing issue)
153+ logger .warn ("{} returned {}: {}" , uri , statusCode , responseBody );
147154 incrementFailureCount (instrumentationKey );
148155 return new ProfileFetcherResult (null , ProfileFetcherResultTaskStatus .FAILED );
149156 }
@@ -171,29 +178,8 @@ void setHttpClient(CloseableHttpAsyncClient client) {
171178 this .httpClient = client ;
172179 }
173180
174- /**
175- * @deprecated Set endpoints using {@link TelemetryConfiguration#setConnectionString(String)}.
176- */
177- @ Deprecated
178- public void setEndpointAddress (String endpoint ) throws MalformedURLException {
179- // set endpoint address to the base address (e.g. https://dc.services.visualstudio.com)
180- // later we will append the profile/ikey segment
181- URL url = new URL (endpoint );
182- String urlStr = url .toString ();
183- this .endpointAddress = urlStr .substring (0 , urlStr .length () - url .getFile ().length ());
184- if (logger .isTraceEnabled ()) {
185- logger .trace ("{} endpoint override: {}" , CdsProfileFetcher .class .getSimpleName (), this .endpointAddress );
186- }
187- }
188-
189181 private Future <HttpResponse > createFetchTask (String instrumentationKey , TelemetryConfiguration configuration ) {
190- final HttpGet request ;
191- if (endpointAddress == null ) {
192- request = new HttpGet (configuration .getEndpointProvider ().getAppIdEndpointURL (instrumentationKey ));
193- } else {
194- request = new HttpGet (String .format (PROFILE_QUERY_ENDPOINT_APP_ID_FORMAT , this .endpointAddress , instrumentationKey ));
195- }
196-
182+ final HttpGet request = new HttpGet (configuration .getEndpointProvider ().getAppIdEndpointURL (instrumentationKey ));
197183 return this .httpClient .execute (request , null );
198184 }
199185
0 commit comments