/** * Ends the tracing of the exchange that is being concluded by sending the given * {@code response}. * @param trace the trace for the exchange * @param response the response that concludes the exchange * @param principal a supplier for the exchange's principal * @param sessionId a supplier for the id of the exchange's session */ public final void sendingResponse(HttpTrace trace, TraceableResponse response, Supplier<Principal> principal, Supplier<String> sessionId) { setIfIncluded(Include.TIME_TAKEN, () -> System.currentTimeMillis() - trace.getTimestamp().toEpochMilli(), trace::setTimeTaken); setIfIncluded(Include.SESSION_ID, sessionId, trace::setSessionId); setIfIncluded(Include.PRINCIPAL, principal, trace::setPrincipal); trace.setResponse( new HttpTrace.Response(new FilteredTraceableResponse(response))); }
/** * Begins the tracing of the exchange that was initiated by the given {@code request} * being received. * @param request the received request * @return the HTTP trace for the */ public final HttpTrace receivedRequest(TraceableRequest request) { return new HttpTrace(new FilteredTraceableRequest(request)); }
void indexTrace(HttpTrace httpTrace) throws JsonProcessingException { ObjectNode document = objectMapper.valueToTree(httpTrace); document.put(TIMESTAMP_FIELD, httpTrace.getTimestamp().toEpochMilli()); if (document.get("request") != null && document.get("request").get("headers") != null) { for (Iterator<String> i = document.get("request").get("headers").fieldNames(); i.hasNext(); ) { String header = i.next(); if (cachedFilterHeaderOut(requestHeaderFiltered, header)) { i.remove(); } } } if (document.get("response") != null && document.get("response").get("headers") != null) { for (Iterator<String> i = document.get("response").get("headers").fieldNames(); i.hasNext(); ) { String header = i.next(); if (cachedFilterHeaderOut(responseHeadersFiltered, header)) { i.remove(); } } } IndexRequestBuilder request = this.client.prepareIndex(index, index) .setSource(objectWriter.writeValueAsString(document)); bulkProcessor.add(request.request()); }
/** * Adds a new {@code HttpTrace} to the repository * * @param httpTrace the HttpTrace */ @Override public void add(HttpTrace httpTrace) { String path = httpTrace.getRequest().getUri().getPath(); if (Strings.isNullOrEmpty(path)) { return; } boolean ignore = ignoredPatterns.stream().anyMatch(pattern -> pattern.matcher(path).matches()); if (!ignore) { super.add(httpTrace); try { indexTrace(httpTrace); } catch (JsonProcessingException e) { logger.error("Cannot index trace", e); } } }