Package org.keycloak.tracing
Class NoopTracingProvider
java.lang.Object
org.keycloak.tracing.NoopTracingProvider
- All Implemented Interfaces:
Provider
,TracingProvider
Return this provider when
Profile.Feature.OPENTELEMETRY
is disabled-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
void
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.io.opentelemetry.api.trace.Tracer
Gets or creates a namedTracer
instance.io.opentelemetry.api.trace.Span
startSpan
(io.opentelemetry.api.trace.SpanBuilder builder) Same asTracingProvider.startSpan(String, String)
, but theSpan
is created from your ownSpanBuilder
instance.io.opentelemetry.api.trace.Span
Gets or creates a tracer instance, and starts a newSpan
.void
Wrapper for code blockexecution
which is traced and no need to manage the span lifecycle on our own.<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.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.keycloak.tracing.TracingProvider
getTracer, startSpan
-
Constructor Details
-
NoopTracingProvider
public NoopTracingProvider()
-
-
Method Details
-
getCurrentSpan
public io.opentelemetry.api.trace.Span getCurrentSpan()Description copied from interface:TracingProvider
Returns theSpan
from the currentContext
, falling back to a default, no-opSpan
if there is no span in the current context.- Specified by:
getCurrentSpan
in interfaceTracingProvider
-
startSpan
Description copied from interface:TracingProvider
Gets or creates a tracer instance, and starts a newSpan
.Span.end()
must be manually called to end thisSpan
, or useTracingProvider.trace(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. } } }
- Specified by:
startSpan
in interfaceTracingProvider
- Parameters:
tracerName
- name ofTracer
that is obtainedspanName
- name ofSpan
that is used- Returns:
- the newly created
Span
.
-
startSpan
public io.opentelemetry.api.trace.Span startSpan(io.opentelemetry.api.trace.SpanBuilder builder) Description copied from interface:TracingProvider
Same asTracingProvider.startSpan(String, String)
, but theSpan
is created from your ownSpanBuilder
instance.Note: The preferred trace approach is to use
trace()
methods, such asTracingProvider.trace(Class, String, Consumer)
that controls the overall span lifecycle.Example of usage:
tracing.startSpan(tracer.spanBuilder("mySpan"))
- Specified by:
startSpan
in interfaceTracingProvider
- Parameters:
builder
- the customSpanBuilder
- Returns:
- the newly created
Span
.
-
endSpan
public void endSpan()Description copied from interface:TracingProvider
Marks the end of the currentSpan
execution.Note: The preferred trace approach is to use
trace()
methods, such asTracingProvider.trace(Class, String, Consumer)
that controls the overall span lifecycle. In that case you should not use this method withtrace()
methods.- Specified by:
endSpan
in interfaceTracingProvider
-
error
Description copied from interface:TracingProvider
- Specified by:
error
in interfaceTracingProvider
- Parameters:
error
- theThrowable
to record.
-
trace
public void trace(String tracerName, String spanName, Consumer<io.opentelemetry.api.trace.Span> execution) Description copied from interface:TracingProvider
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(); }); } }
- Specified by:
trace
in interfaceTracingProvider
- Parameters:
tracerName
- name ofTracer
spanName
- name ofSpan
execution
- code that is executed and traced
-
trace
public <T> T trace(String tracerName, String spanName, Function<io.opentelemetry.api.trace.Span, T> execution) Description copied from interface:TracingProvider
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(); }); } }
- Specified by:
trace
in interfaceTracingProvider
- Parameters:
tracerName
- name ofTracer
spanName
- name ofSpan
execution
- code that is executed and traced that returns a value
-
trace
public void trace(Class<?> tracerClass, String spanSuffix, Consumer<io.opentelemetry.api.trace.Span> execution) Description copied from interface:TracingProvider
Wrapper for code blockexecution
which is traced and no need to manage the span lifecycle on our own. Same asTracingProvider.trace(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(); }); }
- Specified by:
trace
in interfaceTracingProvider
- 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
public <T> T trace(Class<?> tracerClass, String spanSuffix, Function<io.opentelemetry.api.trace.Span, T> execution) Description copied from interface:TracingProvider
Wrapper for code blockexecution
that returns a value, is traced and no need to manage the span lifecycle on our own. Same asTracingProvider.trace(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(); }); }
- Specified by:
trace
in interfaceTracingProvider
- 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
Description copied from interface:TracingProvider
Gets or creates a namedTracer
instance.- Specified by:
getTracer
in interfaceTracingProvider
- Parameters:
name
- name of the tracerscopeVersion
- version of the instrumentation scope.
-
validateAllSpansEnded
public boolean validateAllSpansEnded()Description copied from interface:TracingProvider
Validates whether all startedSpan
instances were ended.As part of the validation, some notification about not ended
Span
s should be shown.- Specified by:
validateAllSpansEnded
in interfaceTracingProvider
- Returns:
- true if all
Span
s ended
-
close
public void close()
-