Java Code Examples for com.nike.internal.util.Pair#getLeft()
The following examples show how to use
com.nike.internal.util.Pair#getLeft() .
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: AsyncWingtipsHelperJava7.java From wingtips with Apache License 2.0 | 5 votes |
/** * Helper method for calling {@link #unlinkTracingFromCurrentThread(Deque, Map)} that * gracefully handles the case where the pair you pass in is null - if the pair you pass in is null then {@link * #unlinkTracingFromCurrentThread(Deque, Map)} will be called with both arguments null. You can pass in a {@link * TracingState} for clearer less verbose code since it extends {@code Pair<Deque<Span>, Map<String, String>>}. * * @deprecated Please move to the Java 8 version of this class and method ({@code AsyncWingtipsHelper} or the static * {@code AsyncWingtipsHelperStatic}) whenever possible. */ @Deprecated public static void unlinkTracingFromCurrentThread( Pair<Deque<Span>, Map<String, String>> threadInfoToResetFor ) { Deque<Span> spanStackToResetFor = (threadInfoToResetFor == null) ? null : threadInfoToResetFor.getLeft(); Map<String, String> mdcContextMapToResetFor = (threadInfoToResetFor == null) ? null : threadInfoToResetFor.getRight(); unlinkTracingFromCurrentThread(spanStackToResetFor, mdcContextMapToResetFor); }
Example 2
Source File: VerifyExampleEndpointComponentTest.java From riposte-microservice-template with Apache License 2.0 | 5 votes |
@BeforeClass public static void setup() throws Exception { Pair<Server, TestUtils.AppServerConfigForTesting> serverAndConfigPair = TestUtils.createServerForTesting(); serverConfig = serverAndConfigPair.getRight(); realRunningServer = serverAndConfigPair.getLeft(); realRunningServer.startup(); }
Example 3
Source File: ChannelPipelineFinalizerHandler.java From riposte with Apache License 2.0 | 5 votes |
@SuppressWarnings("SameParameterValue") protected void logErrorWithTracing(String msg, Throwable ex, ChannelHandlerContext ctx) { Pair<Deque<Span>, Map<String, String>> tracingState = AsyncNettyHelper.extractTracingAndMdcInfoFromChannelHandlerContext(ctx); Deque<Span> distributedTraceStackToLink = null; Map<String, String> mdcContextMapToLink = null; if (tracingState != null) { distributedTraceStackToLink = tracingState.getLeft(); mdcContextMapToLink = tracingState.getRight(); } logErrorWithTracing(msg, ex, distributedTraceStackToLink, mdcContextMapToLink); }
Example 4
Source File: AsyncNettyHelper.java From riposte with Apache License 2.0 | 5 votes |
/** * Helper method for calling {@link #unlinkTracingAndMdcFromCurrentThread(Deque, Map)} that * gracefully handles the case where the pair you pass in is null - if the pair you pass in is null then {@link * #unlinkTracingAndMdcFromCurrentThread(Deque, Map)} will be called with both arguments null. */ public static void unlinkTracingAndMdcFromCurrentThread( Pair<Deque<Span>, Map<String, String>> threadInfoToResetFor) { Deque<Span> traceStackToResetFor = (threadInfoToResetFor == null) ? null : threadInfoToResetFor.getLeft(); Map<String, String> mdcContextMapToResetFor = (threadInfoToResetFor == null) ? null : threadInfoToResetFor.getRight(); unlinkTracingAndMdcFromCurrentThread(traceStackToResetFor, mdcContextMapToResetFor); }
Example 5
Source File: AsyncCompletionHandlerWithTracingAndMdcSupportTest.java From riposte with Apache License 2.0 | 4 votes |
@DataProvider(value = { "null", "false", "true" }) @Test public void onThrowable_deals_with_trace_info_as_expected(Boolean setupForSubspan) throws Throwable { // given Exception ex = new Exception("kaboom"); CompletableFuture<String> cfMock = mock(CompletableFuture.class); Whitebox.setInternalState(handlerSpy, "completableFutureResponse", cfMock); doReturn(false).when(cfMock).isDone(); Pair<Deque<Span>, Map<String, String>> traceInfo = generateTraceInfo(setupForSubspan); Whitebox.setInternalState(handlerSpy, "distributedTraceStackToUse", traceInfo.getLeft()); Whitebox.setInternalState(handlerSpy, "mdcContextToUse", traceInfo.getRight()); Whitebox.setInternalState(handlerSpy, "performSubSpanAroundDownstreamCalls", TRUE.equals(setupForSubspan)); Span expectedSpanBeforeCompletion = (traceInfo.getLeft() == null) ? null : traceInfo.getLeft().peek(); Span expectedSpanAfterCompletion = (setupForSubspan == null) ? null // If setupForSubspan is true, then there will be two items and peekLast will // get the "parent". Otherwise there will only be one item, and // peekLast will still get the correct thing (in this case the only // one there). : traceInfo.getLeft().peekLast(); Pair<ObjectHolder<Span>, ObjectHolder<Span>> actualBeforeAndAfterSpanHolders = setupBeforeAndAfterSpanCaptureForOnThrowable(cfMock); // when handlerSpy.onThrowable(ex); // then verify(circuitBreakerManualTaskMock).handleException(ex); verify(cfMock).completeExceptionally(ex); assertThat(actualBeforeAndAfterSpanHolders.getLeft().objSet).isTrue(); assertThat(actualBeforeAndAfterSpanHolders.getRight().objSet).isTrue(); assertThat(actualBeforeAndAfterSpanHolders.getLeft().obj).isEqualTo(expectedSpanBeforeCompletion); assertThat(actualBeforeAndAfterSpanHolders.getRight().obj).isEqualTo(expectedSpanAfterCompletion); if (TRUE.equals(setupForSubspan)) { assertThat(strategyResponseTaggingAndFinalSpanNameMethodCalled.get()).isTrue(); strategyResponseTaggingArgs.get().verifyArgs( expectedSpanBeforeCompletion, handlerSpy.rbwCopyWithHttpMethodAndUrlOnly, null, ex, wingtipsTagAndNamingAdapterMock ); } else { assertThat(strategyResponseTaggingAndFinalSpanNameMethodCalled.get()).isFalse(); } }
Example 6
Source File: AsyncWingtipsHelperJava7Test.java From wingtips with Apache License 2.0 | 4 votes |
@DataProvider(value = { "true | true", "false | true", "true | false", "false | false" }, splitBy = "\\|") @Test public void linkTracingToCurrentThread_separate_args_works_as_expected(boolean useNullSpanStack, boolean useNullMdcInfo) { // given Pair<Deque<Span>, Map<String, String>> info = generateTracingInfo(); info.getRight().put("fooMdcKey", UUID.randomUUID().toString()); Deque<Span> spanStackForLinking = (useNullSpanStack) ? null : info.getLeft(); Map<String, String> mdcInfoForLinking = (useNullMdcInfo) ? null : info.getRight(); resetTracing(); Tracer.getInstance().startRequestWithRootSpan("foo-" + UUID.randomUUID().toString()); Pair<Deque<Span>, Map<String, String>> expectedPreCallInfo = Pair.of( Tracer.getInstance().getCurrentSpanStackCopy(), MDC.getCopyOfContextMap() ); Map<String, String> expectedMdcInfo; // The expected MDC info will vary depending on combinations. if (useNullMdcInfo) { // MDC may still be populated after the call if the span stack is not empty if (useNullSpanStack) expectedMdcInfo = Collections.emptyMap(); else { // MDC will have been populated with tracing info. expectedMdcInfo = new HashMap<>(); Span expectedSpan = spanStackForLinking.peek(); expectedMdcInfo.put(SpanFieldForLoggerMdc.TRACE_ID.mdcKey, expectedSpan.getTraceId()); } } else { // Not null MDC. Start with the MDC info for linking. expectedMdcInfo = new HashMap<>(mdcInfoForLinking); if (useNullSpanStack) { // In the case of a null span stack, the trace info would be removed from the MDC. expectedMdcInfo.remove(SpanFieldForLoggerMdc.TRACE_ID.mdcKey); } } // when Pair<Deque<Span>, Map<String, String>> preCallInfo = linkTracingToCurrentThread(spanStackForLinking, mdcInfoForLinking); Pair<Deque<Span>, Map<String, String>> postCallInfo = Pair.of( Tracer.getInstance().getCurrentSpanStackCopy(), MDC.getCopyOfContextMap() ); // then assertThat(preCallInfo).isEqualTo(expectedPreCallInfo); assertThat(postCallInfo.getLeft()).isEqualTo(spanStackForLinking); if (expectedMdcInfo.isEmpty()) { assertThat(postCallInfo.getRight()).isNullOrEmpty(); } else { assertThat(postCallInfo.getRight()).isEqualTo(expectedMdcInfo); } }
Example 7
Source File: AsyncNettyHelperTest.java From riposte with Apache License 2.0 | 4 votes |
@DataProvider(value = { "true | true", "false | true", "true | false", "false | false", }, splitBy = "\\|") @Test public void unlinkTracingAndMdcFromCurrentThread_separate_args_works_as_expected(boolean useNullSpanStack, boolean useNullMdcInfo) { // given Pair<Deque<Span>, Map<String, String>> info = setupStateWithTracingAndMdcInfo(); info.getRight().put("fooMdcKey", UUID.randomUUID().toString()); Deque<Span> spanStackForLinking = (useNullSpanStack) ? null : info.getLeft(); Map<String, String> mdcInfoForLinking = (useNullMdcInfo) ? null : info.getRight(); // 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()); Map<String, String> expectedMdcInfo; // The expected MDC info will vary depending on combinations. if (useNullMdcInfo) { // MDC may still be populated after the call if the span stack is not empty if (useNullSpanStack) expectedMdcInfo = Collections.emptyMap(); else { // MDC will have been populated with tracing info. expectedMdcInfo = new HashMap<>(); Span expectedSpan = spanStackForLinking.peek(); expectedMdcInfo.put(SpanFieldForLoggerMdc.TRACE_ID.mdcKey, expectedSpan.getTraceId()); } } else { // Not null MDC. Since unlinkTracingAndMdcFromCurrentThread doesn't call registerWithThread when // the span stack is null we don't need to worry about trace ID and span JSON being removed from MDC. // Therefore it should match mdcInfoForLinking exactly. expectedMdcInfo = new HashMap<>(mdcInfoForLinking); } // when AsyncNettyHelper.unlinkTracingAndMdcFromCurrentThread(spanStackForLinking, mdcInfoForLinking); Pair<Deque<Span>, Map<String, String>> postCallInfo = Pair.of( Tracer.getInstance().getCurrentSpanStackCopy(), MDC.getCopyOfContextMap() ); // then assertThat(postCallInfo.getLeft()).isEqualTo(spanStackForLinking); assertThat(postCallInfo.getRight()).isEqualTo(expectedMdcInfo); }
Example 8
Source File: AsyncNettyHelperTest.java From riposte with Apache License 2.0 | 4 votes |
@DataProvider(value = { "true | true", "false | true", "true | false", "false | false", }, splitBy = "\\|") @Test public void linkTracingAndMdcToCurrentThread_separate_args_works_as_expected(boolean useNullSpanStack, boolean useNullMdcInfo) { // given Pair<Deque<Span>, Map<String, String>> info = setupStateWithTracingAndMdcInfo(); info.getRight().put("fooMdcKey", UUID.randomUUID().toString()); Deque<Span> spanStackForLinking = (useNullSpanStack) ? null : info.getLeft(); Map<String, String> mdcInfoForLinking = (useNullMdcInfo) ? null : info.getRight(); resetTracingAndMdc(); Tracer.getInstance().startRequestWithRootSpan("foo-" + UUID.randomUUID().toString()); Pair<Deque<Span>, Map<String, String>> expectedPreCallInfo = Pair.of( Tracer.getInstance().getCurrentSpanStackCopy(), MDC.getCopyOfContextMap() ); Map<String, String> expectedMdcInfo; // The expected MDC info will vary depending on combinations. if (useNullMdcInfo) { // MDC may still be populated after the call if the span stack is not empty if (useNullSpanStack) expectedMdcInfo = Collections.emptyMap(); else { // MDC will have been populated with tracing info. expectedMdcInfo = new HashMap<>(); Span expectedSpan = spanStackForLinking.peek(); expectedMdcInfo.put(SpanFieldForLoggerMdc.TRACE_ID.mdcKey, expectedSpan.getTraceId()); } } else { // Not null MDC. Start with the MDC info for linking. expectedMdcInfo = new HashMap<>(mdcInfoForLinking); if (useNullSpanStack) { // In the case of a null span stack, the trace info would be removed from the MDC. expectedMdcInfo.remove(SpanFieldForLoggerMdc.TRACE_ID.mdcKey); } } // when Pair<Deque<Span>, Map<String, String>> preCallInfo = AsyncNettyHelper.linkTracingAndMdcToCurrentThread(spanStackForLinking, mdcInfoForLinking); Pair<Deque<Span>, Map<String, String>> postCallInfo = Pair.of( Tracer.getInstance().getCurrentSpanStackCopy(), MDC.getCopyOfContextMap() ); // then assertThat(preCallInfo).isEqualTo(expectedPreCallInfo); assertThat(postCallInfo.getLeft()).isEqualTo(spanStackForLinking); assertThat(postCallInfo.getRight()).isEqualTo(expectedMdcInfo); }
Example 9
Source File: VerifySampleEndpointsComponentTest.java From wingtips with Apache License 2.0 | 4 votes |
private void verifyNestedCallEndpoint(boolean upstreamSendsSpan, boolean upstreamSendsUserId, String endpointPath) { Pair<Span, Map<String, String>> upstreamSpanInfo = (upstreamSendsSpan) ? generateUpstreamSpanHeaders(upstreamSendsUserId) : Pair.of((Span)null, Collections.<String, String>emptyMap()); ExtractableResponse response = given() .baseUri("http://localhost") .port(SERVER_PORT) .headers(upstreamSpanInfo.getRight()) .queryParam("foo", "bar") .log().all() .when() .get(endpointPath) .then() .log().all() .extract(); assertThat(response.statusCode()).isEqualTo(200); // The nested-*-call endpoints sleep once for the outer endpoint, and again for the span-info endpoint sub-call. // We expect 3 spans to have been completed: (1) the server span around the span-info endpoint, // (2) the client subspan around the RestTemplate/AsyncRestTemplate call, and (3) the server span around // the nested-*-call endpoint. verifyMultipleSpansCompletedAndReturnedInResponse( response, SLEEP_TIME_MILLIS * 2, 3, upstreamSpanInfo.getLeft() ); verifySpanTaggingForNestedCallEndpoint(endpointPath); EndpointSpanInfoDto resultDto = response.as(EndpointSpanInfoDto.class); if (upstreamSendsSpan) { // The span-info endpoint would have received span info generated by the nested-blocking-call endpoint, // *not* what we sent in our original call. We can still verify trace ID and user ID though, and // verify that the span-info endpoint had the correct parent/child relationship between spans. Span spanSent = upstreamSpanInfo.getLeft(); assertThat(resultDto.parent_span_info.trace_id).isEqualTo(spanSent.getTraceId()); assertThat(resultDto.parent_span_info.user_id).isEqualTo(spanSent.getUserId()); verifyParentChildRelationship(resultDto); } else { verifyParentChildRelationship(resultDto); } }
Example 10
Source File: AsyncWingtipsHelperTest.java From wingtips with Apache License 2.0 | 4 votes |
@DataProvider(value = { "true | true | true", "false | true | true", "true | false | true", "false | false | true", "true | true | false", "false | true | false", "true | false | false", "false | false | false", }, splitBy = "\\|") @Test public void unlinkTracingFromCurrentThread_separate_args_works_as_expected(boolean useNullSpanStack, boolean useNullMdcInfo, boolean useStaticMethod) { // given Pair<Deque<Span>, Map<String, String>> info = generateTracingInfo(); info.getRight().put("fooMdcKey", UUID.randomUUID().toString()); Deque<Span> spanStackForLinking = (useNullSpanStack) ? null : info.getLeft(); Map<String, String> mdcInfoForLinking = (useNullMdcInfo) ? null : info.getRight(); // Setup the current thread with something that is not ultimately what we expect so that our assertions are // verifying that the unlinkTracingFromCurrentThread method actually did something. resetTracing(); Tracer.getInstance().startRequestWithRootSpan("foo-" + UUID.randomUUID().toString()); Map<String, String> expectedMdcInfo; // The expected MDC info will vary depending on combinations. if (useNullMdcInfo) { // MDC may still be populated after the call if the span stack is not empty if (useNullSpanStack) expectedMdcInfo = Collections.emptyMap(); else { // MDC will have been populated with tracing info. expectedMdcInfo = new HashMap<>(); Span expectedSpan = spanStackForLinking.peek(); expectedMdcInfo.put(SpanFieldForLoggerMdc.TRACE_ID.mdcKey, expectedSpan.getTraceId()); } } else { // Not null MDC. Since unlinkTracingFromCurrentThread doesn't call registerWithThread when // the span stack is null we don't need to worry about trace ID being removed from MDC. // Therefore it should match mdcInfoForLinking exactly. expectedMdcInfo = new HashMap<>(mdcInfoForLinking); } // when if (useStaticMethod) { unlinkTracingFromCurrentThread(spanStackForLinking, mdcInfoForLinking); } else { DEFAULT_IMPL.unlinkTracingFromCurrentThread(spanStackForLinking, mdcInfoForLinking); } Pair<Deque<Span>, Map<String, String>> postCallInfo = Pair.of( Tracer.getInstance().getCurrentSpanStackCopy(), MDC.getCopyOfContextMap() ); // then assertThat(postCallInfo.getLeft()).isEqualTo(spanStackForLinking); if (expectedMdcInfo.isEmpty()) { assertThat(postCallInfo.getRight()).isNullOrEmpty(); } else { assertThat(postCallInfo.getRight()).isEqualTo(expectedMdcInfo); } }
Example 11
Source File: VerifySampleEndpointsComponentTest.java From wingtips with Apache License 2.0 | 4 votes |
@DataProvider(value = { "true | true", "true | false", "false | true", "false | false" }, splitBy = "\\|") @Test public void verify_nested_webclient_call_endpoint(boolean upstreamSendsSpan, boolean upstreamSendsUserId) { Pair<Span, Map<String, String>> upstreamSpanInfo = (upstreamSendsSpan) ? generateUpstreamSpanHeaders(upstreamSendsUserId) : Pair.of((Span)null, Collections.emptyMap()); ExtractableResponse response = given() .baseUri("http://localhost") .port(SERVER_PORT) .headers(upstreamSpanInfo.getRight()) .queryParam("foo", "bar") .log().all() .when() .get(NESTED_WEB_CLIENT_CALL_PATH) .then() .log().all() .extract(); assertThat(response.statusCode()).isEqualTo(200); // The nested-webclient-call endpoint sleeps once for the outer endpoint, and again for the span-info endpoint // sub-call. // We expect 3 spans to have been completed: (1) the server span around the span-info endpoint, // (2) the client subspan around the WebClient call, and (3) the server span around the // nested-webclient-call endpoint. verifyMultipleSpansCompletedAndReturnedInResponse( response, SLEEP_TIME_MILLIS * 2, 3, upstreamSpanInfo.getLeft() ); verifySpanTaggingForNestedCallEndpoint(NESTED_WEB_CLIENT_CALL_PATH); EndpointSpanInfoDto resultDto = response.as(EndpointSpanInfoDto.class); if (upstreamSendsSpan) { // The span-info endpoint would have received span info generated by the nested-webclient-call endpoint, // *not* what we sent in our original call. We can still verify trace ID and user ID though, and // verify that the span-info endpoint had the correct parent/child relationship between spans. Span spanSent = upstreamSpanInfo.getLeft(); assertThat(resultDto.parent_span_info.trace_id).isEqualTo(spanSent.getTraceId()); assertThat(resultDto.parent_span_info.user_id).isEqualTo(spanSent.getUserId()); verifyParentChildRelationship(resultDto); } else { verifyParentChildRelationship(resultDto); } }
Example 12
Source File: VerifySampleEndpointsComponentTest.java From wingtips with Apache License 2.0 | 4 votes |
private void verifyNestedCallEndpoint(boolean upstreamSendsSpan, boolean upstreamSendsUserId, String endpointPath) { Pair<Span, Map<String, String>> upstreamSpanInfo = (upstreamSendsSpan) ? generateUpstreamSpanHeaders(upstreamSendsUserId) : Pair.of((Span)null, Collections.<String, String>emptyMap()); ExtractableResponse response = given() .baseUri("http://localhost") .port(SERVER_PORT) .headers(upstreamSpanInfo.getRight()) .queryParam("foo", "bar") .log().all() .when() .get(endpointPath) .then() .log().all() .extract(); assertThat(response.statusCode()).isEqualTo(200); // The nested-*-call endpoints sleep once for the outer endpoint, and again for the span-info endpoint sub-call. // We expect 3 spans to have been completed: (1) the server span around the span-info endpoint, // (2) the client subspan around the RestTemplate/AsyncRestTemplate call, and (3) the server span around // the nested-*-call endpoint. verifyMultipleSpansCompletedAndReturnedInResponse( response, SLEEP_TIME_MILLIS * 2, 3, upstreamSpanInfo.getLeft() ); verifySpanTaggingForNestedCallEndpoint(endpointPath); EndpointSpanInfoDto resultDto = response.as(EndpointSpanInfoDto.class); if (upstreamSendsSpan) { // The span-info endpoint would have received span info generated by the nested-blocking-call endpoint, // *not* what we sent in our original call. We can still verify trace ID and user ID though, and // verify that the span-info endpoint had the correct parent/child relationship between spans. Span spanSent = upstreamSpanInfo.getLeft(); assertThat(resultDto.parent_span_info.trace_id).isEqualTo(spanSent.getTraceId()); assertThat(resultDto.parent_span_info.user_id).isEqualTo(spanSent.getUserId()); verifyParentChildRelationship(resultDto); } else { verifyParentChildRelationship(resultDto); } }
Example 13
Source File: ChannelFutureListenerWithTracingAndMdc.java From riposte with Apache License 2.0 | 3 votes |
/** * Constructor that uses the given trace and MDC information, which will be associated with the thread when the * given operation is executed. * <p/> * The operation you pass in cannot be null (an {@link IllegalArgumentException} will be thrown if you pass in null * for the operation). * <p/> * The {@link Pair} can be null, or you can pass null for the left and/or right side of the pair, and no error will * be thrown. Any trace or MDC info that is null means the corresponding info will not be available to the thread * when the operation is executed however. */ public ChannelFutureListenerWithTracingAndMdc(Consumer<ChannelFuture> postCompleteOperation, Pair<Deque<Span>, Map<String, String>> originalThreadInfo) { this( postCompleteOperation, (originalThreadInfo == null) ? null : originalThreadInfo.getLeft(), (originalThreadInfo == null) ? null : originalThreadInfo.getRight() ); }
Example 14
Source File: CallableWithTracingAndMdcSupport.java From riposte with Apache License 2.0 | 3 votes |
/** * Constructor that uses the given trace and MDC information, which will be associated with the thread when the * given operation is executed. * <p/> * The operation you pass in cannot be null (an {@link IllegalArgumentException} will be thrown if you pass in null * for the operation). * <p/> * The {@link Pair} can be null, or you can pass null for the left and/or right side of the pair, and no error will * be thrown. Any trace or MDC info that is null means the corresponding info will not be available to the thread * when the operation is executed however. */ public CallableWithTracingAndMdcSupport(Callable<U> origCallable, Pair<Deque<Span>, Map<String, String>> originalThreadInfo) { this( origCallable, (originalThreadInfo == null) ? null : originalThreadInfo.getLeft(), (originalThreadInfo == null) ? null : originalThreadInfo.getRight() ); }
Example 15
Source File: AsyncNettyHelper.java From riposte with Apache License 2.0 | 3 votes |
/** * Links the given distributed tracing and logging MDC info to the current thread. Any existing tracing and MDC info * on the current thread will be wiped out and overridden, so if you need to go back to them in the future you'll * need to store the copy info returned by this method for later. * * @param threadInfoToLink * A {@link Pair} containing the distributed trace stack and MDC info you want to link to the current thread. * This argument can be null - if it is null then {@link Tracer} will be setup with an empty trace stack (wiping * out any existing in-progress traces) *and* {@link org.slf4j.MDC#clear()} will be called (wiping out any * existing MDC info). The left and/or right portion of the pair can also be null, with any null portion of the * pair causing the corresponding portion to be emptied/cleared while letting any non-null portion link to the * thread as expected. * * @return A *COPY* of the original trace stack and MDC info on the thread when this method was called (before being * replaced with the given arguments). The {@link Pair} object will never be null, but the values it contains may be * null. A copy is returned rather than the original to prevent undesired behavior (storing the return value and * then passing it in to {@link #unlinkTracingAndMdcFromCurrentThread(Pair)} later should *guarantee* that after * calling that unlink method the thread state is exactly as it was right *before* calling this link method. If we * returned the original trace stack this contract guarantee could be violated). */ public static Pair<Deque<Span>, Map<String, String>> linkTracingAndMdcToCurrentThread( Pair<Deque<Span>, Map<String, String>> threadInfoToLink ) { Deque<Span> distributedTraceStack = (threadInfoToLink == null) ? null : threadInfoToLink.getLeft(); Map<String, String> mdcContextMap = (threadInfoToLink == null) ? null : threadInfoToLink.getRight(); return linkTracingAndMdcToCurrentThread(distributedTraceStack, mdcContextMap); }
Example 16
Source File: ListenableFutureCallbackWithTracing.java From wingtips with Apache License 2.0 | 3 votes |
/** * Constructor that uses the given trace and MDC information, which will be associated with the thread when the * given operation is executed. * * <p>The operation you pass in cannot be null (an {@link IllegalArgumentException} will be thrown if you pass in * null for the operation). * * <p>The {@link Pair} can be null, or you can pass null for the left and/or right side of the pair, and no error * will be thrown. Any trace or MDC info that is null means the corresponding info will not be available to the * thread when the operation is executed however. * * <p>You can pass in a {@link TracingState} for clearer less verbose code since it extends * {@code Pair<Deque<Span>, Map<String, String>>}. */ public ListenableFutureCallbackWithTracing(ListenableFutureCallback<T> origListenableFutureCallback, Pair<Deque<Span>, Map<String, String>> originalThreadInfo) { this( origListenableFutureCallback, (originalThreadInfo == null) ? null : originalThreadInfo.getLeft(), (originalThreadInfo == null) ? null : originalThreadInfo.getRight() ); }
Example 17
Source File: SupplierWithTracing.java From wingtips with Apache License 2.0 | 3 votes |
/** * Constructor that uses the given trace and MDC information, which will be associated with the thread when the * given operation is executed. * * <p>The operation you pass in cannot be null (an {@link IllegalArgumentException} will be thrown if you pass in * null for the operation). * * <p>The {@link Pair} can be null, or you can pass null for the left and/or right side of the pair, and no error * will be thrown. Any trace or MDC info that is null means the corresponding info will not be available to the * thread when the operation is executed however. * * <p>You can pass in a {@link TracingState} for clearer less verbose code since it extends * {@code Pair<Deque<Span>, Map<String, String>>}. */ public SupplierWithTracing(Supplier<U> origSupplier, Pair<Deque<Span>, Map<String, String>> originalThreadInfo) { this( origSupplier, (originalThreadInfo == null) ? null : originalThreadInfo.getLeft(), (originalThreadInfo == null) ? null : originalThreadInfo.getRight() ); }
Example 18
Source File: PredicateWithTracing.java From wingtips with Apache License 2.0 | 3 votes |
/** * Constructor that uses the given trace and MDC information, which will be associated with the thread when the * given operation is executed. * * <p>The operation you pass in cannot be null (an {@link IllegalArgumentException} will be thrown if you pass in * null for the operation). * * <p>The {@link Pair} can be null, or you can pass null for the left and/or right side of the pair, and no error * will be thrown. Any trace or MDC info that is null means the corresponding info will not be available to the * thread when the operation is executed however. * * <p>You can pass in a {@link TracingState} for clearer less verbose code since it extends * {@code Pair<Deque<Span>, Map<String, String>>}. */ public PredicateWithTracing(Predicate<T> origPredicate, Pair<Deque<Span>, Map<String, String>> originalThreadInfo) { this( origPredicate, (originalThreadInfo == null) ? null : originalThreadInfo.getLeft(), (originalThreadInfo == null) ? null : originalThreadInfo.getRight() ); }
Example 19
Source File: BiConsumerWithTracing.java From wingtips with Apache License 2.0 | 3 votes |
/** * Constructor that uses the given trace and MDC information, which will be associated with the thread when the * given operation is executed. * * <p>The operation you pass in cannot be null (an {@link IllegalArgumentException} will be thrown if you pass in * null for the operation). * * <p>The {@link Pair} can be null, or you can pass null for the left and/or right side of the pair, and no error * will be thrown. Any trace or MDC info that is null means the corresponding info will not be available to the * thread when the operation is executed however. * * <p>You can pass in a {@link TracingState} for clearer less verbose code since it extends * {@code Pair<Deque<Span>, Map<String, String>>}. */ public BiConsumerWithTracing(BiConsumer<T, U> origBiConsumer, Pair<Deque<Span>, Map<String, String>> originalThreadInfo) { this( origBiConsumer, (originalThreadInfo == null) ? null : originalThreadInfo.getLeft(), (originalThreadInfo == null) ? null : originalThreadInfo.getRight() ); }
Example 20
Source File: SuccessCallbackWithTracing.java From wingtips with Apache License 2.0 | 3 votes |
/** * Constructor that uses the given trace and MDC information, which will be associated with the thread when the * given operation is executed. * * <p>The operation you pass in cannot be null (an {@link IllegalArgumentException} will be thrown if you pass in * null for the operation). * * <p>The {@link Pair} can be null, or you can pass null for the left and/or right side of the pair, and no error * will be thrown. Any trace or MDC info that is null means the corresponding info will not be available to the * thread when the operation is executed however. * * <p>You can pass in a {@link TracingState} for clearer less verbose code since it extends * {@code Pair<Deque<Span>, Map<String, String>>}. */ public SuccessCallbackWithTracing(SuccessCallback<T> origSuccessCallback, Pair<Deque<Span>, Map<String, String>> originalThreadInfo) { this( origSuccessCallback, (originalThreadInfo == null) ? null : originalThreadInfo.getLeft(), (originalThreadInfo == null) ? null : originalThreadInfo.getRight() ); }