diff --git a/brave/src/main/java/brave/baggage/BaggagePropagation.java b/brave/src/main/java/brave/baggage/BaggagePropagation.java index 3b4554f3bf..5c7d990977 100644 --- a/brave/src/main/java/brave/baggage/BaggagePropagation.java +++ b/brave/src/main/java/brave/baggage/BaggagePropagation.java @@ -286,8 +286,6 @@ public static List allKeyNames(Propagation 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 { INSTANCE; diff --git a/brave/src/main/java/brave/propagation/Propagation.java b/brave/src/main/java/brave/propagation/Propagation.java index c770a0798b..5cc76041ae 100644 --- a/brave/src/main/java/brave/propagation/Propagation.java +++ b/brave/src/main/java/brave/propagation/Propagation.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 @@ -130,7 +130,7 @@ public TraceContext decorate(TraceContext context) { */ @Deprecated interface KeyFactory { - KeyFactory STRING = new KeyFactory() { // retrolambda no likey + KeyFactory STRING = new KeyFactory() { @Override public String create(String name) { return name; } diff --git a/context/rxjava2/src/main/java/brave/context/rxjava2/internal/TraceContextCompletableObserver.java b/context/rxjava2/src/main/java/brave/context/rxjava2/internal/TraceContextCompletableObserver.java index 9be59d061a..ce8a550918 100644 --- a/context/rxjava2/src/main/java/brave/context/rxjava2/internal/TraceContextCompletableObserver.java +++ b/context/rxjava2/src/main/java/brave/context/rxjava2/internal/TraceContextCompletableObserver.java @@ -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 @@ -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(); @@ -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(); diff --git a/context/rxjava2/src/main/java/brave/context/rxjava2/internal/TraceContextConnectableFlowable.java b/context/rxjava2/src/main/java/brave/context/rxjava2/internal/TraceContextConnectableFlowable.java index cdba236ce4..e92268f3f2 100644 --- a/context/rxjava2/src/main/java/brave/context/rxjava2/internal/TraceContextConnectableFlowable.java +++ b/context/rxjava2/src/main/java/brave/context/rxjava2/internal/TraceContextConnectableFlowable.java @@ -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 @@ -43,7 +43,7 @@ final class TraceContextConnectableFlowable extends ConnectableFlowable { @Override public void connect(Consumer connection) { Scope scope = contextScoper.maybeScope(assembled); - try { // retrolambda can't resolve this try/finally + try { source.connect(connection); } finally { scope.close(); diff --git a/context/rxjava2/src/main/java/brave/context/rxjava2/internal/TraceContextConnectableObservable.java b/context/rxjava2/src/main/java/brave/context/rxjava2/internal/TraceContextConnectableObservable.java index 45ffbadeed..eaddfd461a 100644 --- a/context/rxjava2/src/main/java/brave/context/rxjava2/internal/TraceContextConnectableObservable.java +++ b/context/rxjava2/src/main/java/brave/context/rxjava2/internal/TraceContextConnectableObservable.java @@ -43,7 +43,7 @@ final class TraceContextConnectableObservable extends ConnectableObservable connection) { Scope scope = contextScoper.maybeScope(assembled); - try { // retrolambda can't resolve this try/finally + try { source.connect(connection); } finally { scope.close(); diff --git a/context/rxjava2/src/main/java/brave/context/rxjava2/internal/TraceContextMaybeObserver.java b/context/rxjava2/src/main/java/brave/context/rxjava2/internal/TraceContextMaybeObserver.java index e1d93de8b1..6cee2ebd23 100644 --- a/context/rxjava2/src/main/java/brave/context/rxjava2/internal/TraceContextMaybeObserver.java +++ b/context/rxjava2/src/main/java/brave/context/rxjava2/internal/TraceContextMaybeObserver.java @@ -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 @@ -43,7 +43,7 @@ final class TraceContextMaybeObserver implements MaybeObserver, 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(); @@ -52,7 +52,7 @@ final class TraceContextMaybeObserver implements MaybeObserver, 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(); @@ -61,7 +61,7 @@ final class TraceContextMaybeObserver implements MaybeObserver, Disposable @Override public void onComplete() { Scope scope = contextScoper.maybeScope(assembled); - try { // retrolambda can't resolve this try/finally + try { downstream.onComplete(); } finally { scope.close(); diff --git a/context/rxjava2/src/main/java/brave/context/rxjava2/internal/TraceContextObserver.java b/context/rxjava2/src/main/java/brave/context/rxjava2/internal/TraceContextObserver.java index bdf13e6def..3c45feab08 100644 --- a/context/rxjava2/src/main/java/brave/context/rxjava2/internal/TraceContextObserver.java +++ b/context/rxjava2/src/main/java/brave/context/rxjava2/internal/TraceContextObserver.java @@ -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 @@ -45,7 +45,7 @@ final class TraceContextObserver implements Observer, 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(); @@ -60,7 +60,7 @@ final class TraceContextObserver implements Observer, Disposable { done = true; Scope scope = contextScoper.maybeScope(assembled); - try { // retrolambda can't resolve this try/finally + try { downstream.onError(t); } finally { scope.close(); @@ -72,7 +72,7 @@ final class TraceContextObserver implements Observer, Disposable { done = true; Scope scope = contextScoper.maybeScope(assembled); - try { // retrolambda can't resolve this try/finally + try { downstream.onComplete(); } finally { scope.close(); diff --git a/context/rxjava2/src/main/java/brave/context/rxjava2/internal/TraceContextSingleObserver.java b/context/rxjava2/src/main/java/brave/context/rxjava2/internal/TraceContextSingleObserver.java index 616a536b39..d06eb9e4d8 100644 --- a/context/rxjava2/src/main/java/brave/context/rxjava2/internal/TraceContextSingleObserver.java +++ b/context/rxjava2/src/main/java/brave/context/rxjava2/internal/TraceContextSingleObserver.java @@ -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 @@ -43,7 +43,7 @@ final class TraceContextSingleObserver implements SingleObserver, 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(); @@ -52,7 +52,7 @@ final class TraceContextSingleObserver implements SingleObserver, 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(); diff --git a/context/rxjava2/src/main/java/brave/context/rxjava2/internal/TraceContextSubscriber.java b/context/rxjava2/src/main/java/brave/context/rxjava2/internal/TraceContextSubscriber.java index 934e36f40d..721503f372 100644 --- a/context/rxjava2/src/main/java/brave/context/rxjava2/internal/TraceContextSubscriber.java +++ b/context/rxjava2/src/main/java/brave/context/rxjava2/internal/TraceContextSubscriber.java @@ -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 @@ -46,7 +46,7 @@ class TraceContextSubscriber implements Subscriber { @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(); @@ -61,7 +61,7 @@ class TraceContextSubscriber implements Subscriber { done = true; Scope scope = contextScoper.maybeScope(assembled); - try { // retrolambda can't resolve this try/finally + try { downstream.onError(t); } finally { scope.close(); @@ -73,7 +73,7 @@ class TraceContextSubscriber implements Subscriber { done = true; Scope scope = contextScoper.maybeScope(assembled); - try { // retrolambda can't resolve this try/finally + try { downstream.onComplete(); } finally { scope.close(); diff --git a/instrumentation/dubbo-rpc/src/main/java/brave/dubbo/rpc/TracingResponseCallback.java b/instrumentation/dubbo-rpc/src/main/java/brave/dubbo/rpc/TracingResponseCallback.java index 9b35adb5bf..4363b679c4 100644 --- a/instrumentation/dubbo-rpc/src/main/java/brave/dubbo/rpc/TracingResponseCallback.java +++ b/instrumentation/dubbo-rpc/src/main/java/brave/dubbo/rpc/TracingResponseCallback.java @@ -64,8 +64,8 @@ static final class DelegateAndFinishSpan extends TracingResponseCallback { try { delegate.done(response); } finally { - ws.close(); super.done(response); + ws.close(); } } @@ -74,8 +74,8 @@ static final class DelegateAndFinishSpan extends TracingResponseCallback { try { delegate.caught(exception); } finally { - ws.close(); super.caught(exception); + ws.close(); } } } diff --git a/instrumentation/httpclient/src/main/java/brave/httpclient/TracingProtocolExec.java b/instrumentation/httpclient/src/main/java/brave/httpclient/TracingProtocolExec.java index a275b66b82..0fefa5834c 100644 --- a/instrumentation/httpclient/src/main/java/brave/httpclient/TracingProtocolExec.java +++ b/instrumentation/httpclient/src/main/java/brave/httpclient/TracingProtocolExec.java @@ -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; diff --git a/instrumentation/jms/src/main/java/brave/jms/JmsTracing.java b/instrumentation/jms/src/main/java/brave/jms/JmsTracing.java index 13ac3d43ee..ad62b0edfa 100644 --- a/instrumentation/jms/src/main/java/brave/jms/JmsTracing.java +++ b/instrumentation/jms/src/main/java/brave/jms/JmsTracing.java @@ -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(propagation.keys()); } public Connection connection(Connection connection) { diff --git a/instrumentation/jms/src/main/java/brave/jms/PropertyFilter.java b/instrumentation/jms/src/main/java/brave/jms/PropertyFilter.java index 87c4001ded..3666385171 100644 --- a/instrumentation/jms/src/main/java/brave/jms/PropertyFilter.java +++ b/instrumentation/jms/src/main/java/brave/jms/PropertyFilter.java @@ -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 @@ -86,13 +86,14 @@ static void filterProperties(Message message, Set namesToClear, List> MESSAGE_PROPERTIES_BUFFER = new ThreadLocal<>(); + static final ThreadLocal> MESSAGE_PROPERTIES_BUFFER = + new ThreadLocal>(); /** Also use pair indexing for temporary message properties: (name, value). */ static ArrayList messagePropertiesBuffer() { ArrayList messagePropertiesBuffer = MESSAGE_PROPERTIES_BUFFER.get(); if (messagePropertiesBuffer == null) { - messagePropertiesBuffer = new ArrayList<>(); + messagePropertiesBuffer = new ArrayList(); MESSAGE_PROPERTIES_BUFFER.set(messagePropertiesBuffer); } return messagePropertiesBuffer; diff --git a/instrumentation/jms/src/main/java/brave/jms/TracingCompletionListener.java b/instrumentation/jms/src/main/java/brave/jms/TracingCompletionListener.java index c4e565d8cf..fc84d068d8 100644 --- a/instrumentation/jms/src/main/java/brave/jms/TracingCompletionListener.java +++ b/instrumentation/jms/src/main/java/brave/jms/TracingCompletionListener.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 @@ -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(); } } } diff --git a/instrumentation/jms/src/main/java/brave/jms/TracingExceptionListener.java b/instrumentation/jms/src/main/java/brave/jms/TracingExceptionListener.java index bd6f22c87e..cd57a71ca0 100644 --- a/instrumentation/jms/src/main/java/brave/jms/TracingExceptionListener.java +++ b/instrumentation/jms/src/main/java/brave/jms/TracingExceptionListener.java @@ -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 @@ -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(); } } } diff --git a/instrumentation/jms/src/main/java/brave/jms/TracingJMSProducer.java b/instrumentation/jms/src/main/java/brave/jms/TracingJMSProducer.java index 4f5210b0fc..53d30d00e0 100644 --- a/instrumentation/jms/src/main/java/brave/jms/TracingJMSProducer.java +++ b/instrumentation/jms/src/main/java/brave/jms/TracingJMSProducer.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 @@ -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. diff --git a/instrumentation/jms/src/main/java/brave/jms/TracingMessageListener.java b/instrumentation/jms/src/main/java/brave/jms/TracingMessageListener.java index e02c531d33..7c68f20312 100644 --- a/instrumentation/jms/src/main/java/brave/jms/TracingMessageListener.java +++ b/instrumentation/jms/src/main/java/brave/jms/TracingMessageListener.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 @@ -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(); diff --git a/instrumentation/jms/src/main/java/brave/jms/TracingMessageProducer.java b/instrumentation/jms/src/main/java/brave/jms/TracingMessageProducer.java index d46ca52516..895fd41ba1 100644 --- a/instrumentation/jms/src/main/java/brave/jms/TracingMessageProducer.java +++ b/instrumentation/jms/src/main/java/brave/jms/TracingMessageProducer.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 @@ -120,10 +120,16 @@ Span createAndStartProducerSpan(Message message, Destination destination) { Throwable error = null; try { delegate.send(message); - } catch (Throwable t) { - propagateIfFatal(t); - error = t; - throw t; + } catch (RuntimeException e) { + error = e; + throw e; + } catch (JMSException e) { + error = e; + throw e; + } catch (Error e) { + propagateIfFatal(e); + error = e; + throw e; } finally { if (error != null) span.error(error); span.finish(); @@ -138,10 +144,16 @@ Span createAndStartProducerSpan(Message message, Destination destination) { Throwable error = null; try { delegate.send(message, deliveryMode, priority, timeToLive); - } catch (Throwable t) { - propagateIfFatal(t); - error = t; - throw t; + } catch (RuntimeException e) { + error = e; + throw e; + } catch (JMSException e) { + error = e; + throw e; + } catch (Error e) { + propagateIfFatal(e); + error = e; + throw e; } finally { if (error != null) span.error(error); span.finish(); @@ -184,10 +196,16 @@ void send(SendDestination sendDestination, Destination destination, Message mess Throwable error = null; try { sendDestination.apply(delegate, destination, message); - } catch (Throwable t) { - propagateIfFatal(t); - error = t; - throw t; + } catch (RuntimeException e) { + error = e; + throw e; + } catch (JMSException e) { + error = e; + throw e; + } catch (Error e) { + propagateIfFatal(e); + error = e; + throw e; } finally { if (error != null) span.error(error); span.finish(); @@ -203,10 +221,16 @@ public void send(Destination destination, Message message, int deliveryMode, int Throwable error = null; try { delegate.send(destination, message, deliveryMode, priority, timeToLive); - } catch (Throwable t) { - propagateIfFatal(t); - error = t; - throw t; + } catch (RuntimeException e) { + error = e; + throw e; + } catch (JMSException e) { + error = e; + throw e; + } catch (Error e) { + propagateIfFatal(e); + error = e; + throw e; } finally { if (error != null) span.error(error); span.finish(); @@ -223,10 +247,16 @@ public void send(Message message, CompletionListener completionListener) throws Throwable error = null; try { delegate.send(message, TracingCompletionListener.create(completionListener, destination, span, current)); - } catch (Throwable t) { - propagateIfFatal(t); - error = t; - throw t; + } catch (RuntimeException e) { + error = e; + throw e; + } catch (JMSException e) { + error = e; + throw e; + } catch (Error e) { + propagateIfFatal(e); + error = e; + throw e; } finally { if (error != null) span.error(error).finish(); ws.close(); @@ -243,10 +273,16 @@ public void send(Message message, CompletionListener completionListener) throws Throwable error = null; try { delegate.send(message, deliveryMode, priority, timeToLive, completionListener); - } catch (Throwable t) { - propagateIfFatal(t); - error = t; - throw t; + } catch (RuntimeException e) { + error = e; + throw e; + } catch (JMSException e) { + error = e; + throw e; + } catch (Error e) { + propagateIfFatal(e); + error = e; + throw e; } finally { if (error != null) span.error(error).finish(); ws.close(); @@ -262,10 +298,16 @@ public void send(Message message, CompletionListener completionListener) throws Throwable error = null; try { delegate.send(destination, message, completionListener); - } catch (Throwable t) { - propagateIfFatal(t); - error = t; - throw t; + } catch (RuntimeException e) { + error = e; + throw e; + } catch (JMSException e) { + error = e; + throw e; + } catch (Error e) { + propagateIfFatal(e); + error = e; + throw e; } finally { if (error != null) span.error(error).finish(); ws.close(); @@ -281,10 +323,16 @@ public void send(Message message, CompletionListener completionListener) throws Throwable error = null; try { delegate.send(destination, message, deliveryMode, priority, timeToLive, completionListener); - } catch (Throwable t) { - propagateIfFatal(t); - error = t; - throw t; + } catch (RuntimeException e) { + error = e; + throw e; + } catch (JMSException e) { + error = e; + throw e; + } catch (Error e) { + propagateIfFatal(e); + error = e; + throw e; } finally { if (error != null) span.error(error).finish(); ws.close(); @@ -313,10 +361,16 @@ public void send(Queue queue, Message message, int deliveryMode, int priority, l Throwable error = null; try { qs.send(queue, message, deliveryMode, priority, timeToLive); - } catch (Throwable t) { - propagateIfFatal(t); - error = t; - throw t; + } catch (RuntimeException e) { + error = e; + throw e; + } catch (JMSException e) { + error = e; + throw e; + } catch (Error e) { + propagateIfFatal(e); + error = e; + throw e; } finally { if (error != null) span.error(error); span.finish(); @@ -346,10 +400,16 @@ void checkQueueSender() { Throwable error = null; try { tp.publish(message); - } catch (Throwable t) { - propagateIfFatal(t); - error = t; - throw t; + } catch (RuntimeException e) { + error = e; + throw e; + } catch (JMSException e) { + error = e; + throw e; + } catch (Error e) { + propagateIfFatal(e); + error = e; + throw e; } finally { if (error != null) span.error(error); span.finish(); @@ -367,10 +427,16 @@ void checkQueueSender() { Throwable error = null; try { tp.publish(message, deliveryMode, priority, timeToLive); - } catch (Throwable t) { - propagateIfFatal(t); - error = t; - throw t; + } catch (RuntimeException e) { + error = e; + throw e; + } catch (JMSException e) { + error = e; + throw e; + } catch (Error e) { + propagateIfFatal(e); + error = e; + throw e; } finally { if (error != null) span.error(error); span.finish(); @@ -394,10 +460,16 @@ public void publish(Topic topic, Message message, int deliveryMode, int priority Throwable error = null; try { tp.publish(topic, message, deliveryMode, priority, timeToLive); - } catch (Throwable t) { - propagateIfFatal(t); - error = t; - throw t; + } catch (RuntimeException e) { + error = e; + throw e; + } catch (JMSException e) { + error = e; + throw e; + } catch (Error e) { + propagateIfFatal(e); + error = e; + throw e; } finally { if (error != null) span.error(error); span.finish(); diff --git a/instrumentation/mongodb/src/main/java/brave/mongodb/TraceMongoCommandListener.java b/instrumentation/mongodb/src/main/java/brave/mongodb/TraceMongoCommandListener.java index 4bdc062270..51e6adfc0d 100644 --- a/instrumentation/mongodb/src/main/java/brave/mongodb/TraceMongoCommandListener.java +++ b/instrumentation/mongodb/src/main/java/brave/mongodb/TraceMongoCommandListener.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 @@ -41,7 +41,7 @@ */ final class TraceMongoCommandListener implements CommandListener { // See https://docs.mongodb.com/manual/reference/command for the command reference - static final Set COMMANDS_WITH_COLLECTION_NAME = new LinkedHashSet<>(Arrays.asList( + static final Set COMMANDS_WITH_COLLECTION_NAME = new LinkedHashSet(Arrays.asList( "aggregate", "count", "distinct", "mapReduce", "geoSearch", "delete", "find", "findAndModify", "insert", "update", "collMod", "compact", "convertToCapped", "create", "createIndexes", "drop", "dropIndexes", "killCursors", "listIndexes", "reIndex")); diff --git a/instrumentation/netty-codec-http/src/main/java/brave/netty/http/TracingHttpServerHandler.java b/instrumentation/netty-codec-http/src/main/java/brave/netty/http/TracingHttpServerHandler.java index d9b060db8e..31c4f93632 100644 --- a/instrumentation/netty-codec-http/src/main/java/brave/netty/http/TracingHttpServerHandler.java +++ b/instrumentation/netty-codec-http/src/main/java/brave/netty/http/TracingHttpServerHandler.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 @@ -32,6 +32,8 @@ import java.net.InetSocketAddress; import java.net.URI; +import static brave.internal.Throwables.propagateIfFatal; + final class TracingHttpServerHandler extends ChannelDuplexHandler { final CurrentTraceContext currentTraceContext; final HttpServerHandler handler; @@ -59,7 +61,11 @@ final class TracingHttpServerHandler extends ChannelDuplexHandler { Throwable error = null; try { ctx.fireChannelRead(msg); - } catch (Throwable e) { + } catch (RuntimeException e) { + error = e; + throw e; + } catch (Error e) { + propagateIfFatal(e); error = e; throw e; } finally { @@ -83,9 +89,13 @@ final class TracingHttpServerHandler extends ChannelDuplexHandler { Throwable error = null; try { ctx.write(msg, prm); - } catch (Throwable t) { - error = t; - throw t; + } catch (RuntimeException e) { + error = e; + throw e; + } catch (Error e) { + propagateIfFatal(e); + error = e; + throw e; } finally { HttpServerRequest request = ctx.channel().attr(NettyHttpTracing.REQUEST_ATTRIBUTE).get(); handler.handleSend(new HttpResponseWrapper(request, response, error), span); diff --git a/instrumentation/p6spy/src/main/java/brave/p6spy/TracingP6SpyOptions.java b/instrumentation/p6spy/src/main/java/brave/p6spy/TracingP6SpyOptions.java index bcc5052e71..2177d9a181 100644 --- a/instrumentation/p6spy/src/main/java/brave/p6spy/TracingP6SpyOptions.java +++ b/instrumentation/p6spy/src/main/java/brave/p6spy/TracingP6SpyOptions.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2022 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 @@ -48,7 +48,7 @@ public void load(Map options) { @Override public Map getDefaults() { - Map allDefaults = new LinkedHashMap<>(super.getDefaults()); + Map allDefaults = new LinkedHashMap(super.getDefaults()); allDefaults.putAll(logLoadableOptions.getDefaults()); allDefaults.put(INCLUDE_PARAMETER_VALUES, Boolean.FALSE.toString()); allDefaults.put(INCLUDE_AFFECTED_ROWS_COUNT, Boolean.FALSE.toString()); diff --git a/instrumentation/servlet/src/main/java/brave/servlet/TracingFilter.java b/instrumentation/servlet/src/main/java/brave/servlet/TracingFilter.java index 6cc8aa89b8..4dd155abde 100644 --- a/instrumentation/servlet/src/main/java/brave/servlet/TracingFilter.java +++ b/instrumentation/servlet/src/main/java/brave/servlet/TracingFilter.java @@ -90,6 +90,12 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha } catch (RuntimeException e) { error = e; throw e; + } catch (IOException e) { + error = e; + throw e; + } catch (ServletException e) { + error = e; + throw e; } catch (Error e) { propagateIfFatal(e); error = e; diff --git a/instrumentation/servlet/src/main/java/brave/servlet/internal/ServletRuntime.java b/instrumentation/servlet/src/main/java/brave/servlet/internal/ServletRuntime.java index ba5bb28d88..7fca26afad 100644 --- a/instrumentation/servlet/src/main/java/brave/servlet/internal/ServletRuntime.java +++ b/instrumentation/servlet/src/main/java/brave/servlet/internal/ServletRuntime.java @@ -213,7 +213,7 @@ static final class Servlet25 extends ServletRuntime { try { // we don't check for accessibility as isAccessible is deprecated: just fail later getStatusMethod = clazz.getMethod("getStatus"); - return (int) ((Method) getStatusMethod).invoke(response); + return (Integer) ((Method) getStatusMethod).invoke(response); } catch (Throwable throwable) { propagateIfFatal(throwable); getStatusMethod = RETURN_NULL; @@ -228,7 +228,7 @@ static final class Servlet25 extends ServletRuntime { // if we are here, we have a cached method, that "should" never fail, but we check anyway try { - return (int) ((Method) getStatusMethod).invoke(response); + return (Integer) ((Method) getStatusMethod).invoke(response); } catch (Throwable throwable) { propagateIfFatal(throwable); Map, Object> replacement = new LinkedHashMap, Object>(classesToCheck); diff --git a/instrumentation/spring-web/src/main/java/brave/spring/web/TraceContextListenableFuture.java b/instrumentation/spring-web/src/main/java/brave/spring/web/TraceContextListenableFuture.java index e90dd5195c..4e2da1591e 100644 --- a/instrumentation/spring-web/src/main/java/brave/spring/web/TraceContextListenableFuture.java +++ b/instrumentation/spring-web/src/main/java/brave/spring/web/TraceContextListenableFuture.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 @@ -44,7 +44,7 @@ final class TraceContextListenableFuture implements ListenableFuture { @Override public void addCallback(ListenableFutureCallback callback) { delegate.addCallback(callback != null - ? new TraceContextListenableFutureCallback<>(callback, this) + ? new TraceContextListenableFutureCallback(callback, this) : null ); } @@ -54,7 +54,7 @@ public void addCallback(SuccessCallback successCallback, FailureCallback failureCallback) { delegate.addCallback( successCallback != null - ? new TraceContextSuccessCallback<>(successCallback, this) + ? new TraceContextSuccessCallback(successCallback, this) : null, failureCallback != null ? new TraceContextFailureCallback(failureCallback, this) @@ -104,14 +104,20 @@ static final class TraceContextListenableFutureCallback } @Override public void onSuccess(T result) { - try (Scope scope = currentTraceContext.maybeScope(invocationContext)) { + Scope scope = currentTraceContext.maybeScope(invocationContext); + try { delegate.onSuccess(result); + } finally { + scope.close(); } } @Override public void onFailure(Throwable ex) { - try (Scope scope = currentTraceContext.maybeScope(invocationContext)) { + Scope scope = currentTraceContext.maybeScope(invocationContext); + try { delegate.onFailure(ex); + } finally { + scope.close(); } } @@ -133,8 +139,11 @@ static final class TraceContextSuccessCallback implements SuccessCallback } @Override public void onSuccess(T result) { - try (Scope scope = currentTraceContext.maybeScope(invocationContext)) { + Scope scope = currentTraceContext.maybeScope(invocationContext); + try { delegate.onSuccess(result); + } finally { + scope.close(); } } @@ -156,8 +165,11 @@ static final class TraceContextFailureCallback implements FailureCallback { } @Override public void onFailure(Throwable ex) { - try (Scope scope = currentTraceContext.maybeScope(invocationContext)) { + Scope scope = currentTraceContext.maybeScope(invocationContext); + try { delegate.onFailure(ex); + } finally { + scope.close(); } } diff --git a/instrumentation/spring-web/src/main/java/brave/spring/web/TracingAsyncClientHttpRequestInterceptor.java b/instrumentation/spring-web/src/main/java/brave/spring/web/TracingAsyncClientHttpRequestInterceptor.java index 9f3c23a6f2..c33562851d 100644 --- a/instrumentation/spring-web/src/main/java/brave/spring/web/TracingAsyncClientHttpRequestInterceptor.java +++ b/instrumentation/spring-web/src/main/java/brave/spring/web/TracingAsyncClientHttpRequestInterceptor.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 @@ -33,6 +33,8 @@ import org.springframework.util.concurrent.ListenableFuture; import org.springframework.util.concurrent.ListenableFutureCallback; +import static brave.internal.Throwables.propagateIfFatal; + public final class TracingAsyncClientHttpRequestInterceptor implements AsyncClientHttpRequestInterceptor { @@ -62,15 +64,29 @@ public static AsyncClientHttpRequestInterceptor create(HttpTracing httpTracing) ? currentTraceContext.get() : null; - try (Scope ws = currentTraceContext.maybeScope(span.context())) { + Scope ws = currentTraceContext.maybeScope(span.context()); + Throwable error = null; + try { ListenableFuture result = execution.executeAsync(req, body); result.addCallback(new TraceListenableFutureCallback(request, span, handler)); return invocationContext != null - ? new TraceContextListenableFuture<>(result, currentTraceContext, invocationContext) + ? new TraceContextListenableFuture(result, currentTraceContext, invocationContext) : result; - } catch (Throwable e) { - handler.handleReceive(new ClientHttpResponseWrapper(request, null, e), span); + } catch (RuntimeException e) { + error = e; + throw e; + } catch (IOException e) { + error = e; + throw e; + } catch (Error e) { + propagateIfFatal(e); + error = e; throw e; + } finally { + if (error != null) { + handler.handleReceive(new ClientHttpResponseWrapper(request, null, error), span); + } + ws.close(); } } diff --git a/instrumentation/spring-web/src/main/java/brave/spring/web/TracingClientHttpRequestInterceptor.java b/instrumentation/spring-web/src/main/java/brave/spring/web/TracingClientHttpRequestInterceptor.java index 03acadab3c..563110d6b1 100644 --- a/instrumentation/spring-web/src/main/java/brave/spring/web/TracingClientHttpRequestInterceptor.java +++ b/instrumentation/spring-web/src/main/java/brave/spring/web/TracingClientHttpRequestInterceptor.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 @@ -29,6 +29,8 @@ import org.springframework.http.client.ClientHttpResponse; import org.springframework.web.client.HttpStatusCodeException; +import static brave.internal.Throwables.propagateIfFatal; + public final class TracingClientHttpRequestInterceptor implements ClientHttpRequestInterceptor { public static ClientHttpRequestInterceptor create(Tracing tracing) { return create(HttpTracing.create(tracing)); @@ -51,14 +53,23 @@ public static ClientHttpRequestInterceptor create(HttpTracing httpTracing) { HttpRequestWrapper request = new HttpRequestWrapper(req); Span span = handler.handleSend(request); ClientHttpResponse response = null; + Scope ws = currentTraceContext.newScope(span.context()); Throwable error = null; - try (Scope ws = currentTraceContext.newScope(span.context())) { + try { return response = execution.execute(req, body); - } catch (Throwable e) { + } catch (RuntimeException e) { + error = e; + throw e; + } catch (IOException e) { + error = e; + throw e; + } catch (Error e) { + propagateIfFatal(e); error = e; throw e; } finally { handler.handleReceive(new ClientHttpResponseWrapper(request, response, error), span); + ws.close(); } } diff --git a/spring-beans/src/main/java/brave/spring/beans/TracingFactoryBean.java b/spring-beans/src/main/java/brave/spring/beans/TracingFactoryBean.java index a348095846..fe89bafc2e 100644 --- a/spring-beans/src/main/java/brave/spring/beans/TracingFactoryBean.java +++ b/spring-beans/src/main/java/brave/spring/beans/TracingFactoryBean.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 @@ -38,7 +38,7 @@ public class TracingFactoryBean extends AbstractFactoryBean { String localServiceName; @Deprecated Object localEndpoint, endpoint; // don't pin zipkin class @Deprecated Object spanReporter; // don't pin zipkin class - List spanHandlers = new ArrayList<>(); + List spanHandlers = new ArrayList(); Clock clock; Sampler sampler; @Deprecated ErrorParser errorParser;