Skip to content

Commit

Permalink
more
Browse files Browse the repository at this point in the history
Signed-off-by: Adrian Cole <[email protected]>
  • Loading branch information
Adrian Cole committed Dec 16, 2023
1 parent ee745cb commit 4f619fe
Show file tree
Hide file tree
Showing 27 changed files with 267 additions and 123 deletions.
2 changes: 0 additions & 2 deletions brave/src/main/java/brave/baggage/BaggagePropagation.java
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,6 @@ public static List<String> allKeyNames(Propagation<String> propagation) {
return Collections.unmodifiableList(result);
}

// Not lambda as Retrolambda creates an OSGi dependency on jdk.internal.vm.annotation with JDK 14
// See https://github.com/luontola/retrolambda/issues/160
enum NoopGetter implements Getter<Boolean, String> {
INSTANCE;

Expand Down
4 changes: 2 additions & 2 deletions brave/src/main/java/brave/propagation/Propagation.java
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -130,7 +130,7 @@ public TraceContext decorate(TraceContext context) {
*/
@Deprecated
interface KeyFactory<K> {
KeyFactory<String> STRING = new KeyFactory<String>() { // retrolambda no likey
KeyFactory<String> STRING = new KeyFactory<String>() {
@Override public String create(String name) {
return name;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2019 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 @@ -40,7 +40,7 @@ final class TraceContextCompletableObserver implements CompletableObserver, Disp

@Override public void onError(Throwable t) {
Scope scope = contextScoper.maybeScope(assembled);
try { // retrolambda can't resolve this try/finally
try {
downstream.onError(t);
} finally {
scope.close();
Expand All @@ -49,7 +49,7 @@ final class TraceContextCompletableObserver implements CompletableObserver, Disp

@Override public void onComplete() {
Scope scope = contextScoper.maybeScope(assembled);
try { // retrolambda can't resolve this try/finally
try {
downstream.onComplete();
} finally {
scope.close();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2019 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 @@ -43,7 +43,7 @@ final class TraceContextConnectableFlowable<T> extends ConnectableFlowable<T> {

@Override public void connect(Consumer<? super Disposable> connection) {
Scope scope = contextScoper.maybeScope(assembled);
try { // retrolambda can't resolve this try/finally
try {
source.connect(connection);
} finally {
scope.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ final class TraceContextConnectableObservable<T> extends ConnectableObservable<T

@Override public void connect(Consumer<? super Disposable> connection) {
Scope scope = contextScoper.maybeScope(assembled);
try { // retrolambda can't resolve this try/finally
try {
source.connect(connection);
} finally {
scope.close();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2019 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 @@ -43,7 +43,7 @@ final class TraceContextMaybeObserver<T> implements MaybeObserver<T>, Disposable

@Override public void onError(Throwable t) {
Scope scope = contextScoper.maybeScope(assembled);
try { // retrolambda can't resolve this try/finally
try {
downstream.onError(t);
} finally {
scope.close();
Expand All @@ -52,7 +52,7 @@ final class TraceContextMaybeObserver<T> implements MaybeObserver<T>, Disposable

@Override public void onSuccess(T value) {
Scope scope = contextScoper.maybeScope(assembled);
try { // retrolambda can't resolve this try/finally
try {
downstream.onSuccess(value);
} finally {
scope.close();
Expand All @@ -61,7 +61,7 @@ final class TraceContextMaybeObserver<T> implements MaybeObserver<T>, Disposable

@Override public void onComplete() {
Scope scope = contextScoper.maybeScope(assembled);
try { // retrolambda can't resolve this try/finally
try {
downstream.onComplete();
} finally {
scope.close();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2019 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 @@ -45,7 +45,7 @@ final class TraceContextObserver<T> implements Observer<T>, Disposable {

@Override public void onNext(T t) {
Scope scope = contextScoper.maybeScope(assembled);
try { // retrolambda can't resolve this try/finally
try {
downstream.onNext(t);
} finally {
scope.close();
Expand All @@ -60,7 +60,7 @@ final class TraceContextObserver<T> implements Observer<T>, Disposable {
done = true;

Scope scope = contextScoper.maybeScope(assembled);
try { // retrolambda can't resolve this try/finally
try {
downstream.onError(t);
} finally {
scope.close();
Expand All @@ -72,7 +72,7 @@ final class TraceContextObserver<T> implements Observer<T>, Disposable {
done = true;

Scope scope = contextScoper.maybeScope(assembled);
try { // retrolambda can't resolve this try/finally
try {
downstream.onComplete();
} finally {
scope.close();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2019 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 @@ -43,7 +43,7 @@ final class TraceContextSingleObserver<T> implements SingleObserver<T>, Disposab

@Override public void onError(Throwable t) {
Scope scope = contextScoper.maybeScope(assembled);
try { // retrolambda can't resolve this try/finally
try {
downstream.onError(t);
} finally {
scope.close();
Expand All @@ -52,7 +52,7 @@ final class TraceContextSingleObserver<T> implements SingleObserver<T>, Disposab

@Override public void onSuccess(T value) {
Scope scope = contextScoper.maybeScope(assembled);
try { // retrolambda can't resolve this try/finally
try {
downstream.onSuccess(value);
} finally {
scope.close();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2019 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 @@ -46,7 +46,7 @@ class TraceContextSubscriber<T> implements Subscriber<T> {

@Override public void onNext(T t) {
Scope scope = contextScoper.maybeScope(assembled);
try { // retrolambda can't resolve this try/finally
try {
downstream.onNext(t);
} finally {
scope.close();
Expand All @@ -61,7 +61,7 @@ class TraceContextSubscriber<T> implements Subscriber<T> {
done = true;

Scope scope = contextScoper.maybeScope(assembled);
try { // retrolambda can't resolve this try/finally
try {
downstream.onError(t);
} finally {
scope.close();
Expand All @@ -73,7 +73,7 @@ class TraceContextSubscriber<T> implements Subscriber<T> {
done = true;

Scope scope = contextScoper.maybeScope(assembled);
try { // retrolambda can't resolve this try/finally
try {
downstream.onComplete();
} finally {
scope.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ static final class DelegateAndFinishSpan extends TracingResponseCallback {
try {
delegate.done(response);
} finally {
ws.close();
super.done(response);
ws.close();
}
}

Expand All @@ -74,8 +74,8 @@ static final class DelegateAndFinishSpan extends TracingResponseCallback {
try {
delegate.caught(exception);
} finally {
ws.close();
super.caught(exception);
ws.close();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ final class TracingProtocolExec implements ClientExecChain {
} catch (RuntimeException e) {
error = e;
throw e;
} catch (HttpException e) {
error = e;
throw e;
} catch (IOException e) {
error = e;
throw e;
} catch (Error e) {
propagateIfFatal(e);
error = e;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public JmsTracing build() {
this.producerSampler = builder.messagingTracing.producerSampler();
this.consumerSampler = builder.messagingTracing.consumerSampler();
this.remoteServiceName = builder.remoteServiceName;
this.traceIdProperties = new LinkedHashSet<>(propagation.keys());
this.traceIdProperties = new LinkedHashSet<String>(propagation.keys());
}

public Connection connection(Connection connection) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2019 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 @@ -86,13 +86,14 @@ static void filterProperties(Message message, Set<String> namesToClear, List<Obj
}
}

static final ThreadLocal<ArrayList<Object>> MESSAGE_PROPERTIES_BUFFER = new ThreadLocal<>();
static final ThreadLocal<ArrayList<Object>> MESSAGE_PROPERTIES_BUFFER =
new ThreadLocal<ArrayList<Object>>();

/** Also use pair indexing for temporary message properties: (name, value). */
static ArrayList<Object> messagePropertiesBuffer() {
ArrayList<Object> messagePropertiesBuffer = MESSAGE_PROPERTIES_BUFFER.get();
if (messagePropertiesBuffer == null) {
messagePropertiesBuffer = new ArrayList<>();
messagePropertiesBuffer = new ArrayList<Object>();
MESSAGE_PROPERTIES_BUFFER.set(messagePropertiesBuffer);
}
return messagePropertiesBuffer;
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -45,23 +45,27 @@ static CompletionListener create(CompletionListener delegate,
}

@Override public void onCompletion(Message message) {
try (Scope ws = current.maybeScope(span.context())) {
Scope ws = current.maybeScope(span.context());
try {
delegate.onCompletion(message);
} finally {
// TODO: in order to tag messageId
// parse(new MessageConsumerRequest(message, destination))
span.finish();
ws.close();
}
}

@Override public void onException(Message message, Exception exception) {
try (Scope ws = current.maybeScope(span.context())) {
Scope ws = current.maybeScope(span.context());
try {
// TODO: in order to tag messageId
// parse(new MessageConsumerRequest(message, destination))
delegate.onException(message, exception);
} finally {
span.error(exception);
span.finish();
ws.close();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2019 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 @@ -57,10 +57,12 @@ static final class DelegateAndTagError extends TagError {
delegate.onException(exception);
return;
}
try (SpanInScope ws = tracer.withSpanInScope(span)) {
SpanInScope ws = tracer.withSpanInScope(span);
try {
delegate.onException(exception);
} finally {
span.error(exception);
ws.close();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -107,10 +107,13 @@ void send(Send send, Destination destination, Object message) {
Throwable error = null;
try {
send.apply(delegate, destination, message);
} catch (Throwable t) {
propagateIfFatal(t);
error = t;
throw t;
} catch (RuntimeException e) {
error = e;
throw e;
} catch (Error e) {
propagateIfFatal(e);
error = e;
throw e;
} finally {
if (error != null) {
span.error(error).finish(); // An error can happen regardless of async.
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -74,10 +74,13 @@ static MessageListener create(MessageListener delegate, JmsTracing jmsTracing) {
Throwable error = null;
try {
delegate.onMessage(message);
} catch (Throwable t) {
propagateIfFatal(t);
error = t;
throw t;
} catch (RuntimeException e) {
error = e;
throw e;
} catch (Error e) {
propagateIfFatal(e);
error = e;
throw e;
} finally {
if (error != null) listenerSpan.error(error);
listenerSpan.finish();
Expand Down
Loading

0 comments on commit 4f619fe

Please sign in to comment.