Skip to content

Conversation

@Flash0ver
Copy link
Member

@Flash0ver Flash0ver commented Sep 25, 2025

This is a follow-up PR
from #4462 (comment)
that is applying a change we made for the Serilog integration of Structured Logs
to the SDK-Logger and the Microsoft.Extensions.Logging integration,
when reading values for the attributes "trace_id" and "sentry.trace.parent_span_id".

Rather than using the TraceHeader,
instead use the currently active Span, or the Propagation Context as a fallback.

During testing I noticed, that there doesn't seem to be a behavioral difference in Sentry, hence the #skip-changelog.


Note

Structured Logs now derive trace_id from the active span or scope and only include sentry.trace.parent_span_id when an active span exists.

  • Structured Logs behavior:
    • Read trace_id/parent_span_id via SentryLog.GetTraceIdAndSpanId(...) from the active Span; fall back to scope for trace_id only.
    • Omit sentry.trace.parent_span_id when no active span.
  • Implementations updated:
    • Sentry.Extensions.Logging logger and DefaultSentryStructuredLogger now use the new helper (replacing GetTraceHeader).
    • Sentry.Serilog sink uses the helper; removes its local resolver.
    • Adds helper to SentryLog core type.
  • Tests: Adjusted to validate new source of IDs and absence of parent_span_id without an active span.
  • Changelog: Note about not sending Parent-Span-IDs without an active span.

Written by Cursor Bugbot for commit 2326d97. This will update automatically on new commits. Configure here.

@codecov
Copy link

codecov bot commented Sep 25, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 73.48%. Comparing base (e9f75ac) to head (50ee186).
⚠️ Report is 5 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4565   +/-   ##
=======================================
  Coverage   73.47%   73.48%           
=======================================
  Files         482      482           
  Lines       17679    17678    -1     
  Branches     3495     3493    -2     
=======================================
+ Hits        12989    12990    +1     
  Misses       3799     3799           
+ Partials      891      889    -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.

@Flash0ver
Copy link
Member Author

@sentry review

@Flash0ver Flash0ver marked this pull request as ready for review September 26, 2025 07:05
Copy link
Member

@alexsohn1126 alexsohn1126 left a comment

Choose a reason for hiding this comment

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

A couple of possibly dumb questions 😛

@Flash0ver Flash0ver self-assigned this Sep 29, 2025
@Flash0ver Flash0ver marked this pull request as draft September 29, 2025 17:14
@Flash0ver Flash0ver force-pushed the logs/ref-traceid-parentspanid branch from e9c3cbd to 5b42cad Compare September 30, 2025 14:09
@Flash0ver Flash0ver marked this pull request as ready for review September 30, 2025 14:47
@Flash0ver Flash0ver changed the title ref(logs): Structured Logs read TraceId and ParentSpanId from Active-Span or Propagation-Context fix(logs): Structured Logs do not send ParentSpanId when no Span was active Sep 30, 2025
Copy link
Member

@alexsohn1126 alexsohn1126 left a comment

Choose a reason for hiding this comment

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

Looks good! Thanks for answering my questions 💯

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.

3 participants