private SpanInfoDto emptySpanInfoDto() { return new SpanInfoDto(null, null, null, null, null); }
@GetMapping(path = BLOCKING_PATH) @SuppressWarnings("unused") public String getBlocking() { logger.info("Blocking endpoint hit"); sleepThread(SLEEP_TIME_MILLIS); return BLOCKING_RESULT; }
@GetMapping(path = SPAN_INFO_CALL_PATH) @SuppressWarnings("unused") public EndpointSpanInfoDto getSpanInfoCall(HttpServletRequest request) { logger.info("Span info endpoint hit. Sleeping..."); sleepThread(SLEEP_TIME_MILLIS); return new EndpointSpanInfoDto(request, Tracer.getInstance().getCurrentSpan(), userIdHeaderKeys); }
@GetMapping(path = NESTED_BLOCKING_CALL_PATH) @SuppressWarnings("unused") public EndpointSpanInfoDto getNestedBlockingCall() { logger.info("Nested blocking call endpoint hit. Sleeping..."); sleepThread(SLEEP_TIME_MILLIS); URI nestedCallUri = URI.create( "http://localhost:" + serverPort + SPAN_INFO_CALL_PATH + "?someQuery=foobar"); logger.info("...Calling: " + nestedCallUri.toString()); EndpointSpanInfoDto returnVal = wingtipsEnabledRestTemplate .exchange(nestedCallUri, HttpMethod.GET, getHttpEntityWithUserIdHeader(), EndpointSpanInfoDto.class) .getBody(); logger.info("Blocking RestTemplate call complete"); return returnVal; }
public EndpointSpanInfoDto(HttpServletRequest request, Span endpoint_execution_span, List<String> userIdHeaderKeys) { this.parent_span_info = new SpanInfoDto( request.getHeader(TraceHeaders.TRACE_ID), request.getHeader(TraceHeaders.SPAN_ID), request.getHeader(TraceHeaders.PARENT_SPAN_ID), request.getHeader(TraceHeaders.TRACE_SAMPLED), HttpSpanFactory.getUserIdFromHttpServletRequest(request, userIdHeaderKeys) ); this.endpoint_execution_span_info = new SpanInfoDto( endpoint_execution_span.getTraceId(), endpoint_execution_span.getSpanId(), endpoint_execution_span.getParentSpanId(), String.valueOf(endpoint_execution_span.isSampleable()), endpoint_execution_span.getUserId() ); }
@GetMapping(path = NESTED_ASYNC_CALL_PATH) @SuppressWarnings("unused") public DeferredResult<EndpointSpanInfoDto> getNestedAsyncCall() { DeferredResult<EndpointSpanInfoDto> asyncResponse = new DeferredResult<>(); executor.execute(runnableWithTracing(() -> { try { logger.info("Nested async call endpoint hit. Sleeping..."); sleepThread(SLEEP_TIME_MILLIS); URI nestedCallUri = URI.create( "http://localhost:" + serverPort + SPAN_INFO_CALL_PATH + "?someQuery=foobar" ); logger.info("...Calling: " + nestedCallUri.toString()); ListenableFuture<ResponseEntity<EndpointSpanInfoDto>> asyncRestTemplateResultFuture = wingtipsEnabledAsyncRestTemplate.exchange( nestedCallUri, HttpMethod.GET, getHttpEntityWithUserIdHeader(), EndpointSpanInfoDto.class ); asyncRestTemplateResultFuture.addCallback( successCallbackWithTracing(result -> { logger.info("AsyncRestTemplate call complete"); asyncResponse.setResult(result.getBody()); }), failureCallbackWithTracing(asyncResponse::setErrorResult) ); } catch(Throwable t) { asyncResponse.setErrorResult(t); } })); return asyncResponse; }
@GetMapping(path = WILDCARD_PATH_PREFIX + "/**") @SuppressWarnings("unused") public String getWildcard() { logger.info("Wildcard endpoint hit"); sleepThread(SLEEP_TIME_MILLIS); return WILDCARD_RESULT; }
private SpanInfoDto spanInfoDtoFromSpan(Span span) { return new SpanInfoDto( span.getTraceId(), span.getSpanId(), span.getParentSpanId(), String.valueOf(span.isSampleable()), span.getUserId() ); }
@GetMapping(path = PATH_PARAM_ENDPOINT_PATH_PREFIX + "/{somePathParam}") @SuppressWarnings("unused") public String getPathParam(@PathVariable String somePathParam) { logger.info("Path param endpoint hit - somePathParam: {}", somePathParam); sleepThread(SLEEP_TIME_MILLIS); return PATH_PARAM_ENDPOINT_RESULT; }
@GetMapping(path = ASYNC_CALLABLE_PATH) @SuppressWarnings("unused") public Callable<String> getAsyncCallable() { logger.info("Async endpoint hit (Callable)"); return callableWithTracing(() -> { logger.info("Async endpoint (Callable) async logic"); sleepThread(SLEEP_TIME_MILLIS); return ASYNC_CALLABLE_RESULT; }); }
@GetMapping(path = ASYNC_FUTURE_PATH) @SuppressWarnings("unused") public CompletableFuture<String> getAsyncCompletableFuture() { logger.info("Async endpoint hit (CompletableFuture)"); return CompletableFuture.supplyAsync(supplierWithTracing( () -> { logger.info("Async endpoint (CompletableFuture) async logic"); sleepThread(SLEEP_TIME_MILLIS); return ASYNC_FUTURE_RESULT; }), executor ); }
@GetMapping(path = ASYNC_ERROR_PATH) @SuppressWarnings("unused") public DeferredResult<String> getAsyncError() { logger.info("Async error endpoint hit"); sleepThread(SLEEP_TIME_MILLIS); DeferredResult<String> deferredResult = new DeferredResult<>(); deferredResult.setErrorResult(new RuntimeException("Intentional exception by asyncError endpoint")); return deferredResult; }
@GetMapping(path = ASYNC_DEFERRED_RESULT_PATH) @SuppressWarnings("unused") public DeferredResult<String> getAsyncDeferredResult() { logger.info("Async endpoint hit (DeferredResult)"); DeferredResult<String> asyncResponse = new DeferredResult<>(); executor.execute(runnableWithTracing(() -> { logger.info("Async endpoint (DeferredResult) async logic"); sleepThread(SLEEP_TIME_MILLIS); asyncResponse.setResult(ASYNC_DEFERRED_RESULT_PAYLOAD); })); return asyncResponse; }