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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()voidendSpan()Marks the end of the currentSpanexecution.voidio.opentelemetry.api.trace.SpanReturns theSpanfrom the currentContext, falling back to a default, no-opSpanif there is no span in the current context.io.opentelemetry.api.trace.TracerGets or creates a namedTracerinstance.io.opentelemetry.api.trace.SpanstartSpan(io.opentelemetry.api.trace.SpanBuilder builder) Same asTracingProvider.startSpan(String, String), but theSpanis created from your ownSpanBuilderinstance.io.opentelemetry.api.trace.SpanGets or creates a tracer instance, and starts a newSpan.voidWrapper for code blockexecutionwhich is traced and no need to manage the span lifecycle on our own.<T> Ttrace(Class<?> tracerClass, String spanSuffix, Function<io.opentelemetry.api.trace.Span, T> execution) Wrapper for code blockexecutionthat returns a value, is traced and no need to manage the span lifecycle on our own.voidWrapper for code blockexecutionwhich is traced and no need to manage the span lifecycle on our own.<T> TWrapper for code blockexecutionwhich is traced and no need to manage the span lifecycle on our own.booleanValidates whether all startedSpaninstances were ended.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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:TracingProviderReturns theSpanfrom the currentContext, falling back to a default, no-opSpanif there is no span in the current context.- Specified by:
getCurrentSpanin interfaceTracingProvider
-
startSpan
Description copied from interface:TracingProviderGets 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:
startSpanin interfaceTracingProvider- Parameters:
tracerName- name ofTracerthat is obtainedspanName- name ofSpanthat 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:TracingProviderSame asTracingProvider.startSpan(String, String), but theSpanis created from your ownSpanBuilderinstance.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:
startSpanin interfaceTracingProvider- Parameters:
builder- the customSpanBuilder- Returns:
- the newly created
Span.
-
endSpan
public void endSpan()Description copied from interface:TracingProviderMarks the end of the currentSpanexecution.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:
endSpanin interfaceTracingProvider
-
error
Description copied from interface:TracingProvider- Specified by:
errorin interfaceTracingProvider- Parameters:
error- theThrowableto record.
-
trace
public void trace(String tracerName, String spanName, Consumer<io.opentelemetry.api.trace.Span> execution) Description copied from interface:TracingProviderWrapper for code blockexecutionwhich 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:
tracein interfaceTracingProvider- Parameters:
tracerName- name ofTracerspanName- name ofSpanexecution- 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:TracingProviderWrapper for code blockexecutionwhich 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:
tracein interfaceTracingProvider- Parameters:
tracerName- name ofTracerspanName- name ofSpanexecution- 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:TracingProviderWrapper for code blockexecutionwhich 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:
tracein interfaceTracingProvider- Parameters:
tracerClass- class that is used for getting tracer instance and its name used as prefix forSpanspanSuffix- suffix that is appended to the finalSpannameexecution- 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:TracingProviderWrapper for code blockexecutionthat 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:
tracein interfaceTracingProvider- Parameters:
tracerClass- class that is used for getting tracer instance and its name used as prefix forSpanspanSuffix- suffix that is appended to the finalSpannameexecution- code that is executed and traced
-
getTracer
Description copied from interface:TracingProviderGets or creates a namedTracerinstance.- Specified by:
getTracerin interfaceTracingProvider- Parameters:
name- name of the tracerscopeVersion- version of the instrumentation scope.
-
validateAllSpansEnded
public boolean validateAllSpansEnded()Description copied from interface:TracingProviderValidates whether all startedSpaninstances were ended.As part of the validation, some notification about not ended
Spans should be shown.- Specified by:
validateAllSpansEndedin interfaceTracingProvider- Returns:
- true if all
Spans ended
-
close
public void close()
-