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 Scopes, 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 ContextStorageprivate static final Loggerprivate final StrictContextStorage.PendingScopes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) static AssertionErrorvoidclose()Ensures all scopes that have been created by this storage have been closed.(package private) static StrictContextStoragecreate(ContextStorage delegate) Returns a newStrictContextStoragewhich 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, waitMethods inherited from interface io.opentelemetry.context.ContextStorage
root
-
Field Details
-
logger
-
delegate
-
pendingScopes
-
-
Constructor Details
-
StrictContextStorage
-
-
Method Details
-
create
Returns a newStrictContextStoragewhich delegates to the providedContextStorage, wrapping created scopes to track their usage. -
attach
Description copied from interface:ContextStorageSets the specifiedContextas the currentContextand returns aScoperepresenting the scope of execution.Scope.close()must be called when the currentContextshould be restored to what it was before attachingtoAttach.- Specified by:
attachin interfaceContextStorage
-
current
Description copied from interface:ContextStorage- Specified by:
currentin 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:
closein interfaceAutoCloseable- Throws:
AssertionError- if any scopes were left unclosed.
-
callerError
-