当前位置: 首页>>代码示例>>Java>>正文


Java Tracer类代码示例

本文整理汇总了Java中com.nike.wingtips.Tracer的典型用法代码示例。如果您正苦于以下问题:Java Tracer类的具体用法?Java Tracer怎么用?Java Tracer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Tracer类属于com.nike.wingtips包,在下文中一共展示了Tracer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: completeRequestSpan

import com.nike.wingtips.Tracer; //导入依赖的package包/类
protected void completeRequestSpan() {
    // Async servlet stuff can trigger multiple completion methods depending on how the request is processed,
    //      but we only care about the first.
    if (alreadyCompleted) {
        return;
    }

    try {
        //noinspection deprecation
        runnableWithTracing(
            new Runnable() {
                @Override
                public void run() {
                    Tracer.getInstance().completeRequestSpan();
                }
            },
            originalRequestTracingState
        ).run();
    }
    finally {
        alreadyCompleted = true;
    }
}
 
开发者ID:Nike-Inc,项目名称:wingtips,代码行数:24,代码来源:WingtipsRequestSpanCompletionAsyncListener.java

示例2: linkTracingAndMdcToCurrentThread_should_set_tracing_and_mdc_to_state_values_if_available

import com.nike.wingtips.Tracer; //导入依赖的package包/类
@Test
public void linkTracingAndMdcToCurrentThread_should_set_tracing_and_mdc_to_state_values_if_available() {
    // given
    Map<String, String> stateMdcInfo = new HashMap<>();
    stateMdcInfo.put("foo", "bar");
    Deque<Span> stateTraceStack = new LinkedList<>();
    Span span = Span.generateRootSpanForNewTrace("fooSpanName", LOCAL_ONLY).withTraceId("fooTraceId").build();
    stateTraceStack.add(span);
    state.setLoggerMdcContextMap(stateMdcInfo);
    state.setDistributedTraceStack(stateTraceStack);

    assertThat(MDC.getCopyOfContextMap().isEmpty(), is(true));
    assertThat(Tracer.getInstance().getCurrentSpan(), nullValue());

    // when
    handler.linkTracingAndMdcToCurrentThread(ctxMock);

    // then
    // Tracer adds some stuff to the MDC
    stateMdcInfo.put(Tracer.TRACE_ID_MDC_KEY, span.getTraceId());
    stateMdcInfo.put(Tracer.SPAN_JSON_MDC_KEY, span.toJSON());
    assertThat(MDC.getCopyOfContextMap(), is(stateMdcInfo));
    assertThat(Tracer.getInstance().getCurrentSpanStackCopy(), is(stateTraceStack));
}
 
开发者ID:Nike-Inc,项目名称:riposte,代码行数:25,代码来源:BaseInboundHandlerWithTracingAndMdcSupportTest.java

示例3: doReturn

import com.nike.wingtips.Tracer; //导入依赖的package包/类
@Test
public void unlinkTracingAndMdcFromCurrentThread_should_reset_tracing_and_mdc_to_originalThreadInfo_if_state_is_null() {
    // given
    doReturn(null).when(stateAttributeMock).get();
    MDC.put("foo", "bar");
    Tracer.getInstance().startRequestWithRootSpan("blahtrace");
    assertThat(MDC.getCopyOfContextMap().isEmpty(), is(false));
    assertThat(Tracer.getInstance().getCurrentSpan(), notNullValue());

    Deque<Span> origTraceStack = new LinkedList<>();
    Span origSpan = Span.newBuilder(UUID.randomUUID().toString(), LOCAL_ONLY).withTraceId(UUID.randomUUID().toString()).build();
    origTraceStack.add(origSpan);
    Map<String, String> origMdcInfo = new HashMap<>();
    origMdcInfo.put(UUID.randomUUID().toString(), UUID.randomUUID().toString());
    origMdcInfo.put(Tracer.TRACE_ID_MDC_KEY, origSpan.getTraceId());
    origMdcInfo.put(Tracer.SPAN_JSON_MDC_KEY, origSpan.toJSON());
    Pair<Deque<Span>, Map<String, String>> origThreadInfo = Pair.of(origTraceStack, origMdcInfo);

    // when
    handler.unlinkTracingAndMdcFromCurrentThread(ctxMock, origThreadInfo);

    // then
    assertThat(MDC.getCopyOfContextMap(), is(origMdcInfo));
    assertThat(Tracer.getInstance().getCurrentSpanStackCopy(), is(origTraceStack));
}
 
开发者ID:Nike-Inc,项目名称:riposte,代码行数:26,代码来源:BaseInboundHandlerWithTracingAndMdcSupportTest.java

示例4: beforeMethod

import com.nike.wingtips.Tracer; //导入依赖的package包/类
@Before
public void beforeMethod() {
    handlerSpy = spy(new DTraceEndHandler());
    channelMock = mock(Channel.class);
    ctxMock = mock(ChannelHandlerContext.class);
    stateAttributeMock = mock(Attribute.class);
    state = new HttpProcessingState();
    doReturn(channelMock).when(ctxMock).channel();
    doReturn(stateAttributeMock).when(channelMock).attr(ChannelAttributes.HTTP_PROCESSING_STATE_ATTRIBUTE_KEY);
    doReturn(state).when(stateAttributeMock).get();
    resetTracingAndMdc();

    responseInfoMock = mock(ResponseInfo.class);
    doReturn(true).when(responseInfoMock).isResponseSendingLastChunkSent();
    state.setResponseInfo(responseInfoMock);

    lastChunkChannelFutureMock = mock(ChannelFuture.class);
    state.setResponseWriterFinalChunkChannelFuture(lastChunkChannelFutureMock);

    doAnswer(invocation -> {
        currentSpanWhenCompleteCurrentSpanWasCalled = Tracer.getInstance().getCurrentSpan();
        invocation.callRealMethod();
        currentSpanAfterCompleteCurrentSpanWasCalled = Tracer.getInstance().getCurrentSpan();
        return null;
    }).when(handlerSpy).completeCurrentSpan();
}
 
开发者ID:Nike-Inc,项目名称:riposte,代码行数:27,代码来源:DTraceEndHandlerTest.java

示例5: startTrace_creates_new_trace_if_no_parent_available

import com.nike.wingtips.Tracer; //导入依赖的package包/类
@Test
public void startTrace_creates_new_trace_if_no_parent_available() {
    // given
    String expectedSpanName = handler.getSpanName(httpRequest);

    assertThat(Tracer.getInstance().getCurrentSpan(), nullValue());

    // when
    handler.startTrace(httpRequest);

    // then
    Span span = Tracer.getInstance().getCurrentSpan();
    assertThat(span.getTraceId(), notNullValue());
    assertThat(span.getParentSpanId(), nullValue());
    assertThat(span.getSpanId(), notNullValue());
    assertThat(span.getSpanName(), is(expectedSpanName));
    assertThat(span.getUserId(), nullValue());
}
 
开发者ID:Nike-Inc,项目名称:riposte,代码行数:19,代码来源:DTraceStartHandlerTest.java

示例6: beforeMethod

import com.nike.wingtips.Tracer; //导入依赖的package包/类
@Before
public void beforeMethod() {
    failureCallbackMock = mock(FailureCallback.class);

    inObj = new Exception("kaboom");
    throwExceptionDuringCall = false;
    currentSpanStackWhenFailureCallbackWasCalled = new ArrayList<>();
    currentMdcInfoWhenFailureCallbackWasCalled = new ArrayList<>();
    doAnswer(invocation -> {
        currentSpanStackWhenFailureCallbackWasCalled.add(Tracer.getInstance().getCurrentSpanStackCopy());
        currentMdcInfoWhenFailureCallbackWasCalled.add(MDC.getCopyOfContextMap());
        if (throwExceptionDuringCall)
            throw new RuntimeException("kaboom");
        return null;
    }).when(failureCallbackMock).onFailure(inObj);

    resetTracing();
}
 
开发者ID:Nike-Inc,项目名称:wingtips,代码行数:19,代码来源:FailureCallbackWithTracingTest.java

示例7: linkTracingAndMdcToCurrentThread_pair_works_as_expected_with_non_null_pair_and_null_innards

import com.nike.wingtips.Tracer; //导入依赖的package包/类
@Test
public void linkTracingAndMdcToCurrentThread_pair_works_as_expected_with_non_null_pair_and_null_innards() {
    // given
    Pair<Deque<Span>, Map<String, String>> infoForLinking = Pair.of(null, null);
    resetTracingAndMdc();
    Tracer.getInstance().startRequestWithRootSpan("foo-" + UUID.randomUUID().toString());
    Pair<Deque<Span>, Map<String, String>> expectedPreCallInfo = Pair.of(
        Tracer.getInstance().getCurrentSpanStackCopy(),
        MDC.getCopyOfContextMap()
    );

    // when
    Pair<Deque<Span>, Map<String, String>> preCallInfo =
        AsyncNettyHelper.linkTracingAndMdcToCurrentThread(infoForLinking);
    Pair<Deque<Span>, Map<String, String>> postCallInfo = Pair.of(
        Tracer.getInstance().getCurrentSpanStackCopy(),
        MDC.getCopyOfContextMap()
    );

    // then
    assertThat(preCallInfo).isEqualTo(expectedPreCallInfo);
    assertThat(postCallInfo).isEqualTo(Pair.of(null, Collections.emptyMap()));
}
 
开发者ID:Nike-Inc,项目名称:riposte,代码行数:24,代码来源:AsyncNettyHelperTest.java

示例8: unlinkTracingAndMdcFromCurrentThread_pair_works_as_expected_with_non_null_pair_and_null_innards

import com.nike.wingtips.Tracer; //导入依赖的package包/类
@Test
public void unlinkTracingAndMdcFromCurrentThread_pair_works_as_expected_with_non_null_pair_and_null_innards() {
    // given
    Pair<Deque<Span>, Map<String, String>> infoForLinking = Pair.of(null, null);
    // Setup the current thread with something that is not ultimately what we expect so that our assertions are
    //      verifying that the unlinkTracingAndMdcFromCurrentThread method actually did something.
    resetTracingAndMdc();
    Tracer.getInstance().startRequestWithRootSpan("foo-" + UUID.randomUUID().toString());

    // when
    AsyncNettyHelper.unlinkTracingAndMdcFromCurrentThread(infoForLinking);
    Pair<Deque<Span>, Map<String, String>> postCallInfo = Pair.of(
        Tracer.getInstance().getCurrentSpanStackCopy(),
        MDC.getCopyOfContextMap()
    );

    // then
    assertThat(postCallInfo).isEqualTo(Pair.of(null, Collections.emptyMap()));
}
 
开发者ID:Nike-Inc,项目名称:riposte,代码行数:20,代码来源:AsyncNettyHelperTest.java

示例9: beforeMethod

import com.nike.wingtips.Tracer; //导入依赖的package包/类
@Before
public void beforeMethod() {
    listenableFutureCallbackMock = mock(ListenableFutureCallback.class);

    successInObj = new Object();
    failureInObj = new Exception("kaboom");
    throwExceptionDuringCall = false;
    currentSpanStackWhenListenableFutureCallbackWasCalled = new ArrayList<>();
    currentMdcInfoWhenListenableFutureCallbackWasCalled = new ArrayList<>();
    doAnswer(invocation -> {
        currentSpanStackWhenListenableFutureCallbackWasCalled.add(Tracer.getInstance().getCurrentSpanStackCopy());
        currentMdcInfoWhenListenableFutureCallbackWasCalled.add(MDC.getCopyOfContextMap());
        if (throwExceptionDuringCall)
            throw new RuntimeException("kaboom");
        return null;
    }).when(listenableFutureCallbackMock).onSuccess(successInObj);
    doAnswer(invocation -> {
        currentSpanStackWhenListenableFutureCallbackWasCalled.add(Tracer.getInstance().getCurrentSpanStackCopy());
        currentMdcInfoWhenListenableFutureCallbackWasCalled.add(MDC.getCopyOfContextMap());
        if (throwExceptionDuringCall)
            throw new RuntimeException("kaboom");
        return null;
    }).when(listenableFutureCallbackMock).onFailure(failureInObj);

    resetTracing();
}
 
开发者ID:Nike-Inc,项目名称:wingtips,代码行数:27,代码来源:ListenableFutureCallbackWithTracingTest.java

示例10: executeAsyncCall_shouldReturnCompletableFuture

import com.nike.wingtips.Tracer; //导入依赖的package包/类
@Test
public void executeAsyncCall_shouldReturnCompletableFuture() throws Exception {
    // given
    String expectedResult = UUID.randomUUID().toString();
    ctxMock = TestUtil.mockChannelHandlerContextWithTraceInfo().mockContext;
    Span parentSpan = Tracer.getInstance().getCurrentSpan();
    AtomicReference<Span> runningSpan = new AtomicReference<>();

    // when
    CompletableFuture<String> completableFuture = AsyncNettyHelper.supplyAsync(
            () -> {
                runningSpan.set(Tracer.getInstance().getCurrentSpan());
                return expectedResult;
            },
            executor, ctxMock);

    // then
    assertThat(completableFuture.isCompletedExceptionally()).isFalse();
    assertThat(completableFuture.get()).isEqualTo(expectedResult);
    // verify new span is not created, but existing span does successfully hop threads
    assertThat(runningSpan.get()).isEqualTo(parentSpan);
}
 
开发者ID:Nike-Inc,项目名称:riposte,代码行数:23,代码来源:AsyncNettyHelperTest.java

示例11: executeAsyncCall_shouldReturnCompletableFutureUsingSpanName

import com.nike.wingtips.Tracer; //导入依赖的package包/类
@Test
public void executeAsyncCall_shouldReturnCompletableFutureUsingSpanName() throws Exception {
    // given
    String expectedResult = UUID.randomUUID().toString();
    String expectedSpanName = "nonCircuitBreakerWithSpan";
    ctxMock = TestUtil.mockChannelHandlerContextWithTraceInfo().mockContext;
    Span parentSpan = Tracer.getInstance().getCurrentSpan();
    AtomicReference<Span> runningSpan = new AtomicReference<>();

    // when
    CompletableFuture<String> completableFuture = AsyncNettyHelper.supplyAsync(
            expectedSpanName,
            () -> {
                runningSpan.set(Tracer.getInstance().getCurrentSpan());
                return expectedResult;
            },
            executor, ctxMock);

    // then
    assertThat(completableFuture.isCompletedExceptionally()).isFalse();
    assertThat(completableFuture.get()).isEqualTo(expectedResult);
    // verify span is as expected
    assertThat(runningSpan.get().getParentSpanId()).isEqualTo(parentSpan.getSpanId());
    assertThat(runningSpan.get().getSpanName()).isEqualTo(expectedSpanName);
    assertThat(runningSpan.get().getTraceId()).isEqualTo(parentSpan.getTraceId());
}
 
开发者ID:Nike-Inc,项目名称:riposte,代码行数:27,代码来源:AsyncNettyHelperTest.java

示例12: intercept

import com.nike.wingtips.Tracer; //导入依赖的package包/类
@Override
public ClientHttpResponse intercept(
    HttpRequest request, byte[] body, ClientHttpRequestExecution execution
) throws IOException {
    Tracer tracer = Tracer.getInstance();
    Span spanAroundCall = null;
    try {
        if (surroundCallsWithSubspan) {
            // Will start a new trace if necessary, or a subspan if a trace is already in progress.
            spanAroundCall = tracer.startSpanInCurrentContext(getSubspanSpanName(request), SpanPurpose.CLIENT);
        }

        HttpRequest wrapperRequest = new HttpRequestWrapperWithModifiableHeaders(request);
        propagateTracingHeaders(wrapperRequest, tracer.getCurrentSpan());

        return execution.execute(wrapperRequest, body);
    }
    finally {
        if (spanAroundCall != null) {
            // Span.close() contains the logic we want - if the spanAroundCall was an overall span (new trace)
            //      then tracer.completeRequestSpan() will be called, otherwise it's a subspan and
            //      tracer.completeSubSpan() will be called.
            spanAroundCall.close();
        }
    }
}
 
开发者ID:Nike-Inc,项目名称:wingtips,代码行数:27,代码来源:WingtipsClientHttpRequestInterceptor.java

示例13: beforeMethod

import com.nike.wingtips.Tracer; //导入依赖的package包/类
@Before
public void beforeMethod() {
    channelMock = mock(Channel.class);
    ctxMock = mock(ChannelHandlerContext.class);
    stateAttributeMock = mock(Attribute.class);
    state = new HttpProcessingState();
    doReturn(channelMock).when(ctxMock).channel();
    doReturn(stateAttributeMock).when(channelMock).attr(ChannelAttributes.HTTP_PROCESSING_STATE_ATTRIBUTE_KEY);
    doReturn(state).when(stateAttributeMock).get();

    consumerMock = mock(Consumer.class);

    inObj = new Object();
    throwExceptionDuringCall = false;
    currentSpanStackWhenConsumerWasCalled = new ArrayList<>();
    currentMdcInfoWhenConsumerWasCalled = new ArrayList<>();
    doAnswer(invocation -> {
        currentSpanStackWhenConsumerWasCalled.add(Tracer.getInstance().getCurrentSpanStackCopy());
        currentMdcInfoWhenConsumerWasCalled.add(MDC.getCopyOfContextMap());
        if (throwExceptionDuringCall)
            throw new RuntimeException("kaboom");
        return null;
    }).when(consumerMock).accept(inObj);

    resetTracingAndMdc();
}
 
开发者ID:Nike-Inc,项目名称:riposte,代码行数:27,代码来源:ConsumerWithTracingAndMdcSupportTest.java

示例14: beforeMethod

import com.nike.wingtips.Tracer; //导入依赖的package包/类
@Before
public void beforeMethod() {
    channelMock = mock(Channel.class);
    ctxMock = mock(ChannelHandlerContext.class);
    stateAttributeMock = mock(Attribute.class);
    state = new HttpProcessingState();
    doReturn(channelMock).when(ctxMock).channel();
    doReturn(stateAttributeMock).when(channelMock).attr(ChannelAttributes.HTTP_PROCESSING_STATE_ATTRIBUTE_KEY);
    doReturn(state).when(stateAttributeMock).get();

    consumerMock = mock(Consumer.class);

    inObj = mock(ChannelFuture.class);
    throwExceptionDuringCall = false;
    currentSpanStackWhenChannelFutureWasCalled = new ArrayList<>();
    currentMdcInfoWhenChannelFutureWasCalled = new ArrayList<>();
    doAnswer(invocation -> {
        currentSpanStackWhenChannelFutureWasCalled.add(Tracer.getInstance().getCurrentSpanStackCopy());
        currentMdcInfoWhenChannelFutureWasCalled.add(MDC.getCopyOfContextMap());
        if (throwExceptionDuringCall)
            throw new RuntimeException("kaboom");
        return null;
    }).when(consumerMock).accept(inObj);

    resetTracingAndMdc();
}
 
开发者ID:Nike-Inc,项目名称:riposte,代码行数:27,代码来源:ChannelFutureListenerWithTracingAndMdcTest.java

示例15: beforeMethod

import com.nike.wingtips.Tracer; //导入依赖的package包/类
@Before
public void beforeMethod() throws Exception {
    channelMock = mock(Channel.class);
    ctxMock = mock(ChannelHandlerContext.class);
    stateAttributeMock = mock(Attribute.class);
    state = new HttpProcessingState();
    doReturn(channelMock).when(ctxMock).channel();
    doReturn(stateAttributeMock).when(channelMock).attr(ChannelAttributes.HTTP_PROCESSING_STATE_ATTRIBUTE_KEY);
    doReturn(state).when(stateAttributeMock).get();

    callableMock = mock(Callable.class);

    throwExceptionDuringCall = false;
    currentSpanStackWhenCallableWasCalled = new ArrayList<>();
    currentMdcInfoWhenCallableWasCalled = new ArrayList<>();
    doAnswer(invocation -> {
        currentSpanStackWhenCallableWasCalled.add(Tracer.getInstance().getCurrentSpanStackCopy());
        currentMdcInfoWhenCallableWasCalled.add(MDC.getCopyOfContextMap());
        if (throwExceptionDuringCall)
            throw new RuntimeException("kaboom");
        return null;
    }).when(callableMock).call();

    resetTracingAndMdc();
}
 
开发者ID:Nike-Inc,项目名称:riposte,代码行数:26,代码来源:CallableWithTracingAndMdcSupportTest.java


注:本文中的com.nike.wingtips.Tracer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。