Interface TracingProvider
- All Superinterfaces:
Provider
- All Known Implementing Classes:
NoopTracingProvider
-
Method Summary
Modifier and TypeMethodDescriptionvoid
endSpan()
Marks the end of the currentSpan
execution.void
io.opentelemetry.api.trace.Span
Returns theSpan
from the currentContext
, falling back to a default, no-opSpan
if there is no span in the current context.default io.opentelemetry.api.trace.Tracer
Gets or creates a namedTracer
instance.io.opentelemetry.api.trace.Tracer
Gets or creates a namedTracer
instance.io.opentelemetry.api.trace.Span
startSpan
(io.opentelemetry.api.trace.SpanBuilder builder) default io.opentelemetry.api.trace.Span
Same asstartSpan(String, String)
, but you can start aSpan
that defines specific format for span name.io.opentelemetry.api.trace.Span
Gets or creates a tracer instance, and starts a newSpan
.default void
Wrapper for code blockexecution
which is traced and no need to manage the span lifecycle on our own.default <T> T
trace
(Class<?> tracerClass, String spanSuffix, Function<io.opentelemetry.api.trace.Span, T> execution) Wrapper for code blockexecution
that returns a value, is traced and no need to manage the span lifecycle on our own.void
Wrapper for code blockexecution
which is traced and no need to manage the span lifecycle on our own.<T> T
Wrapper for code blockexecution
which is traced and no need to manage the span lifecycle on our own.boolean
Validates whether all startedSpan
instances were ended.
-
Method Details
-
getCurrentSpan
io.opentelemetry.api.trace.Span getCurrentSpan()Returns theSpan
from the currentContext
, falling back to a default, no-opSpan
if there is no span in the current context. -
startSpan
Gets or creates a tracer instance, and starts a newSpan
.Span.end()
must be manually called to end thisSpan
, or usetrace(String, String, Consumer)
that handles it allExample of usage:
class MyClass { private final TracingProvider tracing; MyClass(KeycloakSession session) { tracing = session.getProvider(TracingProvider.class); } void doWork() { tracing.startSpan("MyTracerName", "mySpanName"); try { doSomeWork(); } finally { // To make sure we end the span even in case of an exception. tracing.endSpan(); // Manually end the span. } } }
- Parameters:
tracerName
- name ofTracer
that is obtainedspanName
- name ofSpan
that is used- Returns:
- the newly created
Span
.
-
startSpan
Same asstartSpan(String, String)
, but you can start aSpan
that defines specific format for span name. The finalSpan
name consists ofClass.getSimpleName()
, andspanSuffix
.Note: The preferred trace approach is to use
that controls the overall span lifecycle.trace()
methods, such astrace(Class, String, Consumer)
.Example of usage:
tracing.startSpan(MyClass.name, "span")
The result
Span
name will be "MyClass.span"- Parameters:
tracerClass
- class that is used for getting tracer instance and its name used as prefix forSpan
spanSuffix
- suffix that is appended to the finalSpan
name- Returns:
- the newly created
Span
.
-
startSpan
io.opentelemetry.api.trace.Span startSpan(io.opentelemetry.api.trace.SpanBuilder builder) Same asstartSpan(String, String)
, but theSpan
is created from your ownSpanBuilder
instance.Note: The preferred trace approach is to use
trace()
methods, such astrace(Class, String, Consumer)
that controls the overall span lifecycle.Example of usage:
tracing.startSpan(tracer.spanBuilder("mySpan"))
- Parameters:
builder
- the customSpanBuilder
- Returns:
- the newly created
Span
.
-
endSpan
void endSpan()Marks the end of the currentSpan
execution.Note: The preferred trace approach is to use
trace()
methods, such astrace(Class, String, Consumer)
that controls the overall span lifecycle. In that case you should not use this method withtrace()
methods. -
error
- Parameters:
exception
- theThrowable
to record.
-
trace
Wrapper for code blockexecution
which is traced and no need to manage the span lifecycle on our own.Example of usage:
class MyClass { private final TracingProvider tracing; MyClass(KeycloakSession session) { tracing = session.getProvider(TracingProvider.class); } void doWork() { tracing.trace("MyTracerName", "mySpanName", span -> { doSomeWork(); }); } }
- Parameters:
tracerName
- name ofTracer
spanName
- name ofSpan
execution
- code that is executed and traced
-
trace
default void trace(Class<?> tracerClass, String spanSuffix, Consumer<io.opentelemetry.api.trace.Span> execution) Wrapper for code blockexecution
which is traced and no need to manage the span lifecycle on our own. Same astrace(String, String, Consumer)
, but should be more usable.Example of usage:
void doWork() { // creates span name 'MyClass.mySpanName' tracing.trace(MyClass.name, "mySpanName", span -> { doSomeWork(); }); }
- Parameters:
tracerClass
- class that is used for getting tracer instance and its name used as prefix forSpan
spanSuffix
- suffix that is appended to the finalSpan
nameexecution
- code that is executed and traced
-
trace
<T> T trace(String tracerName, String spanName, Function<io.opentelemetry.api.trace.Span, T> execution) Wrapper for code blockexecution
which is traced and no need to manage the span lifecycle on our own.Example of usage:
class MyClass { private final TracingProvider tracing; MyClass(KeycloakSession session) { tracing = session.getProvider(TracingProvider.class); } String doWork() { return tracing.trace("MyTracerName", "mySpanName", span -> { return returnSomeString(); }); } }
- Parameters:
tracerName
- name ofTracer
spanName
- name ofSpan
execution
- code that is executed and traced that returns a value
-
trace
default <T> T trace(Class<?> tracerClass, String spanSuffix, Function<io.opentelemetry.api.trace.Span, T> execution) Wrapper for code blockexecution
that returns a value, is traced and no need to manage the span lifecycle on our own. Same astrace(String, String, Function)
, but should be more usable.Example of usage:
String doWork() { // creates span name 'MyClass.mySpanName' return tracing.trace(MyClass.name, "mySpanName", span -> { return returnSomeString(); }); }
- Parameters:
tracerClass
- class that is used for getting tracer instance and its name used as prefix forSpan
spanSuffix
- suffix that is appended to the finalSpan
nameexecution
- code that is executed and traced
-
getTracer
Gets or creates a namedTracer
instance.- Parameters:
name
- name of the tracerscopeVersion
- version of the instrumentation scope.
-
getTracer
Gets or creates a namedTracer
instance. Default scope version is Keycloak version (f.e. 26.0.5)- Parameters:
name
- name of the tracer
-
validateAllSpansEnded
boolean validateAllSpansEnded()Validates whether all startedSpan
instances were ended.As part of the validation, some notification about not ended
Span
s should be shown.- Returns:
- true if all
Span
s ended
-