fix(telemetry): identical resource across all 3 signals (symmetric OTLP trigger + deterministic service.instance.id)
Fix 1 — symmetric OTLP trigger: ZbSerilogConfig.ApplyOpenTelemetryExport now activates only when options.Exporter == ZbExporter.Otlp, matching the core OTel metrics/traces path. The previous fallback that also triggered on a bare OtlpEndpoint is removed; OtlpEndpoint is the address to use when Otlp is selected, not an independent enable. Fix 2 — deterministic service.instance.id: ZbResource.InstanceId (MachineName:ProcessId) is a new public property that produces a stable, process-unique id without a random GUID. ZbResource.Configure passes autoGenerateServiceInstanceId:false + serviceInstanceId:InstanceId so metrics and traces never get a random auto-generated id. ZbSerilogConfig.BuildResourceAttributes adds service.instance.id from ZbResource.InstanceId so the Serilog OTLP log sink carries the exact same value — all three signals now share an identical resource for cross-signal joins. Tests: +2 in ZbResourceTests (InstanceId determinism, no-GUID check), +2 in RedactionTests (service.instance.id parity assertion in BuildResourceAttributes, symmetric OTLP trigger tests). Total: 9 + 14 = 23 tests, all green.
This commit is contained in:
@@ -26,6 +26,8 @@ public sealed class ZbResourceTests
|
||||
Assert.Equal("site-7", attributes["site.id"]);
|
||||
Assert.Equal("central", attributes["node.role"]);
|
||||
Assert.Equal(Environment.MachineName, attributes["host.name"]);
|
||||
// service.instance.id must be the deterministic MachineName:ProcessId — NOT a random GUID.
|
||||
Assert.Equal(ZbResource.InstanceId, attributes["service.instance.id"]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -43,8 +45,29 @@ public sealed class ZbResourceTests
|
||||
Assert.Contains("service.name", keys);
|
||||
Assert.Contains("service.namespace", keys);
|
||||
Assert.Contains("host.name", keys);
|
||||
// service.instance.id is always present (deterministic, not optional).
|
||||
Assert.Contains("service.instance.id", keys);
|
||||
Assert.DoesNotContain("service.version", keys);
|
||||
Assert.DoesNotContain("site.id", keys);
|
||||
Assert.DoesNotContain("node.role", keys);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void InstanceId_is_deterministic_MachineName_colon_ProcessId()
|
||||
{
|
||||
// InstanceId must be stable within the process and follow the MachineName:ProcessId format.
|
||||
var expected = $"{Environment.MachineName}:{Environment.ProcessId}";
|
||||
Assert.Equal(expected, ZbResource.InstanceId);
|
||||
// Calling it twice returns the same value (no random component).
|
||||
Assert.Equal(ZbResource.InstanceId, ZbResource.InstanceId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void InstanceId_does_not_contain_a_random_guid()
|
||||
{
|
||||
// The old OTel SDK default was a random GUID; the deterministic id must NOT be a GUID.
|
||||
Assert.False(
|
||||
Guid.TryParse(ZbResource.InstanceId, out _),
|
||||
$"service.instance.id must not be a GUID; got '{ZbResource.InstanceId}'");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user