refactor(telemetry.serilog): review fixes (thread-safe redactor, bootstrap logger, minlevel ordering, test coverage)
This commit is contained in:
@@ -84,7 +84,53 @@ public sealed class RedactionTests
|
||||
|
||||
using var host = builder.Build();
|
||||
|
||||
// Serilog.ILogger is registered by AddSerilog — not Microsoft.Extensions.Logging.ILogger.
|
||||
var logger = host.Services.GetRequiredService<ILogger>();
|
||||
logger.Information("otlp wiring smoke test");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void BuildResourceAttributes_contains_required_keys_and_optional_keys_when_set()
|
||||
{
|
||||
var options = new ZbTelemetryOptions
|
||||
{
|
||||
ServiceName = "mxgateway",
|
||||
ServiceNamespace = "ZB.MOM.WW",
|
||||
SiteId = "site-a",
|
||||
NodeRole = "central",
|
||||
};
|
||||
|
||||
var attributes = ZbSerilogConfig.BuildResourceAttributes(options);
|
||||
|
||||
// Required keys always present.
|
||||
Assert.True(attributes.ContainsKey("service.name"), "service.name must be present");
|
||||
Assert.True(attributes.ContainsKey("service.namespace"), "service.namespace must be present");
|
||||
Assert.True(attributes.ContainsKey("host.name"), "host.name must be present");
|
||||
|
||||
// Optional keys present when options supply them.
|
||||
Assert.True(attributes.ContainsKey("site.id"), "site.id must be present when SiteId is set");
|
||||
Assert.True(attributes.ContainsKey("node.role"), "node.role must be present when NodeRole is set");
|
||||
|
||||
Assert.Equal("mxgateway", attributes["service.name"]);
|
||||
Assert.Equal("ZB.MOM.WW", attributes["service.namespace"]);
|
||||
Assert.Equal(Environment.MachineName, attributes["host.name"]);
|
||||
Assert.Equal("site-a", attributes["site.id"]);
|
||||
Assert.Equal("central", attributes["node.role"]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void BuildResourceAttributes_omits_optional_keys_when_not_set()
|
||||
{
|
||||
var options = new ZbTelemetryOptions
|
||||
{
|
||||
ServiceName = "mxgateway",
|
||||
SiteId = null,
|
||||
NodeRole = null,
|
||||
};
|
||||
|
||||
var attributes = ZbSerilogConfig.BuildResourceAttributes(options);
|
||||
|
||||
Assert.False(attributes.ContainsKey("site.id"), "site.id must be absent when SiteId is null");
|
||||
Assert.False(attributes.ContainsKey("node.role"), "node.role must be absent when NodeRole is null");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user