Path: redb-route/redb.Route/Telemetry/SpanTagProcessor.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/Telemetry/SpanTagProcessor.cs
----
using System.Diagnostics;
using Microsoft.Extensions.Logging;
using redb.Route.Abstractions;
using redb.Route.Core;
namespace redb.Route.Telemetry;
///
/// The processor of .SpanTag(key, value, target): puts one attribute on a span of the engine. The exchange is
/// not touched. Nothing happens when there is no such span, when it records no data (no listener, not sampled) — the
/// value is then not even evaluated — or when it has already ended. A value that fails to evaluate is skipped and
/// logged at Debug: telemetry does not change the outcome of the message.
///
internal sealed class SpanTagProcessor : IProcessor
{
private readonly string _key;
private readonly IExpression _value;
private readonly SpanTarget _target;
private readonly ILogger? _logger;
internal SpanTagProcessor(string key, IExpression value, SpanTarget target, ILogger? logger)
{
_key = key;
_value = value;
_target = target;
_logger = logger;
}
///
public Task Process(IExchange exchange, CancellationToken ct = default)
{
var span = _target == SpanTarget.Inbound ? (exchange as Exchange)?.InboundSpan : EnclosingSpan();
if (span is not { IsAllDataRequested: true } || span.IsStopped)
return Task.CompletedTask;
object? value;
try
{
value = SpanTagPolicy.ToAttributeValue(_value.Evaluate