Commit 01158ef
authored
Fix orphaned spans in WCF traces (#7842)
## Summary of changes
Fixes orphan traces in WCF
## Reason for change
Many customers have reported that in v3, with "delayed WCF"
instrumentation enabled, they get orphan spans. This can be easily
reproduced, so this PR fixes the issue.
## Background
There are two "modes" WCF can operate in: delayed instrumentation, and
"simple" instrumentation. Delayed instrumentation was introduced in
#1992 to avoid a
problematic error scenario. Instead of instrumenting early across the
whole "channel", we delayed instrumentation. A subsequent PR
#5206 updated the
instrumentation point to ensure the wcf span was active while
`IDispatchMessageInspector` were running.
This was somewhat complex, due to the convoluted and legacy way wcf uses
async and threading. Basically, we use a weak table to hold the current
span, and us the `MessageRpc` object as a key. Later on, we retrieve the
scope and dispose it.
## Implementation details
The missing part was that we were not "restoring" the wcf scope for when
the actual Invoker implementations executed. The process was:
- Update the tests and snapshots to:
- Record _all_ spans and traces (it makes it easier to [understand the
snapshots
using](https://andrewlock.github.io/DatadogSpanSnapshotViewer/))
- Create a span inside the "service" calls.
- These _should_ have been children of the wcf server spans, but they
were not. They were orphaned
- Update the "Invoker" implementations to grab the wcf spans, make it
active, and then deactivate it afterwards
- Regenerate the snapshots, and confirm the custom spans are no longer
orphaned 🎉
Additionally, do a small amount of refactoring:
- "Fix" nullability in some places
- Extract the "restore wcf span" functionality to `WcfCommon` as it's
used in multiple places
## Test coverage
Covered by existing, after the tweaks above. The snapshots change like
this:
Before the fix, after adding the additional custom spans,
`WSHttpBinding` traces:
<img width="1468" height="622" alt="image"
src="https://github.com/user-attachments/assets/7973514c-660e-4871-8c4d-7495473e9944"
/>
After the fix, `WSHttpBinding` traces:
<img width="1459" height="96" alt="image"
src="https://github.com/user-attachments/assets/0698e5d3-cb06-4ea6-ab00-5a3680f7e3ee"
/>
Before the fix, after adding the additional custom spans, WebHttp
traces:
<img width="1458" height="268" alt="image"
src="https://github.com/user-attachments/assets/b0a9f4c9-8584-4fa2-9441-74268d6fd279"
/>
After the fix, Web Http traces
<img width="1465" height="126" alt="image"
src="https://github.com/user-attachments/assets/b06f0255-0818-4516-a6a1-b1807c9781ad"
/>
Unfortunately, this ends up being somewhat unstable in regards to
sorting, so I did some more refactoring to separate the root span for
each separate httpcall. This should make sure we have more stable
ordering of the spans using the built-in sort order
The result is we get separate traces for each API call instead:
<img width="1458" height="713" alt="image"
src="https://github.com/user-attachments/assets/989a0cc8-befa-429f-9a9e-ede09c2abc48"
/>
## Other details
I wonder if we really need a weak table here? 🤔 seeing as we have an
instrumentation point that explicitly disposes the span, shouldn't we
just remove the entry at the same time?1 parent 55cc088 commit 01158ef
File tree
44 files changed
+22200
-2498
lines changed- tracer
- src/Datadog.Trace/ClrProfiler/AutoInstrumentation/Wcf
- test
- Datadog.Trace.ClrProfiler.IntegrationTests
- snapshots
- test-applications/integrations/Samples.Wcf
- Client
- Server
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
44 files changed
+22200
-2498
lines changedLines changed: 5 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
73 | | - | |
| 73 | + | |
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
| |||
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
94 | 87 | | |
95 | 88 | | |
96 | 89 | | |
| |||
Lines changed: 15 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
13 | 12 | | |
14 | 13 | | |
15 | 14 | | |
| |||
29 | 28 | | |
30 | 29 | | |
31 | 30 | | |
32 | | - | |
| 31 | + | |
33 | 32 | | |
34 | | - | |
| 33 | + | |
| 34 | + | |
35 | 35 | | |
36 | | - | |
| 36 | + | |
| 37 | + | |
37 | 38 | | |
38 | | - | |
39 | | - | |
40 | | - | |
| 39 | + | |
| 40 | + | |
41 | 41 | | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
51 | 49 | | |
52 | 50 | | |
| 51 | + | |
53 | 52 | | |
54 | 53 | | |
55 | 54 | | |
| |||
Lines changed: 17 additions & 18 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
13 | 12 | | |
14 | 13 | | |
15 | 14 | | |
| |||
29 | 28 | | |
30 | 29 | | |
31 | 30 | | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
32 | 42 | | |
33 | 43 | | |
34 | 44 | | |
| |||
39 | 49 | | |
40 | 50 | | |
41 | 51 | | |
42 | | - | |
| 52 | + | |
43 | 53 | | |
44 | | - | |
| 54 | + | |
45 | 55 | | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
61 | 59 | | |
62 | 60 | | |
| 61 | + | |
63 | 62 | | |
64 | 63 | | |
65 | 64 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
| 51 | + | |
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
| |||
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
68 | | - | |
| 68 | + | |
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
66 | | - | |
| 66 | + | |
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
| |||
Lines changed: 3 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
| 9 | + | |
8 | 10 | | |
9 | 11 | | |
10 | 12 | | |
11 | 13 | | |
12 | 14 | | |
13 | | - | |
| 15 | + | |
14 | 16 | | |
15 | 17 | | |
16 | 18 | | |
| |||
Lines changed: 6 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
13 | 12 | | |
14 | 13 | | |
15 | 14 | | |
| |||
40 | 39 | | |
41 | 40 | | |
42 | 41 | | |
43 | | - | |
| 42 | + | |
| 43 | + | |
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
48 | | - | |
| 48 | + | |
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
| |||
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
61 | | - | |
| 61 | + | |
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
67 | | - | |
| 67 | + | |
68 | 68 | | |
69 | 69 | | |
| 70 | + | |
70 | 71 | | |
71 | 72 | | |
72 | 73 | | |
| |||
Lines changed: 6 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
13 | | - | |
14 | 12 | | |
15 | 13 | | |
16 | 14 | | |
| |||
40 | 38 | | |
41 | 39 | | |
42 | 40 | | |
43 | | - | |
| 41 | + | |
| 42 | + | |
44 | 43 | | |
45 | 44 | | |
46 | 45 | | |
47 | 46 | | |
48 | | - | |
| 47 | + | |
49 | 48 | | |
50 | 49 | | |
51 | 50 | | |
| |||
58 | 57 | | |
59 | 58 | | |
60 | 59 | | |
61 | | - | |
| 60 | + | |
62 | 61 | | |
63 | 62 | | |
64 | 63 | | |
65 | 64 | | |
66 | 65 | | |
67 | | - | |
| 66 | + | |
68 | 67 | | |
69 | 68 | | |
| 69 | + | |
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
| |||
Lines changed: 49 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| |||
77 | 78 | | |
78 | 79 | | |
79 | 80 | | |
80 | | - | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
81 | 86 | | |
82 | 87 | | |
83 | 88 | | |
| |||
216 | 221 | | |
217 | 222 | | |
218 | 223 | | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
219 | 267 | | |
220 | 268 | | |
221 | 269 | | |
0 commit comments