Class NoopTracingProvider

java.lang.Object
org.keycloak.tracing.NoopTracingProvider
All Implemented Interfaces:
Provider, TracingProvider

public class NoopTracingProvider extends Object implements TracingProvider
Return this provider when Profile.Feature.OPENTELEMETRY is disabled
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
    void
    Marks the end of the current Span execution.
    void
    Records information about the Throwable to the Span, and set Span status to StatusCode.ERROR
    io.opentelemetry.api.trace.Span
    Returns the Span from the current Context, falling back to a default, no-op Span if there is no span in the current context.
    io.opentelemetry.api.trace.Tracer
    getTracer(String name, String scopeVersion)
    Gets or creates a named Tracer instance.
    io.opentelemetry.api.trace.Span
    startSpan(io.opentelemetry.api.trace.SpanBuilder builder)
    Same as TracingProvider.startSpan(String, String), but the Span is created from your own SpanBuilder instance.
    io.opentelemetry.api.trace.Span
    startSpan(String tracerName, String spanName)
    Gets or creates a tracer instance, and starts a new Span.
    void
    trace(Class<?> tracerClass, String spanSuffix, Consumer<io.opentelemetry.api.trace.Span> execution)
    Wrapper for code block execution 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 block execution that returns a value, is traced and no need to manage the span lifecycle on our own.
    void
    trace(String tracerName, String spanName, Consumer<io.opentelemetry.api.trace.Span> execution)
    Wrapper for code block execution which is traced and no need to manage the span lifecycle on our own.
    <T> T
    trace(String tracerName, String spanName, Function<io.opentelemetry.api.trace.Span,T> execution)
    Wrapper for code block execution which is traced and no need to manage the span lifecycle on our own.
    boolean
    Validates whether all started Span 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 the Span from the current Context, falling back to a default, no-op Span if there is no span in the current context.
      Specified by:
      getCurrentSpan in interface TracingProvider
    • startSpan

      public io.opentelemetry.api.trace.Span startSpan(String tracerName, String spanName)
      Description copied from interface: TracingProvider
      Gets or creates a tracer instance, and starts a new Span.

      Span.end() must be manually called to end this Span, or use TracingProvider.trace(String, String, Consumer) that handles it all

      Example 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 interface TracingProvider
      Parameters:
      tracerName - name of Tracer that is obtained
      spanName - name of Span 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 as TracingProvider.startSpan(String, String), but the Span is created from your own SpanBuilder instance.

      Note: The preferred trace approach is to use trace() methods, such as TracingProvider.trace(Class, String, Consumer) that controls the overall span lifecycle.

      Example of usage:

      tracing.startSpan(tracer.spanBuilder("mySpan"))

      Specified by:
      startSpan in interface TracingProvider
      Parameters:
      builder - the custom SpanBuilder
      Returns:
      the newly created Span.
    • endSpan

      public void endSpan()
      Description copied from interface: TracingProvider
      Marks the end of the current Span execution.

      Note: The preferred trace approach is to use trace() methods, such as TracingProvider.trace(Class, String, Consumer) that controls the overall span lifecycle. In that case you should not use this method with trace() methods.

      Specified by:
      endSpan in interface TracingProvider
    • error

      public void error(Throwable error)
      Description copied from interface: TracingProvider
      Records information about the Throwable to the Span, and set Span status to StatusCode.ERROR
      Specified by:
      error in interface TracingProvider
      Parameters:
      error - the Throwable 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 block execution 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 interface TracingProvider
      Parameters:
      tracerName - name of Tracer
      spanName - name of Span
      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 block execution 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 interface TracingProvider
      Parameters:
      tracerName - name of Tracer
      spanName - name of Span
      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 block execution which is traced and no need to manage the span lifecycle on our own. Same as TracingProvider.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 interface TracingProvider
      Parameters:
      tracerClass - class that is used for getting tracer instance and its name used as prefix for Span
      spanSuffix - suffix that is appended to the final Span name
      execution - 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 block execution that returns a value, is traced and no need to manage the span lifecycle on our own. Same as TracingProvider.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 interface TracingProvider
      Parameters:
      tracerClass - class that is used for getting tracer instance and its name used as prefix for Span
      spanSuffix - suffix that is appended to the final Span name
      execution - code that is executed and traced
    • getTracer

      public io.opentelemetry.api.trace.Tracer getTracer(String name, String scopeVersion)
      Description copied from interface: TracingProvider
      Gets or creates a named Tracer instance.
      Specified by:
      getTracer in interface TracingProvider
      Parameters:
      name - name of the tracer
      scopeVersion - version of the instrumentation scope.
    • validateAllSpansEnded

      public boolean validateAllSpansEnded()
      Description copied from interface: TracingProvider
      Validates whether all started Span instances were ended.

      As part of the validation, some notification about not ended Spans should be shown.

      Specified by:
      validateAllSpansEnded in interface TracingProvider
      Returns:
      true if all Spans ended
    • close

      public void close()
      Specified by:
      close in interface Provider