Skip to content

perf: avoid activity id conversion allocations#5239

Merged
jamescrosswell merged 5 commits into
getsentry:mainfrom
Sean-Kenneth-Doherty:codex/otel-activity-id-allocations
May 20, 2026
Merged

perf: avoid activity id conversion allocations#5239
jamescrosswell merged 5 commits into
getsentry:mainfrom
Sean-Kenneth-Doherty:codex/otel-activity-id-allocations

Conversation

@Sean-Kenneth-Doherty
Copy link
Copy Markdown
Contributor

Fixes #4289.

#skip-changelog

Summary

  • Add internal span/byte formatting helpers for SpanId and SentryId.
  • Convert Sentry IDs to OpenTelemetry Activity*Id values with stackallocated byte buffers on net8.0+, avoiding the intermediate ToString() allocation.
  • Keep stackallocated char-buffer fallbacks for legacy target frameworks.
  • Add explicit fixed-value conversion coverage for high-bit span IDs and trace IDs.

Verification

  • dotnet test /home/sean/.cache/codex/oss-contrib/sentry-dotnet-otel-alloc/test/Sentry.OpenTelemetry.Exporter.Tests/Sentry.OpenTelemetry.Exporter.Tests.csproj --framework net10.0 --no-restore /p:MSBuildEnableWorkloadResolver=false /p:WorkloadList=none /p:NO_MOBILE=true
  • dotnet build /home/sean/.cache/codex/oss-contrib/sentry-dotnet-otel-alloc/src/Sentry.OpenTelemetry.Exporter/Sentry.OpenTelemetry.Exporter.csproj --framework netstandard2.0 --no-restore /p:MSBuildEnableWorkloadResolver=false /p:WorkloadList=none /p:NO_MOBILE=true
  • dotnet build /home/sean/.cache/codex/oss-contrib/sentry-dotnet-otel-alloc/src/Sentry.OpenTelemetry.Exporter/Sentry.OpenTelemetry.Exporter.csproj --framework net462 --no-restore /p:MSBuildEnableWorkloadResolver=false /p:WorkloadList=none /p:NO_MOBILE=true
  • git diff --check

AI assistance: This PR was prepared with OpenAI Codex.

Co-Authored-By: OpenAI Codex <codex@openai.com>
Comment thread src/Sentry/SentryId.cs Outdated
@Sean-Kenneth-Doherty
Copy link
Copy Markdown
Contributor Author

Local validation on 413dd80b using the repo-requested .NET SDK 10.0.203 from global.json:

  • dotnet test test/Sentry.OpenTelemetry.Exporter.Tests/Sentry.OpenTelemetry.Exporter.Tests.csproj --framework net10.0 --no-restore /p:MSBuildEnableWorkloadResolver=false /p:WorkloadList=none /p:NO_MOBILE=true -> 59 passed
  • dotnet build src/Sentry.OpenTelemetry.Exporter/Sentry.OpenTelemetry.Exporter.csproj --framework netstandard2.0 --no-restore /p:MSBuildEnableWorkloadResolver=false /p:WorkloadList=none /p:NO_MOBILE=true -> passed
  • dotnet build src/Sentry.OpenTelemetry.Exporter/Sentry.OpenTelemetry.Exporter.csproj --framework net462 --no-restore /p:MSBuildEnableWorkloadResolver=false /p:WorkloadList=none /p:NO_MOBILE=true -> passed
  • git diff --check origin/main...HEAD and git diff --check -> clean

The netstandard2.0 and net462 builds emit the existing UnoptimizedAssemblyDetector warning for Sentry.dll, but complete with 0 errors.

Comment thread src/Sentry/SpanId.cs
@jamescrosswell jamescrosswell self-requested a review May 20, 2026 00:03
Copy link
Copy Markdown
Collaborator

@jamescrosswell jamescrosswell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Sean-Kenneth-Doherty .

I added a couple of commits to tidy up the code from Codex (the code was technically correct but it wasn't very obvious what that code was doing, so hard to maintain).

@codecov
Copy link
Copy Markdown

codecov Bot commented May 20, 2026

Codecov Report

❌ Patch coverage is 77.27273% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.10%. Comparing base (a9cb3b2) to head (e7d3326).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
src/Sentry/SentryId.cs 45.45% 2 Missing and 4 partials ⚠️
src/Sentry/SpanId.cs 78.94% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5239      +/-   ##
==========================================
- Coverage   74.12%   74.10%   -0.02%     
==========================================
  Files         508      508              
  Lines       18282    18315      +33     
  Branches     3574     3581       +7     
==========================================
+ Hits        13551    13573      +22     
- Misses       3861     3870       +9     
- Partials      870      872       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jamescrosswell jamescrosswell merged commit b682a76 into getsentry:main May 20, 2026
55 of 58 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf: Avoid allocations in OpenTelemetryExtensions

2 participants