Skip to content

Commit

Permalink
fix: Ensure span ids are 16 characters (#3850)
Browse files Browse the repository at this point in the history
  • Loading branch information
knd775 authored Dec 17, 2024
1 parent 50251b2 commit b283298
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/Sentry/SpanId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace Sentry;
public override int GetHashCode() => StringComparer.Ordinal.GetHashCode(_value);

/// <inheritdoc />
public override string ToString() => _value.ToString("x8");
public override string ToString() => _value.ToString("x8").PadLeft(16, '0');

/// <summary>
/// Generates a new Sentry ID.
Expand Down
11 changes: 11 additions & 0 deletions test/Sentry.Tests/Protocol/Context/TraceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

0 comments on commit b283298

Please sign in to comment.