Path: redb-route/redb.Route/Processors/InboundSpanProcessor.cs Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages. License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route Page: https://redbase.app/src/dev-2026-12-06/redb-route/redb.Route/Processors/InboundSpanProcessor.cs ---- using System.Diagnostics; using redb.Route.Abstractions; using redb.Route.Core; using redb.Route.Telemetry; namespace redb.Route.Processors; /// /// Keeps the inbound span of the transport that delivered the exchange on the exchange while its route runs, for /// .SpanTag(..., SpanTarget.Inbound). The consumer opened that span around the route /// (), so on entry it is /// . A route entered through direct: finds one of the caller's internal spans /// there and keeps the caller's inbound span. Restored on exit, as does the context. /// internal sealed class InboundSpanProcessor : IProcessor { private readonly IProcessor _inner; public InboundSpanProcessor(IProcessor inner) => _inner = inner ?? throw new ArgumentNullException(nameof(inner)); public async Task Process(IExchange exchange, CancellationToken ct = default) { if (exchange is not Exchange stampable || Activity.Current is not { } current || !IsInbound(current)) { await _inner.Process(exchange, ct).ConfigureAwait(false); return; } var previous = stampable.InboundSpan; stampable.InboundSpan = current; try { await _inner.Process(exchange, ct).ConfigureAwait(false); } finally { stampable.InboundSpan = previous; } } private static bool IsInbound(Activity span) => span.Source == RouteActivitySource.Source && span.Kind is ActivityKind.Server or ActivityKind.Consumer; }