Skip to content

Conversation

@bouwkast
Copy link
Collaborator

Summary of changes

Fixes a DuckTypeFieldIsReadonlyException happening in the RabbitMQ v7+ instrumentation when BasicPublish is called with CachedStrings.

Reason for change

https://github.com/rabbitmq/rabbitmq-dotnet-client/blob/94147996821f6a77bed0e77fd1886e75b08a31f9/projects/RabbitMQ.Client/CachedString.cs#L16

is defined as readonly

Our DuckType had was a get/set property.

When calling BasicPublish with CachedString we'd get the following error:

2025-12-23 09:52:24.105 -05:00 [ERR] Exception occurred when calling the CallTarget integration continuation. System.TypeInitializationException: The type initializer for 'Datadog.Trace.ClrProfiler.CallTarget.Handlers.BeginMethodHandler`8' threw an exception.
 ---> Datadog.Trace.ClrProfiler.CallTarget.CallTargetInvokerException: The field 'Value' is marked as readonly, you should remove the setter from the base type class or interface.
 ---> Datadog.Trace.DuckTyping.DuckTypeFieldIsReadonlyException: The field 'Value' is marked as readonly, you should remove the setter from the base type class or interface.
   at Datadog.Trace.DuckTyping.DuckTypeFieldIsReadonlyException.Throw(FieldInfo field) in C:\Users\steven.bouwkamp\source\repos\dd-trace-dotnet2\tracer\src\Datadog.Trace\DuckTyping\DuckTypeExceptions.cs:line 171
   at Datadog.Trace.DuckTyping.DuckType.CreateProperties(TypeBuilder proxyTypeBuilder, Type proxyDefinitionType, Type targetType, FieldInfo instanceField) in C:\Users\steven.bouwkamp\source\repos\dd-trace-dotnet2\tracer\src\Datadog.Trace\DuckTyping\DuckType.cs:line 774
   at Datadog.Trace.DuckTyping.DuckType.CreateProxyType(Type proxyDefinitionType, Type targetType, Boolean dryRun) in C:\Users\steven.bouwkamp\source\repos\dd-trace-dotnet2\tracer\src\Datadog.Trace\DuckTyping\DuckType.cs:line 215
--- End of stack trace from previous location ---
   at Datadog.Trace.ClrProfiler.CallTarget.Handlers.IntegrationMapper.CreateBeginMethodDelegate(Type integrationType, Type targetType, Type[] argumentsTypes) in C:\Users\steven.bouwkamp\source\repos\dd-trace-dotnet2\tracer\src\Datadog.Trace\ClrProfiler\CallTarget\Handlers\IntegrationMapper.cs:line 142
   at Datadog.Trace.ClrProfiler.CallTarget.Handlers.BeginMethodHandler`8..cctor() in C:\Users\steven.bouwkamp\source\repos\dd-trace-dotnet2\tracer\src\Datadog.Trace\ClrProfiler\CallTarget\Handlers\BeginMethodHandler`6.cs:line 28
   --- End of inner exception stack trace ---
   at Datadog.Trace.ClrProfiler.CallTarget.Handlers.BeginMethodHandler`8..cctor() in C:\Users\steven.bouwkamp\source\repos\dd-trace-dotnet2\tracer\src\Datadog.Trace\ClrProfiler\CallTarget\Handlers\BeginMethodHandler`6.cs:line 35
   --- End of inner exception stack trace ---
   at RabbitMQ.Client.Impl.Channel.BasicPublishAsync[TProperties](CachedString exchange, CachedString routingKey, Boolean mandatory, TProperties basicProperties, ReadOnlyMemory`1 body, CancellationToken cancellationToken)
 { MachineName: ".", Process: "[68600 Samples.RabbitMQ]", AppDomain: "[1 Samples.RabbitMQ]", AssemblyLoadContext: "\"\" Datadog.Trace.ClrProfiler.Managed.Loader.ManagedProfilerAssemblyLoadContext #2", TracerVersion: "3.35.0.0" }

Implementation details

Removed the set.

Test coverage

So, I updated the sample application to make a call with CachedStrings on V7+ instead of the normal string calls. So no new spans, we would expect the spans to be the same and they are.

Without this fix (removing the set) the tests fail as the snapshots are different for V7. I didn't think it was super valuable to update the sample application to call both versions of BasicPublish for V7 (one with CachedString and one without) as BasicPublishAsyncCachedStringsIntegration just calls return BasicPublishAsyncIntegration.OnMethodBegin so 🤷

Other details

Fixes this error identified by Error Tracking

Copy link
Member

@andrewlock andrewlock left a comment

Choose a reason for hiding this comment

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

Nice, thanks!

@dd-trace-dotnet-ci-bot
Copy link

Execution-Time Benchmarks Report ⏱️

Execution-time results for samples comparing This PR (8006) and master.

✅ No regressions detected - check the details below

Full Metrics Comparison

FakeDbCommand

Metric Master (Mean ± 95% CI) Current (Mean ± 95% CI) Change Status
.NET Framework 4.8 - Baseline
duration68.44 ± (68.43 - 68.68) ms68.60 ± (68.67 - 68.93) ms+0.2%✅⬆️
.NET Framework 4.8 - Bailout
duration72.34 ± (72.34 - 72.53) ms72.41 ± (72.31 - 72.53) ms+0.1%✅⬆️
.NET Framework 4.8 - CallTarget+Inlining+NGEN
duration1005.31 ± (1010.97 - 1020.36) ms1000.53 ± (1004.09 - 1011.26) ms-0.5%
.NET Core 3.1 - Baseline
process.internal_duration_ms21.93 ± (21.90 - 21.97) ms21.94 ± (21.92 - 21.97) ms+0.0%✅⬆️
process.time_to_main_ms78.76 ± (78.61 - 78.92) ms78.74 ± (78.59 - 78.89) ms-0.0%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.91 ± (10.91 - 10.91) MB10.90 ± (10.90 - 10.90) MB-0.1%
runtime.dotnet.threads.count12 ± (12 - 12)12 ± (12 - 12)+0.0%
.NET Core 3.1 - Bailout
process.internal_duration_ms21.87 ± (21.84 - 21.90) ms21.88 ± (21.85 - 21.91) ms+0.0%✅⬆️
process.time_to_main_ms79.86 ± (79.78 - 79.94) ms80.07 ± (79.98 - 80.17) ms+0.3%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.96 ± (10.96 - 10.96) MB10.96 ± (10.95 - 10.96) MB-0.0%
runtime.dotnet.threads.count13 ± (13 - 13)13 ± (13 - 13)+0.0%
.NET Core 3.1 - CallTarget+Inlining+NGEN
process.internal_duration_ms210.19 ± (208.66 - 211.71) ms209.13 ± (207.84 - 210.41) ms-0.5%
process.time_to_main_ms471.17 ± (470.58 - 471.75) ms471.17 ± (470.58 - 471.77) ms+0.0%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed48.10 ± (48.08 - 48.12) MB48.18 ± (48.16 - 48.20) MB+0.2%✅⬆️
runtime.dotnet.threads.count28 ± (28 - 28)28 ± (28 - 28)+0.0%
.NET 6 - Baseline
process.internal_duration_ms20.70 ± (20.67 - 20.73) ms20.56 ± (20.54 - 20.59) ms-0.7%
process.time_to_main_ms68.40 ± (68.27 - 68.53) ms67.90 ± (67.77 - 68.02) ms-0.7%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.60 ± (10.60 - 10.60) MB10.64 ± (10.64 - 10.64) MB+0.4%✅⬆️
runtime.dotnet.threads.count10 ± (10 - 10)10 ± (10 - 10)+0.0%
.NET 6 - Bailout
process.internal_duration_ms20.56 ± (20.54 - 20.59) ms20.56 ± (20.54 - 20.57) ms-0.0%
process.time_to_main_ms68.85 ± (68.80 - 68.89) ms68.86 ± (68.81 - 68.92) ms+0.0%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.65 ± (10.65 - 10.66) MB10.68 ± (10.68 - 10.69) MB+0.2%✅⬆️
runtime.dotnet.threads.count11 ± (11 - 11)11 ± (11 - 11)+0.0%
.NET 6 - CallTarget+Inlining+NGEN
process.internal_duration_ms198.56 ± (197.52 - 199.60) ms200.28 ± (199.20 - 201.37) ms+0.9%✅⬆️
process.time_to_main_ms437.99 ± (437.50 - 438.49) ms438.05 ± (437.48 - 438.62) ms+0.0%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed48.18 ± (48.12 - 48.25) MB48.17 ± (48.09 - 48.25) MB-0.0%
runtime.dotnet.threads.count28 ± (28 - 28)28 ± (28 - 28)-0.1%
.NET 8 - Baseline
process.internal_duration_ms18.77 ± (18.75 - 18.79) ms18.82 ± (18.79 - 18.85) ms+0.3%✅⬆️
process.time_to_main_ms66.88 ± (66.76 - 67.00) ms67.23 ± (67.09 - 67.37) ms+0.5%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed7.69 ± (7.69 - 7.70) MB7.68 ± (7.67 - 7.69) MB-0.2%
runtime.dotnet.threads.count10 ± (10 - 10)10 ± (10 - 10)+0.0%
.NET 8 - Bailout
process.internal_duration_ms18.83 ± (18.81 - 18.85) ms18.95 ± (18.87 - 19.03) ms+0.6%✅⬆️
process.time_to_main_ms68.30 ± (68.23 - 68.37) ms69.06 ± (68.75 - 69.37) ms+1.1%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed7.72 ± (7.72 - 7.73) MB7.73 ± (7.72 - 7.73) MB+0.1%✅⬆️
runtime.dotnet.threads.count11 ± (11 - 11)11 ± (11 - 11)+0.0%
.NET 8 - CallTarget+Inlining+NGEN
process.internal_duration_ms180.01 ± (179.07 - 180.96) ms179.82 ± (178.68 - 180.97) ms-0.1%
process.time_to_main_ms424.89 ± (424.36 - 425.41) ms424.15 ± (423.60 - 424.70) ms-0.2%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed36.26 ± (36.23 - 36.28) MB36.24 ± (36.21 - 36.28) MB-0.0%
runtime.dotnet.threads.count27 ± (27 - 27)27 ± (27 - 27)+0.1%✅⬆️

HttpMessageHandler

Metric Master (Mean ± 95% CI) Current (Mean ± 95% CI) Change Status
.NET Framework 4.8 - Baseline
duration193.25 ± (193.49 - 194.46) ms194.42 ± (194.51 - 195.37) ms+0.6%✅⬆️
.NET Framework 4.8 - Bailout
duration197.63 ± (197.46 - 198.00) ms197.67 ± (197.53 - 198.11) ms+0.0%✅⬆️
.NET Framework 4.8 - CallTarget+Inlining+NGEN
duration1113.62 ± (1124.61 - 1135.50) ms1109.82 ± (1109.79 - 1116.87) ms-0.3%
.NET Core 3.1 - Baseline
process.internal_duration_ms187.96 ± (187.52 - 188.40) ms189.55 ± (189.12 - 189.97) ms+0.8%✅⬆️
process.time_to_main_ms80.74 ± (80.54 - 80.95) ms81.43 ± (81.19 - 81.66) ms+0.8%✅⬆️
runtime.dotnet.exceptions.count3 ± (3 - 3)3 ± (3 - 3)+0.0%
runtime.dotnet.mem.committed16.10 ± (16.07 - 16.13) MB16.12 ± (16.10 - 16.14) MB+0.1%✅⬆️
runtime.dotnet.threads.count20 ± (20 - 20)20 ± (20 - 20)-0.3%
.NET Core 3.1 - Bailout
process.internal_duration_ms187.33 ± (187.04 - 187.61) ms187.98 ± (187.55 - 188.41) ms+0.3%✅⬆️
process.time_to_main_ms81.78 ± (81.64 - 81.92) ms82.28 ± (82.09 - 82.46) ms+0.6%✅⬆️
runtime.dotnet.exceptions.count3 ± (3 - 3)3 ± (3 - 3)+0.0%
runtime.dotnet.mem.committed16.16 ± (16.13 - 16.18) MB16.07 ± (16.04 - 16.10) MB-0.5%
runtime.dotnet.threads.count21 ± (21 - 21)21 ± (20 - 21)-1.1%
.NET Core 3.1 - CallTarget+Inlining+NGEN
process.internal_duration_ms398.72 ± (395.86 - 401.58) ms398.01 ± (395.35 - 400.66) ms-0.2%
process.time_to_main_ms474.71 ± (474.05 - 475.38) ms475.63 ± (474.72 - 476.53) ms+0.2%✅⬆️
runtime.dotnet.exceptions.count3 ± (3 - 3)3 ± (3 - 3)+0.0%
runtime.dotnet.mem.committed58.42 ± (58.27 - 58.57) MB58.61 ± (58.47 - 58.75) MB+0.3%✅⬆️
runtime.dotnet.threads.count29 ± (29 - 29)29 ± (29 - 30)+0.1%✅⬆️
.NET 6 - Baseline
process.internal_duration_ms192.71 ± (192.28 - 193.14) ms192.77 ± (192.38 - 193.15) ms+0.0%✅⬆️
process.time_to_main_ms70.37 ± (70.11 - 70.62) ms69.92 ± (69.76 - 70.08) ms-0.6%
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed16.22 ± (16.11 - 16.34) MB15.93 ± (15.78 - 16.08) MB-1.8%
runtime.dotnet.threads.count19 ± (19 - 19)18 ± (18 - 18)-3.5%
.NET 6 - Bailout
process.internal_duration_ms191.90 ± (191.62 - 192.18) ms191.47 ± (191.17 - 191.76) ms-0.2%
process.time_to_main_ms70.97 ± (70.85 - 71.08) ms70.83 ± (70.75 - 70.92) ms-0.2%
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed16.23 ± (16.11 - 16.36) MB15.96 ± (15.80 - 16.12) MB-1.7%
runtime.dotnet.threads.count20 ± (20 - 20)20 ± (19 - 20)-0.5%
.NET 6 - CallTarget+Inlining+NGEN
process.internal_duration_ms410.56 ± (408.41 - 412.71) ms413.59 ± (411.01 - 416.18) ms+0.7%✅⬆️
process.time_to_main_ms445.29 ± (444.74 - 445.85) ms446.97 ± (446.31 - 447.64) ms+0.4%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed59.17 ± (59.03 - 59.31) MB58.90 ± (58.76 - 59.04) MB-0.5%
runtime.dotnet.threads.count30 ± (29 - 30)30 ± (29 - 30)+0.1%✅⬆️
.NET 8 - Baseline
process.internal_duration_ms190.90 ± (190.58 - 191.22) ms191.90 ± (191.52 - 192.29) ms+0.5%✅⬆️
process.time_to_main_ms69.98 ± (69.75 - 70.21) ms69.74 ± (69.56 - 69.91) ms-0.3%
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed11.77 ± (11.74 - 11.80) MB11.74 ± (11.72 - 11.76) MB-0.3%
runtime.dotnet.threads.count18 ± (18 - 18)18 ± (18 - 18)+0.3%✅⬆️
.NET 8 - Bailout
process.internal_duration_ms191.54 ± (191.06 - 192.02) ms192.54 ± (192.08 - 193.00) ms+0.5%✅⬆️
process.time_to_main_ms71.04 ± (70.90 - 71.18) ms71.26 ± (71.08 - 71.44) ms+0.3%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed11.80 ± (11.77 - 11.83) MB11.77 ± (11.75 - 11.79) MB-0.2%
runtime.dotnet.threads.count19 ± (19 - 19)19 ± (19 - 19)-0.0%
.NET 8 - CallTarget+Inlining+NGEN
process.internal_duration_ms368.26 ± (366.90 - 369.62) ms366.52 ± (364.99 - 368.04) ms-0.5%
process.time_to_main_ms430.09 ± (429.45 - 430.72) ms431.18 ± (430.58 - 431.77) ms+0.3%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed47.91 ± (47.88 - 47.95) MB48.02 ± (47.99 - 48.05) MB+0.2%✅⬆️
runtime.dotnet.threads.count29 ± (29 - 29)29 ± (29 - 29)-0.0%
Comparison explanation

Execution-time benchmarks measure the whole time it takes to execute a program, and are intended to measure the one-off costs. Cases where the execution time results for the PR are worse than latest master results are highlighted in **red**. The following thresholds were used for comparing the execution times:

  • Welch test with statistical test for significance of 5%
  • Only results indicating a difference greater than 5% and 5 ms are considered.

Note that these results are based on a single point-in-time result for each branch. For full results, see the dashboard.

Graphs show the p99 interval based on the mean and StdDev of the test run, as well as the mean value of the run (shown as a diamond below the graph).

Duration charts
FakeDbCommand (.NET Framework 4.8)
gantt
    title Execution time (ms) FakeDbCommand (.NET Framework 4.8)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (8006) - mean (69ms)  : 67, 71
    master - mean (69ms)  : 67, 70

    section Bailout
    This PR (8006) - mean (72ms)  : 71, 73
    master - mean (72ms)  : 72, 73

    section CallTarget+Inlining+NGEN
    This PR (8006) - mean (1,008ms)  : 956, 1059
    master - mean (1,016ms)  : 947, 1084

Loading
FakeDbCommand (.NET Core 3.1)
gantt
    title Execution time (ms) FakeDbCommand (.NET Core 3.1)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (8006) - mean (106ms)  : 103, 108
    master - mean (106ms)  : 104, 108

    section Bailout
    This PR (8006) - mean (107ms)  : 106, 108
    master - mean (107ms)  : 105, 108

    section CallTarget+Inlining+NGEN
    This PR (8006) - mean (708ms)  : 680, 735
    master - mean (712ms)  : 673, 752

Loading
FakeDbCommand (.NET 6)
gantt
    title Execution time (ms) FakeDbCommand (.NET 6)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (8006) - mean (93ms)  : 91, 95
    master - mean (94ms)  : 92, 96

    section Bailout
    This PR (8006) - mean (94ms)  : 93, 95
    master - mean (94ms)  : 93, 95

    section CallTarget+Inlining+NGEN
    This PR (8006) - mean (664ms)  : 643, 684
    master - mean (665ms)  : 642, 688

Loading
FakeDbCommand (.NET 8)
gantt
    title Execution time (ms) FakeDbCommand (.NET 8)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (8006) - mean (92ms)  : 90, 95
    master - mean (92ms)  : 89, 94

    section Bailout
    This PR (8006) - mean (94ms)  : 90, 97
    master - mean (93ms)  : 92, 94

    section CallTarget+Inlining+NGEN
    This PR (8006) - mean (631ms)  : 618, 645
    master - mean (631ms)  : 614, 649

Loading
HttpMessageHandler (.NET Framework 4.8)
gantt
    title Execution time (ms) HttpMessageHandler (.NET Framework 4.8)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (8006) - mean (195ms)  : 190, 200
    master - mean (194ms)  : 189, 199

    section Bailout
    This PR (8006) - mean (198ms)  : 195, 200
    master - mean (198ms)  : 195, 200

    section CallTarget+Inlining+NGEN
    This PR (8006) - mean (1,113ms)  : 1063, 1164
    master - mean (1,130ms)  : 1045, 1215

Loading
HttpMessageHandler (.NET Core 3.1)
gantt
    title Execution time (ms) HttpMessageHandler (.NET Core 3.1)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (8006) - mean (280ms)  : 271, 288
    master - mean (277ms)  : 272, 283

    section Bailout
    This PR (8006) - mean (279ms)  : 274, 283
    master - mean (278ms)  : 275, 281

    section CallTarget+Inlining+NGEN
    This PR (8006) - mean (911ms)  : 866, 957
    master - mean (911ms)  : 868, 955

Loading
HttpMessageHandler (.NET 6)
gantt
    title Execution time (ms) HttpMessageHandler (.NET 6)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (8006) - mean (271ms)  : 265, 277
    master - mean (272ms)  : 266, 278

    section Bailout
    This PR (8006) - mean (270ms)  : 266, 275
    master - mean (271ms)  : 267, 274

    section CallTarget+Inlining+NGEN
    This PR (8006) - mean (895ms)  : 844, 945
    master - mean (891ms)  : 847, 935

Loading
HttpMessageHandler (.NET 8)
gantt
    title Execution time (ms) HttpMessageHandler (.NET 8)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (8006) - mean (272ms)  : 264, 279
    master - mean (271ms)  : 266, 275

    section Bailout
    This PR (8006) - mean (274ms)  : 265, 283
    master - mean (273ms)  : 267, 278

    section CallTarget+Inlining+NGEN
    This PR (8006) - mean (829ms)  : 807, 852
    master - mean (827ms)  : 811, 844

Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants