Record Class OpenTelemetryPropagationContext

java.lang.Object
java.lang.Record
io.micronaut.tracing.opentelemetry.OpenTelemetryPropagationContext
Record Components:
context - The OpenTelemetry context
All Implemented Interfaces:
io.micronaut.core.propagation.PropagatedContextElement, io.micronaut.core.propagation.ThreadPropagatedContextElement<io.opentelemetry.context.Scope>

public record OpenTelemetryPropagationContext(io.opentelemetry.context.Context context) extends Record implements io.micronaut.core.propagation.ThreadPropagatedContextElement<io.opentelemetry.context.Scope>
The element of Micronaut's PropagatedContext that carries an OpenTelemetry Context. While the propagated context is in scope, for example inside PropagatedContext.propagate(java.util.function.Supplier) or code wrapped with PropagatedContext.wrap(Runnable), the OpenTelemetry context is current.

Integrations that make a span current for the code they call, such as messaging listeners, add the span's context as this element, so that it follows Micronaut's thread hops. Reactive code finds it with OpenTelemetryReactorPropagation.currentContext(reactor.util.context.ContextView), which looks the element up by this type, so another ThreadPropagatedContextElement carrying the same context wouldn't be found there.

Since:
8.4.0
Author:
Denis Stepanov
  • Constructor Details

    • OpenTelemetryPropagationContext

      public OpenTelemetryPropagationContext(io.opentelemetry.context.Context context)
      Creates an instance of a OpenTelemetryPropagationContext record class.
      Parameters:
      context - the value for the context record component
  • Method Details

    • updateThreadContext

      public io.opentelemetry.context.Scope updateThreadContext()
      Specified by:
      updateThreadContext in interface io.micronaut.core.propagation.ThreadPropagatedContextElement<io.opentelemetry.context.Scope>
    • restoreThreadContext

      public void restoreThreadContext(io.opentelemetry.context.Scope oldScope)
      Specified by:
      restoreThreadContext in interface io.micronaut.core.propagation.ThreadPropagatedContextElement<io.opentelemetry.context.Scope>
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • context

      public io.opentelemetry.context.Context context()
      Returns the value of the context record component.
      Returns:
      the value of the context record component