You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix Client Diagnostics following upgrade to DiagnosticSource 5.0.0 (#5326)
Relates: elastic/apm-agent-dotnet#1094
This commit fixes a rather pernicious bug with Diagnostics from the clients,
following the upgrade to System.Diagnostics.DiagnosticSource 5.0.0.
`Diagnostic` and `Diagnostic<TState, TStateEnd>` derived from
System.Diagnostics.Activity, implementing IDisposable to make them
nicer to work with. In System.Diagnostics.DiagnosticSource 5.0.0, Activity now
implements IDisposable, so the impl was updated to override `Dispose(bool)`.
A problem arises from now deriving from Activity in that for an activity that is not finished,
`Dispose()` calls `Stop()` which in turn will notify the ActivitySource that it has stopped
**and** sets `Activity.Current` to the parent Activity (null if there's no parent). Now,
when calling into overridden `Dispose(bool)`, the DiagnosticSource is notified that
the `Activity` has stopped, allowing for listeners to take action. If a listener is getting
the Activity through `Activity.Current` as Elastic APM's integration does however,
`Activity.Current` no longer represents the Activity that has stopped, but its parent, with
no nice way to reference the stopped Activity.
This commit removes deriving from `Activity` and introduces a private field
in which to hold an Activity that is started, and ended on Dispose. Starting
and stopping the activity sets the start and end times, respectively.
0 commit comments