public interface ScopeManager
ScopeManager
interface abstracts both the activation of Span
instances via
activate(Span)
and access to an active Span
via activeSpan()
.Scope
,
Tracer.scopeManager()
Modifier and Type | Method and Description |
---|---|
Scope |
activate(Span span)
Set the specified
Span as the active instance for the current
context (usually a thread). |
Scope |
activate(Span span,
boolean finishSpanOnClose)
Deprecated.
use
activate(Span) instead.
Set the specified Span as the active instance for the current
context (usually a thread).
Finishing the
|
Scope |
active()
Deprecated.
use
activeSpan() instead.
Return the currently active Scope which can be used to deactivate the currently active
Span .
Observe that
Because both |
Span |
activeSpan()
Return the currently active
Span . |
Scope activate(Span span)
Span
as the active instance for the current
context (usually a thread).
The returned Scope
represents the active state for the span.
Once its active period is due, Scope.close()
ought to be called.
To ease this operation, Scope
supports try-with-resources.
Observe the span will not be automatically finished when Scope.close()
is called.
The corresponding Span
can be accessed at any time through activeSpan()
.
Usage:
Span span = tracer.buildSpan("...").start();
try (Scope scope = tracer.scopeManager().activate(span)) {
span.setTag("...", "...");
...
} catch (Exception e) {
span.log(...);
} finally {
// Optionally finish the Span if the operation it represents
// is logically completed at this point.
span.finish();
}
span
- the Span
that should become the activeSpan()
Scope
instance to control the end of the active period for the Span
. It is a
programming error to neglect to call Scope.close()
on the returned instance.@Deprecated Scope active()
activeSpan()
instead.
Return the currently active Scope
which can be used to deactivate the currently active
Span
.
Observe that Scope
is expected to be used only in the same thread where it was
created, and thus should not be passed across threads.
Because both active()
and activeSpan()
reference the current
active state, they both will be either null or non-null.
active scope
, or null if none could be found.Span activeSpan()
Span
.
Because both active()
and activeSpan()
reference the current
active state, they both will be either null or non-null.
active span
, or null if none could be found.@Deprecated Scope activate(Span span, boolean finishSpanOnClose)
activate(Span)
instead.
Set the specified Span
as the active instance for the current
context (usually a thread).
Finishing the Span
upon Scope.close()
is discouraged,
as reporting errors becomes impossible:
try (Scope scope = tracer.scopeManager().activate(span, true)) {
} catch (Exception e) {
// Not possible to report errors, as
// the span has been already finished.
}
span
- the Span
that should become the activeSpan()
finishSpanOnClose
- whether span should automatically be finished when Scope.close()
is calledScope
instance to control the end of the active period for the Span
. It is a
programming error to neglect to call Scope.close()
on the returned instance.Copyright © 2016–2019 OpenTracing. All rights reserved.