|
1 | 1 | /* |
2 | | - * Copyright 2012-2019 the original author or authors. |
| 2 | + * Copyright 2012-2020 the original author or authors. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
|
22 | 22 | import java.util.List; |
23 | 23 | import java.util.Map; |
24 | 24 | import java.util.Set; |
| 25 | +import java.util.concurrent.TimeUnit; |
25 | 26 | import java.util.function.Consumer; |
26 | 27 | import java.util.function.Predicate; |
27 | 28 | import java.util.function.Supplier; |
@@ -68,8 +69,7 @@ public final HttpTrace receivedRequest(TraceableRequest request) { |
68 | 69 | */ |
69 | 70 | public final void sendingResponse(HttpTrace trace, TraceableResponse response, Supplier<Principal> principal, |
70 | 71 | Supplier<String> sessionId) { |
71 | | - setIfIncluded(Include.TIME_TAKEN, () -> System.currentTimeMillis() - trace.getTimestamp().toEpochMilli(), |
72 | | - trace::setTimeTaken); |
| 72 | + setIfIncluded(Include.TIME_TAKEN, () -> calculateTimeTaken(trace), trace::setTimeTaken); |
73 | 73 | setIfIncluded(Include.SESSION_ID, sessionId, trace::setSessionId); |
74 | 74 | setIfIncluded(Include.PRINCIPAL, principal, trace::setPrincipal); |
75 | 75 | trace.setResponse(new HttpTrace.Response(new FilteredTraceableResponse(response))); |
@@ -102,6 +102,10 @@ private Map<String, List<String>> getHeadersIfIncluded(Include include, |
102 | 102 | .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); |
103 | 103 | } |
104 | 104 |
|
| 105 | + private long calculateTimeTaken(HttpTrace trace) { |
| 106 | + return TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - trace.getStartNanoTime()); |
| 107 | + } |
| 108 | + |
105 | 109 | private final class FilteredTraceableRequest implements TraceableRequest { |
106 | 110 |
|
107 | 111 | private final TraceableRequest delegate; |
|
0 commit comments