Add MustBeClosed to Context.makeCurrent (#1914)
This commit is contained in:
parent
ed75175578
commit
34953d5fee
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
package io.opentelemetry.api.baggage;
|
||||
|
||||
import com.google.errorprone.annotations.MustBeClosed;
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.context.ContextKey;
|
||||
import io.opentelemetry.context.Scope;
|
||||
|
|
@ -69,6 +70,7 @@ public final class BaggageUtils {
|
|||
* @param baggage the {@link Baggage} to be added to the current {@code Context}.
|
||||
* @return the {@link Scope} for the updated {@code Context}.
|
||||
*/
|
||||
@MustBeClosed
|
||||
public static Scope currentContextWith(Baggage baggage) {
|
||||
Context context = withBaggage(baggage, Context.current());
|
||||
return context.makeCurrent();
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ package io.opentelemetry.context;
|
|||
|
||||
import brave.propagation.CurrentTraceContext;
|
||||
import brave.propagation.TraceContext;
|
||||
import com.google.errorprone.annotations.MustBeClosed;
|
||||
|
||||
public class OpenTelemetryCurrentTraceContext extends CurrentTraceContext {
|
||||
|
||||
|
|
@ -18,8 +19,9 @@ public class OpenTelemetryCurrentTraceContext extends CurrentTraceContext {
|
|||
return Context.current().get(TRACE_CONTEXT_KEY);
|
||||
}
|
||||
|
||||
@SuppressWarnings("ReferenceEquality")
|
||||
@SuppressWarnings({"ReferenceEquality", "MustBeClosedChecker"})
|
||||
@Override
|
||||
@MustBeClosed
|
||||
public Scope newScope(TraceContext context) {
|
||||
Context currentOtel = Context.current();
|
||||
TraceContext currentBrave = currentOtel.get(TRACE_CONTEXT_KEY);
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ public class ContextStorageOverride extends Context.Storage {
|
|||
private static final ContextKey<Context> GRPC_CONTEXT = ContextKey.named("grpc-context");
|
||||
private static final Context.Key<Scope> OTEL_SCOPE = Context.key("otel-scope");
|
||||
|
||||
@SuppressWarnings("MustBeClosedChecker")
|
||||
@Override
|
||||
public Context doAttach(Context toAttach) {
|
||||
io.opentelemetry.context.Context otelContext = io.opentelemetry.context.Context.current();
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@
|
|||
|
||||
package io.opentelemetry.context;
|
||||
|
||||
import com.google.errorprone.annotations.MustBeClosed;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
|
@ -136,6 +137,7 @@ public interface Context {
|
|||
* assert Context.current() == prevCtx;
|
||||
* }</pre>
|
||||
*/
|
||||
@MustBeClosed
|
||||
default Scope makeCurrent() {
|
||||
return ContextStorage.get().attach(this);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue