diff --git a/src/OpenTelemetry.Shims.OpenTracing/CHANGELOG.md b/src/OpenTelemetry.Shims.OpenTracing/CHANGELOG.md index 89768ea28f2..f5da296139c 100644 --- a/src/OpenTelemetry.Shims.OpenTracing/CHANGELOG.md +++ b/src/OpenTelemetry.Shims.OpenTracing/CHANGELOG.md @@ -6,6 +6,9 @@ Notes](../../RELEASENOTES.md). ## Unreleased +* Fixes support for `byte`, `short`, `int`, and `float` attributes. + ([#7080](https://github.com/open-telemetry/opentelemetry-dotnet/pull/7080)) + ## 1.15.2-beta.1 Released 2026-Apr-08 diff --git a/src/OpenTelemetry.Shims.OpenTracing/SpanShim.cs b/src/OpenTelemetry.Shims.OpenTracing/SpanShim.cs index a4e61a76eb5..f09b8863f17 100644 --- a/src/OpenTelemetry.Shims.OpenTracing/SpanShim.cs +++ b/src/OpenTelemetry.Shims.OpenTracing/SpanShim.cs @@ -66,6 +66,15 @@ public ISpan Log(DateTimeOffset timestamp, IEnumerable pair.Key, pair => pair.Value); + + Assert.Equal(6, tags.Count); + + Assert.Equal(1L, Assert.IsType(tags["byte-value"])); + Assert.Equal(2L, Assert.IsType(tags["short-value"])); + Assert.Equal(3L, Assert.IsType(tags["int-value"])); + Assert.Equal(4L, Assert.IsType(tags["long-value"])); + Assert.Equal(5D, Assert.IsType(tags["float-value"])); + Assert.Equal(6D, Assert.IsType(tags["double-value"])); + } + + [Fact] + public void LogUsingFieldsPreservesFractionalNumericValues() + { + var tracer = TracerProvider.Default.GetTracer(TracerName); + var shim = new SpanShim(tracer.StartSpan(SpanName)); + + shim.Log( + [ + new("float-point-one", 0.1f), + new("double-point-one", 0.1D), + new("float-point-three", 0.3f), + new("double-point-three", 0.3D), + new("float-exact", 1.5f), + new("double-exact", 1.5D), + ]); + + Assert.NotNull(shim.Span.Activity); + var evt = Assert.Single(shim.Span.Activity.Events); + var tags = evt.Tags.ToDictionary(pair => pair.Key, pair => pair.Value); + + Assert.Equal(6, tags.Count); + + // float->double widening: 0.1f is not exactly 0.1D due to IEEE 754 representation. + // Verify that the stored value matches the widened float, not the double literal. + double expectedFloatPointOne = 0.1f; + Assert.Equal(expectedFloatPointOne, Assert.IsType(tags["float-point-one"])); + Assert.NotEqual(0.1D, (double)tags["float-point-one"]!); + + Assert.Equal(0.1D, Assert.IsType(tags["double-point-one"])); + + double expectedFloatPointThree = 0.3f; + Assert.Equal(expectedFloatPointThree, Assert.IsType(tags["float-point-three"])); + Assert.NotEqual(0.3D, (double)tags["float-point-three"]!); + + Assert.Equal(0.3D, Assert.IsType(tags["double-point-three"])); + + // 1.5 is exactly representable in both float and double. + Assert.Equal(1.5D, Assert.IsType(tags["float-exact"])); + Assert.Equal(1.5D, Assert.IsType(tags["double-exact"])); + } + [Fact] public void SetTagStringValue() {