Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamically created assemblies will not be instrumented by the .NET Agent in .NET 7 #1295

Closed
angelatan2 opened this issue Oct 28, 2022 · 7 comments

Comments

@angelatan2
Copy link
Contributor

Our agent support for .NET 7 instrumentation may depend on the release of the resolution of
dotnet/runtime#77068
dotnet/runtime#77533

@angelatan2 angelatan2 added this to the .NET 7 GA Support milestone Oct 28, 2022
@workato-integration
Copy link

@angelatan2 angelatan2 changed the title dynamically load assemblies (manually, or via several dependency injection libraries) may/will not see any expected instrumentation for those assemblies for our Agent in .NET 7. Dynamically load assemblies (manually, or via several dependency injection libraries) may/will not see any expected instrumentation for those assemblies for our Agent in .NET 7. Oct 28, 2022
@angelatan2 angelatan2 pinned this issue Oct 28, 2022
@workato-integration workato-integration bot changed the title Dynamically load assemblies (manually, or via several dependency injection libraries) may/will not see any expected instrumentation for those assemblies for our Agent in .NET 7. Dynamically created assemblies (manually, or via several dependency injection libraries) may/will not see any expected instrumentation for those assemblies for our Agent in .NET 7. Nov 28, 2022
@workato-integration
Copy link

Jira CommentId: 116263
Commented by angelatan:

Dependencies on .NET 7 patch release by Microsoft. (Target: Jan 2023)

@workato-integration workato-integration bot changed the title Dynamically created assemblies (manually, or via several dependency injection libraries) may/will not see any expected instrumentation for those assemblies for our Agent in .NET 7. Dynamically created assemblies will not generate any instrumentation for those assemblies for our Agent in .NET 7. Nov 28, 2022
@JcolemanNR JcolemanNR changed the title Dynamically created assemblies will not generate any instrumentation for those assemblies for our Agent in .NET 7. Dynamically created assemblies will not be instrumented by Agent in .NET 7 Dec 7, 2022
@JcolemanNR JcolemanNR changed the title Dynamically created assemblies will not be instrumented by Agent in .NET 7 Dynamically created assemblies will not be instrumented by the .NET Agent in .NET 7 Dec 7, 2022
@workato-integration
Copy link

Jira CommentId: 144280
Commented by angelatan:

1/30/2023

The fix was merged a couple of months ago, but it hasn't been included in any releases yet. Microsoft has only pushed out security fixes since then. We are keeping an eye on release notes as they come out.

@angelatan2 angelatan2 removed this from the .NET 7 GA Support milestone Feb 14, 2023
@workato-integration
Copy link

Jira CommentId: 153202
Commented by chynes:

Somehow I missed that this was included in the 7.0.1 release in December: [https://github.com/dotnet/runtime/issues?q=milestone%3A7.0.1+is%3Aclosed+label%3Aservicing-approved+]

This is ready for verification.

@workato-integration
Copy link

Jira CommentId: 171860
Commented by mtippin:

After quite a bit of testing, I've determined that the agent will not instrument dynamically generated assemblies at all.

Tried under .NET 6 and .NET 7 (latest releases), using attribute-based instrumentation and XML instrumentation. In every case, the dynamically generated method was not instrumented. 

When using attribute-based instrumentation, the profiler acted like it was trying to reJIT the dynamic method but didn't do anything:
[Trace] 2023-03-21 21:27:34 JITCompilationStarted. 140717006813776
[Trace] 2023-03-21 21:27:34 Possibly instrumenting: (Module: RefEmit_InMemoryManifestModule, AppDomain: clrhost)[DynamicAssembly]DynamicType.MyDynamicMethod(System.Int32,System.Int32)
[Debug] 2023-03-21 21:27:34 Request reJIT: [140717006813776] (Module: RefEmit_InMemoryManifestModule, AppDomain: clrhost)[DynamicAssembly]DynamicType.MyDynamicMethod(System.Int32,System.Int32)
[Trace] 2023-03-21 21:27:34 JITCompilationStartedFinished. 140717006813776
When using XML-based instrumentation, the profiler logged an exception:
[Trace] 2023-03-22 16:59:26 JITCompilationStarted. 140717310921824
[Error] 2023-03-22 16:59:26 Win32 function call failed. Function: _profilerInfo->GetILFunctionBody HRESULT: 0x80131351
[Error] 2023-03-22 16:59:26 An exception was thrown while getting details about a function.
[Trace] 2023-03-22 16:59:26 JITCompilationStartedFinished. 140717310921824
I did verify, however, that calling an instrumented method from a dynamically generated method does instrument the instrumented method as expected. 

There's a newer ICorProfiler interface (ICorProfiler8) that includes methods specifically about [JIT compilation of dynamic methods|https://learn.microsoft.com/en-us/dotnet/framework/unmanaged-api/profiling/icorprofilercallback8-dynamicmethodjitcompilationstarted-method]. Perhaps we should consider implementing support for those methods - though I have no idea if that will resolve this issue or not.

@workato-integration
Copy link

Jira CommentId: 171860
Commented by mtippin:

After quite a bit of testing, I've determined that the agent will not instrument dynamically generated assemblies at all.

Tried under .NET 6 and .NET 7 (latest releases), using attribute-based instrumentation and XML instrumentation. In every case, the dynamically generated method was not instrumented. 

When using attribute-based instrumentation, the profiler acted like it was trying to reJIT the dynamic method but didn't do anything:

 
{code:java}
[Trace] 2023-03-21 21:27:34 JITCompilationStarted. 140717006813776
[Trace] 2023-03-21 21:27:34 Possibly instrumenting: (Module: RefEmit_InMemoryManifestModule, AppDomain: clrhost)[DynamicAssembly]DynamicType.MyDynamicMethod(System.Int32,System.Int32)
[Debug] 2023-03-21 21:27:34 Request reJIT: [140717006813776] (Module: RefEmit_InMemoryManifestModule, AppDomain: clrhost)[DynamicAssembly]DynamicType.MyDynamicMethod(System.Int32,System.Int32)
[Trace] 2023-03-21 21:27:34 JITCompilationStartedFinished. 140717006813776{code}
When using XML-based instrumentation, the profiler logged an exception:
{code:java}
[Trace] 2023-03-22 16:59:26 JITCompilationStarted. 140717310921824
[Error] 2023-03-22 16:59:26 Win32 function call failed. Function: _profilerInfo->GetILFunctionBody HRESULT: 0x80131351
[Error] 2023-03-22 16:59:26 An exception was thrown while getting details about a function.
[Trace] 2023-03-22 16:59:26 JITCompilationStartedFinished. 140717310921824{code}
I did verify, however, that calling an instrumented method from a dynamically generated method does instrument the instrumented method as expected. 

There's a newer ICorProfiler interface (ICorProfiler8) that includes methods specifically about [JIT compilation of dynamic methods|https://learn.microsoft.com/en-us/dotnet/framework/unmanaged-api/profiling/icorprofilercallback8-dynamicmethodjitcompilationstarted-method]. Perhaps we should consider implementing support for those methods - though I have no idea if that will resolve this issue or not.

@workato-integration
Copy link

This issue won't be actioned.

@angelatan2 angelatan2 unpinned this issue Apr 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant