Nexus API Reference

TraceContextMiddleware
in package
implements MiddlewareInterface

FinalYes
Tags
psalm-api

W3C Trace Context middleware. Parses the inbound traceparent header (per https://www.w3.org/TR/trace-context/), pushes the trace/span IDs into MDC so every downstream log line carries them, generates a fresh trace if the header is missing or malformed, and writes a new traceparent onto the response so callers/sidecars can correlate.

Format: 00-{32 hex}-{16 hex}-{2 hex}

  • version: 00 (only one defined)
  • trace-id: 16 random bytes (32 hex), preserved across the request
  • span-id: 8 random bytes (16 hex), this hop's span
  • flags: bitfield (01 = sampled)

Three request attributes are set so downstream code can read them without re-parsing:

  • trace.id
  • trace.parentSpanId (the inbound span, this hop's parent)
  • trace.spanId (this hop's span)

MDC keys: traceId, spanId, parentSpanId.

If nexus-logger is not installed, MDC writes are skipped silently (the middleware still sets request attributes and the response header). Soft-depends nexus-actors/logger.

Table of Contents

Interfaces

MiddlewareInterface

Methods

process()  : ResponseInterface

Methods

process()

public process(ServerRequestInterface $request, RequestHandlerInterface $handler) : ResponseInterface
Parameters
$request : ServerRequestInterface
$handler : RequestHandlerInterface
Return values
ResponseInterface

        
On this page

Search results