Skip to content

Commit

Permalink
Temporarily revert brave 6 change
Browse files Browse the repository at this point in the history
This reverts commit 44e4081
temporarily for a 5.18.1 release.
  • Loading branch information
Adrian Cole committed Jan 8, 2024
1 parent f99265d commit 5c977a2
Show file tree
Hide file tree
Showing 349 changed files with 19,171 additions and 641 deletions.
36 changes: 36 additions & 0 deletions brave-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<main.basedir>${project.basedir}/..</main.basedir>

<!-- use the same values in ../pom.xml -->
<zipkin.version>2.27.0</zipkin.version>
<zipkin-reporter.version>3.0.0</zipkin-reporter.version>
</properties>

<organization>
Expand Down Expand Up @@ -81,6 +85,18 @@

<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.zipkin.reporter2</groupId>
<artifactId>zipkin-reporter-bom</artifactId>
<version>${zipkin-reporter.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>io.zipkin.zipkin2</groupId>
<artifactId>zipkin</artifactId>
<version>${zipkin.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>brave</artifactId>
Expand Down Expand Up @@ -111,6 +127,11 @@
<artifactId>brave-context-slf4j</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>brave-context-rxjava2</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>brave-instrumentation-benchmarks</artifactId>
Expand All @@ -121,6 +142,11 @@
<artifactId>brave-instrumentation-dubbo</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>brave-instrumentation-dubbo-rpc</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>brave-instrumentation-grpc</artifactId>
Expand Down Expand Up @@ -226,6 +252,11 @@
<artifactId>brave-instrumentation-okhttp3</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>brave-instrumentation-p6spy</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>brave-instrumentation-rpc</artifactId>
Expand All @@ -241,6 +272,11 @@
<artifactId>brave-instrumentation-servlet-jakarta</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>brave-instrumentation-sparkjava</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>brave-instrumentation-spring-rabbit</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2024 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
Expand Down Expand Up @@ -311,7 +311,7 @@ protected void is_inheritable(CurrentTraceContext inheritableCurrentTraceContext
}

@Test void restoresSpanAfterCallable() throws Exception {
try (Scope scope = currentTraceContext.newScope(context)) {
try (Scope scope0 = currentTraceContext.newScope(context)) {
attachesSpanInCallable();
assertThat(currentTraceContext.get())
.isEqualTo(context);
Expand Down Expand Up @@ -341,7 +341,7 @@ protected void is_inheritable(CurrentTraceContext inheritableCurrentTraceContext
@Test void restoresSpanAfterRunnable() throws Exception {
TraceContext context0 = TraceContext.newBuilder().traceId(3L).spanId(3L).build();

try (Scope scope = currentTraceContext.newScope(context0)) {
try (Scope scope0 = currentTraceContext.newScope(context0)) {
attachesSpanInRunnable();
assertThat(currentTraceContext.get())
.isEqualTo(context0);
Expand All @@ -366,7 +366,7 @@ static class Unused extends ClassLoaders.ConsumerRunnable<CurrentTraceContext.Bu
static class ClosedScope extends ClassLoaders.ConsumerRunnable<CurrentTraceContext.Builder> {
@Override public void accept(CurrentTraceContext.Builder builder) {
CurrentTraceContext current = builder.build();
try (Scope scope = current.newScope(TraceContext.newBuilder().traceId(1L).spanId(2L).build())) {
try (Scope ws = current.newScope(TraceContext.newBuilder().traceId(1L).spanId(2L).build())) {
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2024 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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2024 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
Expand All @@ -13,8 +13,8 @@
*/
package brave.test.propagation;

import brave.internal.Nullable;
import brave.internal.codec.HexCodec;
import brave.internal.Nullable;
import brave.propagation.Propagation;
import brave.propagation.Propagation.Getter;
import brave.propagation.Propagation.Setter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2024 The OpenZipkin Authors
* Copyright 2013-2020 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
Expand All @@ -18,6 +18,8 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.BiConsumer;
import org.assertj.core.api.AbstractThrowableAssert;
import org.assertj.core.api.ObjectAssert;

import static org.assertj.core.api.Assertions.assertThat;

Expand Down Expand Up @@ -102,6 +104,31 @@ public void onError(Throwable throwable) {
throw new AssertionError("unexpected state");
}

// TODO: not actually used as we don't need to verify http status code or otherwise yet
public ObjectAssert<V> assertThatSuccess() {
return assertThat(join());
}

// TODO: not actually used as we have no async error tests, yet
public AbstractThrowableAssert<?, ? extends Throwable> assertThatError() {
awaitUninterruptably();

if (onErrorCount.get() > 0) {
assertThat(onErrorCount)
.withFailMessage("onError signaled multiple times")
.hasValueLessThan(2);

assertThat(onSuccessCount)
.withFailMessage("Both onSuccess and onError were signaled")
.hasValue(0);

return assertThat(result == NULL_SENTINEL ? null : (Throwable) result);
} else if (onSuccessCount.get() > 0) {
throw new AssertionError("expected onError, but received onSuccess(" + result + ")");
}
throw new AssertionError(); // unexpected as we only have two callbacks to handle!
}

void awaitUninterruptably() {
try {
await(3, TimeUnit.SECONDS);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2024 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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package brave.propagation;

import brave.internal.Nullable;
import brave.test.propagation.PropagationTest;
import java.util.Map;
import java.util.function.Supplier;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;

class B3SinglePropagationTest extends PropagationTest {
@Override protected Class<? extends Supplier<Propagation<String>>> propagationSupplier() {
return PropagationSupplier.class;
}

static class PropagationSupplier implements Supplier<Propagation<String>> {
@Override public Propagation<String> get() {
return Propagation.B3_SINGLE_STRING;
}
}

@Override protected void inject(Map<String, String> map, @Nullable String traceId,
@Nullable String parentId, @Nullable String spanId, @Nullable Boolean sampled,
@Nullable Boolean debug) {
StringBuilder builder = new StringBuilder();
char sampledChar = sampledChar(sampled, debug);
if (traceId == null) {
if (sampledChar != 0) builder.append(sampledChar);
} else {
builder.append(traceId).append('-').append(spanId);
if (sampledChar != 0) builder.append('-').append(sampledChar);
if (parentId != null) builder.append('-').append(parentId);
}
if (builder.length() != 0) map.put("b3", builder.toString());
}

/** returns 0 if there's no sampling status */
static char sampledChar(@Nullable Boolean sampled, @Nullable Boolean debug) {
if (Boolean.TRUE.equals(debug)) return 'd';
if (sampled != null) return sampled ? '1' : '0';
return 0;
}

@Override protected void inject(Map<String, String> request, SamplingFlags flags) {
char sampledChar = sampledChar(flags.sampled(), flags.debug());
if (sampledChar != 0) request.put("b3", String.valueOf(sampledChar));
}

@Test void extractTraceContext_sampledFalse() {
MapEntry mapEntry = new MapEntry();
map.put("b3", "0");

SamplingFlags result = propagation.extractor(mapEntry).extract(map).samplingFlags();

assertThat(result)
.isEqualTo(SamplingFlags.NOT_SAMPLED);
}

@Test void extractTraceContext_malformed() {
MapEntry mapEntry = new MapEntry();
map.put("b3", "not-a-tumor");

SamplingFlags result = propagation.extractor(mapEntry).extract(map).samplingFlags();

assertThat(result)
.isEqualTo(SamplingFlags.EMPTY);
}

@Test void extractTraceContext_malformed_uuid() {
MapEntry mapEntry = new MapEntry();
map.put("b3", "b970dafd-0d95-40aa-95d8-1d8725aebe40");

SamplingFlags result = propagation.extractor(mapEntry).extract(map).samplingFlags();

assertThat(result)
.isEqualTo(SamplingFlags.EMPTY);
}

@Test void extractTraceContext_debug_with_ids() {
MapEntry mapEntry = new MapEntry();

map.put("b3", "4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-d");

TraceContext result = propagation.extractor(mapEntry).extract(map).context();

assertThat(result.debug())
.isTrue();
}
}
6 changes: 3 additions & 3 deletions brave/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ When you need more features, or finer control, use the `Span` type:
// Start a new trace or a span within an existing trace representing an operation
Span span = tracer.nextSpan().name("encode").start();
// Put the span in "scope" so that downstream code such as loggers can see trace IDs
try (SpanInScope scope = tracer.withSpanInScope(span)) {
try (SpanInScope ws = tracer.withSpanInScope(span)) {
return encoder.encode();
} catch (RuntimeException | Error e) {
span.error(e); // Unless you handle exceptions, you might not know the operation failed!
Expand Down Expand Up @@ -192,7 +192,7 @@ tracing.propagation().injector(ClientRequestWrapper::addHeader)
span.kind(request.spanKind());
span.name("Report");
span.start();
try (Scope scope = currentTraceContext.newScope(span.context())) { // 2.
try (Scope ws = currentTraceContext.newScope(span.context())) { // 2.
return invoke(request); // 3.
} catch (Throwable e) {
span.error(error); // 4.
Expand Down Expand Up @@ -721,7 +721,7 @@ external code might be invoked (such as proceeding an interceptor or
otherwise), place the span in scope like this.

```java
try (SpanInScope scope = tracer.withSpanInScope(span)) {
try (SpanInScope ws = tracer.withSpanInScope(span)) {
return inboundRequest.invoke();
} catch (RuntimeException | Error e) {
span.error(e);
Expand Down
19 changes: 19 additions & 0 deletions brave/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@
</properties>

<dependencies>
<!-- Intentionally pinned so that we can move off Tracing.Builder.spanReporter
Once zipkin-reporter-brave is out a while, we can un-pin it. -->
<dependency>
<groupId>io.zipkin.reporter2</groupId>
<artifactId>zipkin-reporter-brave</artifactId>
<version>${zipkin-reporter.version}</version>
</dependency>
<dependency>
<groupId>io.zipkin.zipkin2</groupId>
<artifactId>zipkin</artifactId>
<version>${zipkin.version}</version>
</dependency>

<!-- To show off SpanHandler -->
<dependency>
<groupId>org.junit.jupiter</groupId>
Expand Down Expand Up @@ -98,6 +111,12 @@
<version>${spring5.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.zipkin.reporter2</groupId>
<artifactId>zipkin-sender-okhttp3</artifactId>
<version>${zipkin-reporter.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
Loading

0 comments on commit 5c977a2

Please sign in to comment.