Skip to content

Commit 6640554

Browse files
authored
Merge pull request #83 from ruhan1/master-logforrequest
Log upstream req/resp that we can calculate response time
2 parents 55e7928 + f36174e commit 6640554

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

src/main/java/org/commonjava/util/gateway/util/WebClientAdapter.java

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,7 @@
2222
import io.smallrye.mutiny.vertx.UniHelper;
2323
import io.vertx.core.Future;
2424
import io.vertx.core.http.HttpServerRequest;
25-
import okhttp3.Call;
26-
import okhttp3.Callback;
27-
import okhttp3.Interceptor;
28-
import okhttp3.MediaType;
29-
import okhttp3.OkHttpClient;
30-
import okhttp3.Request;
31-
import okhttp3.RequestBody;
32-
import okhttp3.Response;
25+
import okhttp3.*;
3326
import org.apache.commons.io.IOUtils;
3427
import org.commonjava.util.gateway.config.ProxyConfiguration;
3528
import org.commonjava.util.gateway.config.ServiceConfig;
@@ -310,8 +303,6 @@ public Uni<Response> enqueue()
310303
}
311304

312305
return UniHelper.toUni( Future.future( ( p ) -> {
313-
logger.debug( "Starting upstream request..." );
314-
315306
Span span = otel.newClientSpan( "okhttp",
316307
requestBuilder.build().method() + ":" + serviceConfig.host + ":"
317308
+ serviceConfig.port );
@@ -322,10 +313,14 @@ public Uni<Response> enqueue()
322313

323314
Call call = callClient.newCall( requestBuilder.build() );
324315

316+
final String timestamp = System.currentTimeMillis() + "." + System.nanoTime(); // to identify the beginning/ending log message
317+
final HttpUrl url = call.request().url();
318+
final String method = call.request().method();
319+
logger.info( "Starting upstream request: [{}] {} ({})", method, url, timestamp );
325320

326-
span.setAttribute( SemanticAttributes.HTTP_METHOD, call.request().method() );
327-
span.setAttribute( SemanticAttributes.HTTP_HOST, call.request().url().host() );
328-
span.setAttribute( SemanticAttributes.HTTP_URL, call.request().url().url().toExternalForm() );
321+
span.setAttribute( SemanticAttributes.HTTP_METHOD, method );
322+
span.setAttribute( SemanticAttributes.HTTP_HOST, url.host() );
323+
span.setAttribute( SemanticAttributes.HTTP_URL, url.url().toExternalForm() );
329324

330325
call.enqueue( new Callback()
331326
{
@@ -341,7 +336,7 @@ public void onFailure( @NotNull Call call, @NotNull IOException e )
341336
scope.close();
342337
span.end();
343338

344-
logger.trace( "Failed: " + call.request().url(), e );
339+
logger.warn( String.format("Failed: [%s] %s (%s)", method, url, timestamp), e );
345340
p.fail( e );
346341
}
347342

@@ -357,7 +352,7 @@ public void onResponse( @NotNull Call call, @NotNull Response response )
357352
scope.close();
358353
span.end();
359354

360-
logger.trace( "Success: " + call.request().url() + " -> " + response.code() );
355+
logger.info( "Success: [{}] {} -> {} ({})", method, url, response.code(), timestamp );
361356
p.complete( response );
362357
}
363358
} );

0 commit comments

Comments
 (0)