Commit f51d779
authored
Fix exception in Kafka on .NET Framework (#8366)
## Summary of changes
Ran Kafka locally as I was attempting to port it to Testcontainers and
was actually get exceptions / errors on it, this resolves them (or at
least it seems to resolve them). Also noticed them in Error Tracking,
but only a single instance, but I'm not 100% sure if it was the same,
Error Tracking is linked in the linked Jira Ticket.
## Reason for change
Previously this was using `IsCompletedSuccessfully` and then doing a
cast and enumeration of all properties and was failing with the
following error as `IsCompletedSuccessfully` isn't available on .NET
Framework:
```
2026-03-24 15:43:11.768 -04:00 [WRN] Error extracting cluster_id from Kafka metadata Datadog.Trace.DuckTyping.DuckTypePropertyOrFieldNotFoundException: The property or field 'IsCompletedSuccessfully' for the proxy property 'IsCompletedSuccessfully' was not found in the instance of type 'System.Threading.Tasks.Task`1[[Confluent.Kafka.Admin.DescribeClusterResult, Confluent.Kafka, Version=2.6.1.0, Culture=neutral, PublicKeyToken=12c514ca49093d1e]]'.
at Datadog.Trace.DuckTyping.DuckTypePropertyOrFieldNotFoundException.Throw(String name, String duckAttributeName, Type type)
at Datadog.Trace.DuckTyping.DuckType.CreateProperties(TypeBuilder proxyTypeBuilder, Type proxyDefinitionType, Type targetType, FieldInfo instanceField)
at Datadog.Trace.DuckTyping.DuckType.CreateProxyType(Type proxyDefinitionType, Type targetType, Boolean dryRun)
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Datadog.Trace.DuckTyping.DuckType.CreateTypeResult.ThrowOnError[T](Object instance)
at Datadog.Trace.DuckTyping.DuckType.CreateTypeResult.CreateInstance[T](Object instance)
at Datadog.Trace.DuckTyping.DuckType.CreateCache`1.Create(Object instance)
at Datadog.Trace.ClrProfiler.AutoInstrumentation.Kafka.KafkaHelper.DescribeClusterWithTimeout(IAdminClient adminClient, Type describeClusterOptionsType)
at Datadog.Trace.ClrProfiler.AutoInstrumentation.Kafka.KafkaHelper.GetClusterId(String bootstrapServers, Object clientInstance)
{ MachineName: ".", Process: "[59476 Samples.Kafka]", AppDomain: "[1 Samples.Kafka.exe]", TracerVersion: "3.41.0.0" }
```
## Implementation details
Remove `IsCompletedSuccessfully` from `IDuckTypeTask` as it isn't there
on .NET Framework, attempted initially to go with TaskStatus but this
caused failures for xUnit/MS Test integration tests as those appear to
be using ValueTask, which doesn't have it.
Removing `IsCompletedSuccessfully` required some more changes to
`KafkaHelper`
## Test coverage
Applied the fix, re-ran didn't see again, however, the Error Tracking
one may be a different bug as it appears that it is on .NET 9.0 😕
Edit: yes appears to be a different error that came up during
development that was addressed
## Other details
<!-- Fixes #{issue} -->
Fixes https://datadoghq.atlassian.net/browse/APMLP-1146
<!-- 1 parent afb0834 commit f51d779
2 files changed
Lines changed: 11 additions & 33 deletions
File tree
- tracer/src/Datadog.Trace
- ClrProfiler/AutoInstrumentation/Kafka
- DuckTyping
Lines changed: 11 additions & 23 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
462 | 462 | | |
463 | 463 | | |
464 | 464 | | |
465 | | - | |
466 | | - | |
467 | 465 | | |
468 | | - | |
469 | | - | |
470 | | - | |
| 466 | + | |
| 467 | + | |
471 | 468 | | |
472 | | - | |
473 | | - | |
474 | | - | |
475 | | - | |
476 | | - | |
477 | | - | |
478 | | - | |
479 | | - | |
480 | | - | |
481 | | - | |
| 469 | + | |
| 470 | + | |
482 | 471 | | |
483 | | - | |
484 | | - | |
485 | | - | |
486 | | - | |
487 | | - | |
488 | | - | |
489 | | - | |
490 | | - | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
491 | 479 | | |
492 | 480 | | |
493 | 481 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | 15 | | |
21 | 16 | | |
22 | 17 | | |
| |||
34 | 29 | | |
35 | 30 | | |
36 | 31 | | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | 32 | | |
43 | 33 | | |
44 | 34 | | |
| |||
0 commit comments