Commit 6f69452
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.
Co-authored-by: Russ Cam <[email protected]>
1 parent 01fc7c0 commit 6f69452
1 file changed
+16
-24
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
21 | | - | |
| 20 | + | |
| 21 | + | |
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
27 | 26 | | |
28 | | - | |
| 27 | + | |
| 28 | + | |
29 | 29 | | |
30 | | - | |
| 30 | + | |
31 | 31 | | |
32 | | - | |
| 32 | + | |
33 | 33 | | |
34 | 34 | | |
35 | | - | |
| 35 | + | |
| 36 | + | |
36 | 37 | | |
37 | 38 | | |
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
41 | 42 | | |
42 | 43 | | |
43 | | - | |
| 44 | + | |
44 | 45 | | |
45 | | - | |
| 46 | + | |
46 | 47 | | |
47 | 48 | | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | 49 | | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
62 | 54 | | |
63 | 55 | | |
64 | 56 | | |
0 commit comments