Package io.opentelemetry.context
Class StrictContextStorage
java.lang.Object
io.opentelemetry.context.StrictContextStorage
- All Implemented Interfaces:
ContextStorage
,AutoCloseable
A
ContextStorage
which keeps track of opened and closed Scope
s, reporting caller
information if a Scope
is closed incorrectly or not at all.
Calling close()
will check at the moment it's called whether
there are any scopes that have been opened but not closed yet. This could be called at the end of
a unit test to ensure the tested code cleaned up scopes correctly.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static class
(package private) static class
(package private) final class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ContextStorage
private static final Logger
private final StrictContextStorage.PendingScopes
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) static AssertionError
void
close()
Ensures all scopes that have been created by this storage have been closed.(package private) static StrictContextStorage
create
(ContextStorage delegate) Returns a newStrictContextStorage
which delegates to the providedContextStorage
, wrapping created scopes to track their usage.current()
Returns the currentContext
.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.opentelemetry.context.ContextStorage
root
-
Field Details
-
logger
-
delegate
-
pendingScopes
-
-
Constructor Details
-
StrictContextStorage
-
-
Method Details
-
create
Returns a newStrictContextStorage
which delegates to the providedContextStorage
, wrapping created scopes to track their usage. -
attach
Description copied from interface:ContextStorage
Sets the specifiedContext
as the currentContext
and returns aScope
representing the scope of execution.Scope.close()
must be called when the currentContext
should be restored to what it was before attachingtoAttach
.- Specified by:
attach
in interfaceContextStorage
-
current
Description copied from interface:ContextStorage
- Specified by:
current
in interfaceContextStorage
-
close
public void close()Ensures all scopes that have been created by this storage have been closed. This can be useful to call at the end of a test to make sure everything has been cleaned up.Note: It is important to close all resources prior to calling this, so that in-flight operations are not mistaken as scope leaks. If this raises an error, consider if a Context.wrap(Executor) wrapped executor} is still running.
- Specified by:
close
in interfaceAutoCloseable
- Throws:
AssertionError
- if any scopes were left unclosed.
-
callerError
-