Add ActivityContext capture to LogEvent for trace correlation#7995
Merged
Aaronontheweb merged 10 commits intoakkadotnet:devfrom Jan 25, 2026
Merged
Conversation
Captures Activity.Current?.Context at LogEvent creation time, enabling downstream logging backends (like OpenTelemetry) to correlate logs with their parent trace/span even after async dispatch through the actor mailbox. This addresses GitHub issue akkadotnet#6855 where Activity.Current is lost when log events cross actor mailbox boundaries due to AsyncLocal not flowing. Changes: - Add ActivityContext? property to LogEvent base class - Capture context in constructor before mailbox crossing - Add System.Diagnostics.DiagnosticSource package for netstandard2.0 - Add unit tests for trace context capture behavior - Update API approval baselines
2 tasks
Aaronontheweb
added a commit
to Aaronontheweb/akka.net
that referenced
this pull request
Jan 26, 2026
…tnet#7995) Captures Activity.Current?.Context at LogEvent creation time, enabling downstream logging backends (like OpenTelemetry) to correlate logs with their parent trace/span even after async dispatch through the actor mailbox. This addresses GitHub issue akkadotnet#6855 where Activity.Current is lost when log events cross actor mailbox boundaries due to AsyncLocal not flowing. Changes: - Add ActivityContext? property to LogEvent base class - Capture context in constructor before mailbox crossing - Add System.Diagnostics.DiagnosticSource package for netstandard2.0 - Add unit tests for trace context capture behavior - Update API approval baselines Co-authored-by: Gregorius Soedharmo <arkatufus@yahoo.com>
Merged
Aaronontheweb
added a commit
that referenced
this pull request
Jan 26, 2026
Captures Activity.Current?.Context at LogEvent creation time, enabling downstream logging backends (like OpenTelemetry) to correlate logs with their parent trace/span even after async dispatch through the actor mailbox. This addresses GitHub issue #6855 where Activity.Current is lost when log events cross actor mailbox boundaries due to AsyncLocal not flowing. Changes: - Add ActivityContext? property to LogEvent base class - Capture context in constructor before mailbox crossing - Add System.Diagnostics.DiagnosticSource package for netstandard2.0 - Add unit tests for trace context capture behavior - Update API approval baselines Co-authored-by: Gregorius Soedharmo <arkatufus@yahoo.com>
This was referenced Jan 27, 2026
This was referenced Jan 27, 2026
This was referenced Feb 9, 2026
This was referenced Feb 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ActivityContext?property toLogEventbase classActivity.Current?.Contextat log event creation time (before mailbox crossing)Motivation
Related to #6855 -
Activity.CurrentusesAsyncLocal<T>which doesn't flow across actor mailbox boundaries. By capturing theActivityContextat log event creation time, we preserve the trace context for use by logging backends likeLoggerFactoryLoggerin Akka.Hosting.Changes
LogEvent.cs- AddedActivityContext?property with capture in constructorAkka.csproj- AddedSystem.Diagnostics.DiagnosticSourcepackage for netstandard2.0Test plan
ActivityContextcapture whenActivity.CurrentexistsActivityContextwhen no activity