From c9b47b6b8c0addc799eab95d9fe4202f57b2bab0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Carlos=20Ch=C3=A1vez?= Date: Thu, 30 Jun 2022 10:17:41 +0200 Subject: [PATCH 1/2] chore: test to prove #1306 --- brave/src/test/java/brave/TracerTest.java | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/brave/src/test/java/brave/TracerTest.java b/brave/src/test/java/brave/TracerTest.java index 1a9dd78b81..098a0359c8 100644 --- a/brave/src/test/java/brave/TracerTest.java +++ b/brave/src/test/java/brave/TracerTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2020 The OpenZipkin Authors + * Copyright 2013-2022 The OpenZipkin Authors * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at @@ -37,9 +37,12 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.concurrent.ExecutionException; import java.util.function.Function; import org.junit.After; import org.junit.Test; +import org.mockito.Mockito; + import zipkin2.Endpoint; import zipkin2.reporter.Reporter; @@ -226,6 +229,7 @@ public class TracerTest { @Test public void join_createsChildWhenUnsupportedByPropagation() { tracer = Tracing.newBuilder() .propagationFactory(new Propagation.Factory() { + @Override @Deprecated public Propagation create(Propagation.KeyFactory keyFactory) { return B3Propagation.FACTORY.create(keyFactory); } @@ -1092,6 +1096,22 @@ private static void simulateInProcessPropagation(Tracer tracer1, Tracer tracer2) assertThat(toSpan.extra()).isNotEmpty(); } + @Test public void toSpan_flushedAfterFetch() throws InterruptedException, ExecutionException { + propagationFactory = baggageFactory; + TraceContext parent = TraceContext.newBuilder().traceId(1L).spanId(2L).sampled(true).build(); + TraceContext incoming = TraceContext.newBuilder().traceId(1L).spanId(3L).parentId(2L).sampled(true).build(); + + tracer.pendingSpans.getOrCreate(parent, incoming, false); + Tracer spiedTracer = Mockito.spy(tracer); + Mockito.doAnswer(i -> { + //Simulate a concurrent call flushing the span at the beginning of this method's execution + tracer.pendingSpans.flush(incoming); + return i.callRealMethod(); + }).when(spiedTracer)._toSpan(Mockito.any(TraceContext.class), Mockito.any(TraceContext.class)); + + spiedTracer.toSpan(incoming); + } + @Test public void currentSpan_sameContextReference() { Span span = tracer.newTrace(); try (SpanInScope ws = tracer.withSpanInScope(span)) { From 3654d56c27361699a7a6cad6558dc72d88c06faa Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Fri, 15 Dec 2023 19:00:08 +0700 Subject: [PATCH 2/2] license Signed-off-by: Adrian Cole --- brave/src/main/java/brave/baggage/BaggagePropagationConfig.java | 2 +- brave/src/main/java/brave/handler/SpanHandler.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/brave/src/main/java/brave/baggage/BaggagePropagationConfig.java b/brave/src/main/java/brave/baggage/BaggagePropagationConfig.java index 7ec562a2da..81b6ec0433 100644 --- a/brave/src/main/java/brave/baggage/BaggagePropagationConfig.java +++ b/brave/src/main/java/brave/baggage/BaggagePropagationConfig.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2020 The OpenZipkin Authors + * Copyright 2013-2023 The OpenZipkin Authors * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at diff --git a/brave/src/main/java/brave/handler/SpanHandler.java b/brave/src/main/java/brave/handler/SpanHandler.java index 3e00db681f..01b21edf90 100644 --- a/brave/src/main/java/brave/handler/SpanHandler.java +++ b/brave/src/main/java/brave/handler/SpanHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2020 The OpenZipkin Authors + * Copyright 2013-2023 The OpenZipkin Authors * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at