Class Tracing

java.lang.Object
com.jsgalactic.axiom.otel.Tracing

public final class Tracing extends Object
Creates one OpenTelemetry SERVER span per admitted request without adding a dependency or an SPI to axiom-core. The span's parent comes from the caller's W3C traceparent and tracestate, extracted by the OpenTelemetry API propagator; a request without a valid header starts a root span.

Span names are METHOD route-template for a matched route and the method alone for a router-generated answer. Attributes use the stable HTTP semantic conventions http.request.method, http.route and http.response.status_code; raw paths, query strings, headers and identities are never attributes. The tracer and meter of this module use the instrumentation scope "com.jsgalactic.axiom.otel".

A successful response's status is recorded on the span before it ends. An exception is recorded with Span.recordException(Throwable), sets StatusCode.ERROR, and gets the failing status of an AxiomException or 500 for any other exception; the span ends before the exception leaves the middleware. Responses produced from exceptions do not flow back through the chain, so Middleware.afterError(com.jsgalactic.axiom.context.Context, com.jsgalactic.axiom.http.Response) adds a traceresponse header carrying the span's identity to a mapped error response. A failure with no mapped error response has no header to decorate.

The returned middleware is thread-safe: per-request state stays in local variables and one confined thread-local slot. It makes the created span current while the chain runs, so OpenTelemetry instrumentation on the same thread uses it as the parent.

  • Field Details

    • SCOPE_NAME

      public static final String SCOPE_NAME
      Instrumentation scope name of every tracer and meter this module creates.
      See Also:
  • Method Details

    • create

      public static Middleware create(io.opentelemetry.api.OpenTelemetry openTelemetry)
      Creates middleware using the tracer of SCOPE_NAME from the supplied instance. The caller owns that instance, its SDK, its sampler and its exporters; this module never installs or configures them.
      Parameters:
      openTelemetry - tracer and propagator source, usually the application's SDK or OpenTelemetry.noop()
      Returns:
      thread-safe tracing middleware
    • create

      public static Middleware create(io.opentelemetry.api.trace.Tracer tracer)
      Creates middleware around a caller-supplied tracer. Use this overload when the caller chooses the instrumentation scope; create(OpenTelemetry) supplies the scope of this module.
      Parameters:
      tracer - tracer that creates the SERVER spans
      Returns:
      thread-safe tracing middleware