Path: redb-route/tests/redb.Route.Tests/Telemetry/TelemetryProcessorTests.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/tests/redb.Route.Tests/Telemetry/TelemetryProcessorTests.cs
----
using redb.Route.Abstractions;
using redb.Route.Core;
using redb.Route.Processors;
using redb.Route.Telemetry;
namespace redb.Route.Tests.Telemetry;
///
/// Tests for and .
///
[Collection("Telemetry")]
public class TelemetryProcessorTests
{
[Fact]
public async Task InstrumentedProcessor_DelegatesToInner()
{
var called = false;
var inner = new DelegateProcessor(_ => called = true);
var sut = new InstrumentedProcessor(inner, "test-op");
var exchange = new Exchange(new Message { Body = "data" });
await sut.Process(exchange);
called.Should().BeTrue();
}
[Fact]
public async Task InstrumentedProcessor_PropagatesException()
{
var inner = new DelegateProcessor(async (_, _) =>
{
throw new InvalidOperationException("traced failure");
});
var sut = new InstrumentedProcessor(inner, "failing-op");
var exchange = new Exchange(new Message { Body = "data" });
var act = () => sut.Process(exchange);
await act.Should().ThrowAsync()
.WithMessage("traced failure");
}
[Fact]
public async Task MeteredProcessor_DelegatesToInner()
{
var called = false;
var inner = new DelegateProcessor(_ => called = true);
var sut = new MeteredProcessor(inner, "test-route");
var exchange = new Exchange(new Message { Body = "data" });
await sut.Process(exchange);
called.Should().BeTrue();
}
[Fact]
public async Task MeteredProcessor_PropagatesException()
{
var inner = new DelegateProcessor(async (_, _) =>
{
throw new InvalidOperationException("metered failure");
});
var sut = new MeteredProcessor(inner, "test-route");
var exchange = new Exchange(new Message { Body = "data" });
var act = () => sut.Process(exchange);
await act.Should().ThrowAsync()
.WithMessage("metered failure");
}
[Fact]
public void RouteActivitySource_HasCorrectName()
{
RouteActivitySource.Source.Name.Should().Be("redb.Route");
}
[Fact]
public void RouteMetrics_MeterName_IsCorrect()
{
RouteMetrics.MeterName.Should().Be("redb.Route");
}
/// The span's correlation tag comes from the CamelCorrelationId property, as Camel keeps it.
[Fact]
public async Task InstrumentedProcessor_TagsCorrelationId_FromTheProperty()
{
var operation = "correlation-op-" + Guid.NewGuid().ToString("N");
string? tag = null;
using var listener = new System.Diagnostics.ActivityListener
{
ShouldListenTo = s => s.Name == RouteActivitySource.SourceName,
Sample = (ref System.Diagnostics.ActivityCreationOptions _) =>
System.Diagnostics.ActivitySamplingResult.AllDataAndRecorded,
ActivityStopped = a =>
{
if (a.OperationName == operation)
tag = a.GetTagItem("redb.correlation.id") as string;
},
};
System.Diagnostics.ActivitySource.AddActivityListener(listener);
var exchange = new Exchange(new Message("data"));
exchange.Properties[ExchangePropertyKeys.CorrelationId] = "parent-1";
exchange.In.Headers["CamelCorrelationId"] = "from-a-header";
await new InstrumentedProcessor(new DelegateProcessor(_ => { }), operation).Process(exchange);
tag.Should().Be("parent-1");
}
}