Skip to content

Commit 2a8ea8a

Browse files
Fix edge case with loading instrumentations (#6815)
## Summary of changes This PR ignores additional modules for consideration when injecting our startup hook (which initializes the rest of the library's instrumentations). This avoids a rare issue with the injection of the startup hook. ## Reason for change This fixes an occasional issue I've encountered where small .NET 8 apps fail to load instrumentations, which I've tracked down to the startup hook being injected too early in `System.Security.*` modules. This results in a failure to call our startup hook, as shown here: ``` 04/02/25 03:23:16.488 PM [428784|422832] [error] An error occured in the managed loader: System.Runtime.InteropServices.MarshalDirectiveException: Cannot marshal 'parameter #1': Cannot marshal managed types when the runtime marshalling system is disabled. at __DDVoidMethodType__.GetAssemblyAndSymbolsBytes(IntPtr&, Int32&, IntPtr&, Int32&) at __DDVoidMethodType__.__DDInvokeLoader__() at __DDVoidMethodType__.__DDVoidMethodCall__() ``` ## Implementation details Adds the following module names to ignore when deciding whether to inject the startup hook: - `System.Security.AccessControl` - `System.Security.Claims` - `System.Security.Principal.Windows` After making this change I observed in my test console application that the startup hook was correctly inserted into `Program.Main()` ## Test coverage Relies on existing tests. ## Other details
1 parent 2b5c978 commit 2a8ea8a

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

tracer/src/Datadog.Tracer.Native/cor_profiler.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1638,6 +1638,9 @@ HRESULT STDMETHODCALLTYPE CorProfiler::JITCompilationStarted(FunctionID function
16381638
}
16391639
else if (module_metadata->assemblyName == WStr("System") ||
16401640
module_metadata->assemblyName == WStr("System.Net.Http") ||
1641+
module_metadata->assemblyName == WStr("System.Security.AccessControl") ||
1642+
module_metadata->assemblyName == WStr("System.Security.Claims") ||
1643+
module_metadata->assemblyName == WStr("System.Security.Principal.Windows") ||
16411644
module_metadata->assemblyName == WStr("System.Linq")) // Avoid instrumenting System.Linq which is used as part of the async state machine
16421645
{
16431646
valid_startup_hook_callsite = false;

0 commit comments

Comments
 (0)