Pmartinez/missing field exception 2 - #9156
pablomartinezbernardo wants to merge 6 commits into
Conversation
BenchmarksBenchmark execution time: 2026-09-01 11:53:58 Comparing candidate commit 2c4bc1a in PR branch Found 0 performance improvements and 1 performance regressions! Performance is the same for 71 metrics, 0 unstable metrics, 71 known flaky benchmarks, 55 flaky benchmarks without significant changes.
|
Execution-Time Benchmarks Report ⏱️Execution-time results for samples comparing This PR (9156) and master. ✅ No regressions detected |
…ield-exception-2 # Conflicts: # tracer/test/Datadog.Trace.DuckTyping.Tests/GetAssemblyTests.cs
## Summary of changes - Generate DuckTyping proxy assemblies in the target assembly's load context. - Add compiled fixtures that model the Azure Functions load-context topology and cover both cross-ALC field access and proxy-cache isolation. ## Reason for change Azure Functions can load assemblies with the same identity into the default and a custom `AssemblyLoadContext`. DuckTyping previously generated its proxy in the default context, so the proxy could resolve a field dependency from the wrong context and throw `MissingFieldException`. ## Implementation details - For the `net6.0` tracer build, which is selected on .NET 6 and later, enter contextual reflection for the target assembly while defining the dynamic proxy assembly. - For the `netstandard2.0` and `netcoreapp3.1` tracer builds, invoke `AssemblyBuilder.DefineDynamicAssembly` from a one-shot `DynamicMethod` associated with the target manifest module. This selects the target load context on .NET Core 2.1 through .NET 5, where contextual reflection cannot solve this case. - Keep the .NET Framework path unchanged. - Keep the existing cache key based on the exact proxy-definition and target `Type` identities. Because `Type` identity includes its load context, the cache already isolates types loaded into different contexts. A new test verifies reuse within one context and separation across contexts containing assemblies with the same identity. - Use two lightweight `netstandard2.0` fixture projects to provide the target and its duplicated dependency. These projects are test-only build inputs and add no dependencies to the production `Datadog.Trace` assembly or package. - Regenerate the app trimming descriptor to include `AssemblyLoadContext.ContextualReflectionScope`. ## Test coverage - Focused cross-ALC tests passed on x64 under Rosetta for `netcoreapp2.1`, `netcoreapp3.0`, `netcoreapp3.1`, `net5.0`, `net6.0`, and `net10.0`. - Full DuckTyping suites passed on x64 for `netcoreapp2.1` (10,925 passed), `netcoreapp3.1` (10,926 passed), and `net6.0` (10,926 passed). - `Datadog.Trace` compiled successfully for `net461` with 0 warnings and 0 errors. ## Other details Includes and extends the reproduction from #9156. <!-- Fixes #{issue} --> <!--⚠️ Note: Where possible, please obtain 2 approvals prior to merging. Unless CODEOWNERS specifies otherwise, for external teams it is typically best to have one review from a team member, and one review from apm-dotnet. Trivial changes do not require 2 reviews. MergeQueue is NOT enabled in this repository. If you have write access to the repo, the PR has 1-2 approvals (see above), and all of the required checks have passed, you can use the Squash and Merge button to merge the PR. If you don't have write access, or you need help, reach out in the #apm-dotnet channel in Slack. --> --------- Co-authored-by: pablo.martinezbernardo <pablo.martinezbernardo@datadoghq.com>
Summary of changes
Reason for change
Implementation details
Test coverage
Other details