Path: redb-route/tests/redb.Route.Tests.Http/HttpTelemetrySmokeTests.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.Http/HttpTelemetrySmokeTests.cs
----
using System.Diagnostics;
using System.Net;
using System.Net.Sockets;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using OpenTelemetry;
using OpenTelemetry.Trace;
using redb.Route.Abstractions;
using redb.Route.Core;
using redb.Route.Http;
using redb.Route.Telemetry;
using redb.Route.Tests.Telemetry;
namespace redb.Route.Tests.Http;
///
/// Smoke test: verifies opens a transport span on
/// with the OpenTelemetry semantic
/// HTTP attributes after P1 telemetry instrumentation.
///
public sealed class HttpTelemetrySmokeTests : IAsyncLifetime
{
private WebApplication? _server;
private int _port;
public async Task InitializeAsync()
{
_port = GetFreePort();
var builder = WebApplication.CreateSlimBuilder();
builder.WebHost.ConfigureKestrel(o => o.Listen(IPAddress.Loopback, _port));
builder.Logging.ClearProviders();
_server = builder.Build();
_server.Map("/{**catch}", static async ctx =>
{
ctx.Response.StatusCode = 200;
await ctx.Response.WriteAsync("ok");
});
await _server.StartAsync();
}
public async Task DisposeAsync()
{
if (_server is not null)
{
await _server.StopAsync();
await _server.DisposeAsync();
}
}
[Fact]
public async Task HttpProducer_EmitsTransportSpanWithHttpSemantics()
{
// Filtered to this test's own endpoint: the exporter is process state, so a plain
// AddSource(...) collects the spans of every route the other tests are running right now, and
// the Single() below then fails on somebody else's span. The producer span carries
// redb.route.endpoint; this test owns a port nobody else has.
using var probe = RouteTelemetryProbe.ForEndpointContaining($":{_port}/");
var component = new HttpComponent();
var path = $"/localhost:{_port}/smoke";
var uri = new EndpointUri("http", path, $"http:{path}", new Dictionary());
var endpoint = (HttpEndpoint)component.CreateEndpoint(uri);
var producer = new HttpProducer(endpoint, endpoint.EndpointOptions);
await producer.Start();
try
{
await producer.Process(new Exchange(new Message(null)));
}
finally
{
await producer.Stop();
}
probe.Activities.Should().NotBeEmpty("HttpProducer.Process must open a transport span");
var activity = probe.Activities.Single();
activity.Source.Name.Should().Be(RouteActivitySource.SourceName);
activity.Kind.Should().Be(ActivityKind.Client);
activity.GetTagItem("http.method").Should().Be("GET");
activity.GetTagItem("redb.route.endpoint").Should().NotBeNull();
}
private static int GetFreePort() => global::redb.Route.Tests.Shared.TestPorts.Next();
}