Commit 37f6383
authored
Fix
## Summary of changes
Fixes a `DuckTypeFieldIsReadonlyException` happening in the RabbitMQ v7+
instrumentation when `BasicPublish` is called with `CachedString`s.
## 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 `CachedString`s
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 #{issue} -->
Fixes [this error identified by Error
Tracking](https://app.datadoghq.com/error-tracking/issue/b5bb096c-6bd4-11f0-adde-da7ad0900002)
<!-- DuckTypeFieldIsReadonlyException in RabbitMQ v7+ auto-instrumentation (#8006)1 parent 4eb6bef commit 37f6383
File tree
2 files changed
+24
-2
lines changed- tracer
- src/Datadog.Trace/ClrProfiler/AutoInstrumentation/RabbitMQ
- test/test-applications/integrations/Samples.RabbitMQ
2 files changed
+24
-2
lines changedLines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
58 | | - | |
| 58 | + | |
59 | 59 | | |
60 | 60 | | |
61 | | - | |
| 61 | + | |
62 | 62 | | |
Lines changed: 22 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
135 | 135 | | |
136 | 136 | | |
137 | 137 | | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
138 | 149 | | |
| 150 | + | |
139 | 151 | | |
140 | 152 | | |
141 | 153 | | |
| |||
180 | 192 | | |
181 | 193 | | |
182 | 194 | | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
183 | 204 | | |
184 | 205 | | |
185 | 206 | | |
| 207 | + | |
186 | 208 | | |
187 | 209 | | |
188 | 210 | | |
| |||
0 commit comments