fix(telemetry): redact after ConfigureLogger enrichers, keep colliding dictionary keys, require http(s) OTLP endpoint and validate the options overload; bump 0.2.1 (scadaproj#48)

Claude-Session: https://claude.ai/code/session_01GT67AEHd2Acv1YPwGfXEoV
This commit is contained in:
Joseph Doherty
2026-11-09 14:57:48 -05:00
parent 5bf2f2caf1
commit 1786bab0a0
12 changed files with 182 additions and 25 deletions
@@ -55,6 +55,43 @@ public sealed class AddZbTelemetryTests
Assert.Contains("OtlpEndpoint", ex.Message);
}
[Theory]
[InlineData("localhost:4317")]
[InlineData("otel-collector:4317")]
[InlineData("ftp://collector:4317")]
public void AddZbTelemetry_Throws_WhenOtlpEndpointIsSchemeLessOrNotHttp(string endpoint)
{
// Telemetry-011: "host:port" parses as an absolute URI whose scheme is the host name.
var builder = WebApplication.CreateBuilder();
var ex = Assert.Throws<ArgumentException>(() =>
builder.AddZbTelemetry(o =>
{
o.ServiceName = "telemetry-test";
o.Exporter = ZbExporter.Otlp;
o.OtlpEndpoint = endpoint;
}));
Assert.Contains("OtlpEndpoint", ex.Message);
}
[Fact]
public void AddZbTelemetry_PrebuiltOptionsOverload_ValidatesServiceNameAndOtlpEndpoint()
{
var services = new ServiceCollection();
Assert.Throws<ArgumentException>(() =>
services.AddZbTelemetry(new ZbTelemetryOptions()));
var ex = Assert.Throws<ArgumentException>(() =>
services.AddZbTelemetry(new ZbTelemetryOptions
{
ServiceName = "telemetry-test",
Exporter = ZbExporter.Otlp,
OtlpEndpoint = "collector:4317",
}));
Assert.Equal("options", ex.ParamName);
Assert.Contains("OtlpEndpoint", ex.Message);
}
[Fact]
public void AddZbTelemetry_Throws_WhenOtlpExporterHasNoEndpoint()
{