Java Code Examples for com.nike.wingtips.Span#getSpanId()

The following examples show how to use com.nike.wingtips.Span#getSpanId() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SampleController.java    From wingtips with Apache License 2.0 6 votes vote down vote up
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()
    );
}
 
Example 2
Source File: SampleController.java    From wingtips with Apache License 2.0 6 votes vote down vote up
public EndpointSpanInfoDto(ServerWebExchange exchange, Span endpoint_execution_span, List<String> userIdHeaderKeys) {
    HttpHeaders headers = exchange.getRequest().getHeaders();
    this.parent_span_info = new SpanInfoDto(
        headers.getFirst(TraceHeaders.TRACE_ID),
        headers.getFirst(TraceHeaders.SPAN_ID),
        headers.getFirst(TraceHeaders.PARENT_SPAN_ID),
        headers.getFirst(TraceHeaders.TRACE_SAMPLED),
        HttpRequestTracingUtils.getUserIdFromRequestWithHeaders(
            new RequestWithHeadersServerWebExchangeAdapter(exchange),
            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()
    );
}
 
Example 3
Source File: SampleController.java    From wingtips with Apache License 2.0 6 votes vote down vote up
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()
    );
}
 
Example 4
Source File: VerifyAsyncHttpClientHelperComponentTest.java    From riposte with Apache License 2.0 4 votes vote down vote up
@DataProvider(value = {
        "true   |   true",
        "true   |   false",
        "false  |   true",
        "false  |   false"
}, splitBy = "\\|")
@Test
public void verify_basic_functionality(boolean surroundWithSubspan, boolean parentSpanExists) throws Exception {
    // given
    AsyncHttpClientHelper asyncClient = AsyncHttpClientHelper.builder()
        .setPerformSubSpanAroundDownstreamCalls(surroundWithSubspan)
        .build();

    String fullUrl = "http://localhost:" + serverPort + TestEndpoint.MATCHING_PATH + "?foo=bar";
    RequestBuilderWrapper rbw = asyncClient.getRequestBuilder(fullUrl, HttpMethod.GET);
    rbw.requestBuilder.setHeader(TestEndpoint.EXPECTED_HEADER_KEY, TestEndpoint.EXPECTED_HEADER_VAL);
    rbw.requestBuilder.setBody(TestEndpoint.EXPECTED_REQUEST_PAYLOAD);

    Deque<Span> distributedTraceStackForCall = null;
    Map<String, String> mdcContextForCall = null;
    Span origSpan = null;

    if (parentSpanExists) {
        origSpan = Tracer.getInstance().startRequestWithRootSpan("overallReqSpan");
        distributedTraceStackForCall = Tracer.getInstance().getCurrentSpanStackCopy();
        mdcContextForCall = MDC.getCopyOfContextMap();
        resetTracing();
    }

    // when
    Response result = asyncClient.executeAsyncHttpRequest(
            rbw, response -> response, distributedTraceStackForCall, mdcContextForCall
    ).join();

    // then
    Span subspan = findSubspan();

    assertThat(result.getStatusCode()).isEqualTo(200);
    assertThat(result.getResponseBody()).isEqualTo(TestEndpoint.RESPONSE_PAYLOAD);

    if (surroundWithSubspan) {
        assertThat(subspan).isNotNull();
        assertThat(result.getHeader(TraceHeaders.TRACE_ID)).isEqualTo(subspan.getTraceId());
        assertThat(result.getHeader(TraceHeaders.SPAN_ID)).isEqualTo(subspan.getSpanId());
        assertThat(result.getHeader(TraceHeaders.PARENT_SPAN_ID)).isEqualTo(
                String.valueOf(subspan.getParentSpanId())
        );
        verifySubspanTags(subspan, fullUrl, "200", false);
    } else {
        assertThat(subspan).isNull();
    }

    if (parentSpanExists) {
        assertThat(result.getHeader(TraceHeaders.TRACE_ID)).isEqualTo(origSpan.getTraceId());
        String expectedParentSpanId = (surroundWithSubspan) ? subspan.getParentSpanId() : "null";
        assertThat(result.getHeader(TraceHeaders.PARENT_SPAN_ID)).isEqualTo(expectedParentSpanId);
        String expectedSpanId = (surroundWithSubspan) ? subspan.getSpanId() : origSpan.getSpanId();
        assertThat(result.getHeader(TraceHeaders.SPAN_ID)).isEqualTo(expectedSpanId);
    }

    if (!parentSpanExists && !surroundWithSubspan) {
        assertThat(result.getHeader(TraceHeaders.TRACE_ID)).isEqualTo("null");
        assertThat(result.getHeader(TraceHeaders.SPAN_ID)).isEqualTo("null");
        assertThat(result.getHeader(TraceHeaders.PARENT_SPAN_ID)).isEqualTo("null");
    }
}
 
Example 5
Source File: VerifyAsyncHttpClientHelperComponentTest.java    From riposte with Apache License 2.0 4 votes vote down vote up
@DataProvider(value = {
    "true   |   true",
    "true   |   false",
    "false  |   true",
    "false  |   false"
}, splitBy = "\\|")
@Test
public void verify_basic_functionality(boolean surroundWithSubspan, boolean parentSpanExists) throws Exception {
    // given
    AsyncHttpClientHelper asyncClient = new AsyncHttpClientHelper(surroundWithSubspan);

    String fullUrl = "http://localhost:" + serverPort + TestEndpoint.MATCHING_PATH + "?foo=bar";
    RequestBuilderWrapper rbw = asyncClient.getRequestBuilder(fullUrl, HttpMethod.GET);
    rbw.requestBuilder.setHeader(TestEndpoint.EXPECTED_HEADER_KEY, TestEndpoint.EXPECTED_HEADER_VAL);
    rbw.requestBuilder.setBody(TestEndpoint.EXPECTED_REQUEST_PAYLOAD);

    Deque<Span> distributedTraceStackForCall = null;
    Map<String, String> mdcContextForCall = null;
    Span origSpan = null;

    if (parentSpanExists) {
        origSpan = Tracer.getInstance().startRequestWithRootSpan("overallReqSpan");
        distributedTraceStackForCall = Tracer.getInstance().getCurrentSpanStackCopy();
        mdcContextForCall = MDC.getCopyOfContextMap();
        resetTracing();
    }

    // when
    Response result = asyncClient.executeAsyncHttpRequest(
        rbw, response -> response, distributedTraceStackForCall, mdcContextForCall
    ).join();

    // then
    Span subspan = findSubspan();

    assertThat(result.getStatusCode()).isEqualTo(200);
    assertThat(result.getResponseBody()).isEqualTo(TestEndpoint.RESPONSE_PAYLOAD);

    if (surroundWithSubspan) {
        assertThat(subspan).isNotNull();
        assertThat(result.getHeader(TraceHeaders.TRACE_ID)).isEqualTo(subspan.getTraceId());
        assertThat(result.getHeader(TraceHeaders.SPAN_ID)).isEqualTo(subspan.getSpanId());
        assertThat(result.getHeader(TraceHeaders.PARENT_SPAN_ID)).isEqualTo(
            String.valueOf(subspan.getParentSpanId())
        );
        verifySubspanTags(subspan, fullUrl, "200", false);
    }
    else {
        assertThat(subspan).isNull();
    }

    if (parentSpanExists) {
        assertThat(result.getHeader(TraceHeaders.TRACE_ID)).isEqualTo(origSpan.getTraceId());
        String expectedParentSpanId = (surroundWithSubspan) ? subspan.getParentSpanId() : "null";
        assertThat(result.getHeader(TraceHeaders.PARENT_SPAN_ID)).isEqualTo(expectedParentSpanId);
        String expectedSpanId = (surroundWithSubspan) ? subspan.getSpanId() : origSpan.getSpanId();
        assertThat(result.getHeader(TraceHeaders.SPAN_ID)).isEqualTo(expectedSpanId);
    }

    if (!parentSpanExists && !surroundWithSubspan) {
        assertThat(result.getHeader(TraceHeaders.TRACE_ID)).isEqualTo("null");
        assertThat(result.getHeader(TraceHeaders.SPAN_ID)).isEqualTo("null");
        assertThat(result.getHeader(TraceHeaders.PARENT_SPAN_ID)).isEqualTo("null");
    }
}
 
Example 6
Source File: VerifySampleEndpointsComponentTest.java    From wingtips with Apache License 2.0 4 votes vote down vote up
private SpanInfoDto spanInfoDtoFromSpan(Span span) {
    return new SpanInfoDto(
        span.getTraceId(), span.getSpanId(), span.getParentSpanId(), String.valueOf(span.isSampleable()),
        span.getUserId()
    );
}
 
Example 7
Source File: VerifySampleEndpointsComponentTest.java    From wingtips with Apache License 2.0 4 votes vote down vote up
private SpanInfoDto spanInfoDtoFromSpan(Span span) {
    return new SpanInfoDto(
        span.getTraceId(), span.getSpanId(), span.getParentSpanId(), String.valueOf(span.isSampleable()),
        span.getUserId()
    );
}
 
Example 8
Source File: VerifySampleEndpointsComponentTest.java    From wingtips with Apache License 2.0 4 votes vote down vote up
private SpanInfoDto spanInfoDtoFromSpan(Span span) {
    return new SpanInfoDto(
        span.getTraceId(), span.getSpanId(), span.getParentSpanId(), String.valueOf(span.isSampleable()),
        span.getUserId()
    );
}