From b283298493999bda0711ae3baf43f6e6d2107d47 Mon Sep 17 00:00:00 2001
From: Ben Ayles <1235055+knd775@users.noreply.github.com>
Date: Tue, 17 Dec 2024 18:01:34 -0500
Subject: [PATCH] fix: Ensure span ids are 16 characters (#3850)
---
CHANGELOG.md | 1 +
src/Sentry/SpanId.cs | 2 +-
test/Sentry.Tests/Protocol/Context/TraceTests.cs | 11 +++++++++++
3 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f302bb5e53..5deb951993 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,6 +9,7 @@
### Fixes
- Fixed JNI Error when accessing Android device data from multiple threads ([#3802](https://github.com/getsentry/sentry-dotnet/pull/3802))
+- Fix "System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. (Parameter 'idData')" error propagating OpenTelemetry span ids ([#3850](https://github.com/getsentry/sentry-dotnet/pull/3850))
### Dependencies
diff --git a/src/Sentry/SpanId.cs b/src/Sentry/SpanId.cs
index a4e1062a40..0548d75d53 100644
--- a/src/Sentry/SpanId.cs
+++ b/src/Sentry/SpanId.cs
@@ -41,7 +41,7 @@ namespace Sentry;
public override int GetHashCode() => StringComparer.Ordinal.GetHashCode(_value);
///
- public override string ToString() => _value.ToString("x8");
+ public override string ToString() => _value.ToString("x8").PadLeft(16, '0');
///
/// Generates a new Sentry ID.
diff --git a/test/Sentry.Tests/Protocol/Context/TraceTests.cs b/test/Sentry.Tests/Protocol/Context/TraceTests.cs
index 46bcf7d930..27372d0d9a 100644
--- a/test/Sentry.Tests/Protocol/Context/TraceTests.cs
+++ b/test/Sentry.Tests/Protocol/Context/TraceTests.cs
@@ -85,4 +85,15 @@ public void Clone_CopyValues()
Assert.Equal(trace.SpanId, clone.SpanId);
Assert.Equal(trace.TraceId, clone.TraceId);
}
+
+ [Fact]
+ public void SpanId_LeadingZero_ToStringValid()
+ {
+ // Arrange
+ const string spanIdInput = "0ecd6f15f72015cb";
+ var spanId = new SpanId(spanIdInput);
+
+ // Assert
+ Assert.Equal(spanIdInput, spanId.ToString());
+ }
}