opentelemetry-dotnet-instrumentation icon indicating copy to clipboard operation
opentelemetry-dotnet-instrumentation copied to clipboard

DbCommand byte code instrumentation

Open Kielek opened this issue 3 years ago • 9 comments
trafficstars

Feature Request

Are you requesting automatic instrumentation for a framework or library? Please describe.

DbCommand intrumentation. It should cover also Oracle.ManagedDataAccess.dll library requested in #1117 but it cover more libraries not only Oracle.

Describe the solution you'd like Cover all DbCommand based libraries.

Describe alternatives you've considered Have dedicated instrumentations for specific libraries as in upstream side: https://github.com/DataDog/dd-trace-dotnet/tree/master/tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/AdoNet

Additional context Verify how it will be working with Npgsql. We have source code instrumentation there.

Kielek avatar Aug 24 '22 16:08 Kielek

Hi @Kielek , during my prototype, I noticed System.Data got loaded in shared appdomain on .NET framework.

[2022-08-21T15:54:07.404708400Z] [33532|35180] [debug] Comparing signature for method: System.Data.Common.DbCommand..ctor
[2022-08-21T15:54:07.404737400Z] [33532|35180] [debug] Enqueue for ReJIT [ModuleId=140712098334424, MethodDef=06002de7, AppDomainId=140713692092832, IsDomainNeutral=1, Assembly=System.Data, Type=System.Data.Common.DbCommand, Method=.ctor, Signature=200001]
[2022-08-21T15:54:07.404761800Z] [33532|35180] [debug] ModuleLoadFinished stored metadata for 140712098334424 System.Data AppDomain 140713692092832 EE Shared Assembly Repository
...
[2022-08-21T15:54:08.943335000Z] [33532|35180] [debug] GetReJITParameters: [moduleId: 140712098334424, methodId: 100675047]
[2022-08-21T15:54:08.947088900Z] [33532|35180] [debug] *** CallTarget_RewriterCallback() Start: System.Data.Common.DbCommand..ctor() [IsVoid=1, IsStatic=0, IntegrationType=OpenTelemetry.AutoInstrumentation.Instrumentations.Odp.DbCmdClientIntegration, Arguments=0]
[2022-08-21T15:54:08.947106800Z] [33532|35180] [warning] *** CallTarget_RewriterCallback() skipping method: Method replacement found but the managed profiler has not yet been loaded into AppDomain with id=140713692092832 token=100675047 caller_name=System.Data.Common.DbCommand..ctor()

I remember the current bytecode instrumentation has a limitation on assembly in shared appdomain. Could you please confirm?

muhaook avatar Aug 26 '22 09:08 muhaook

@muhaook could you please share the full logs for this? It seems that we failed to inject the managed code on the non-shared app-domain I'm not sure why.

pjanotti avatar Aug 27 '22 01:08 pjanotti

@pjanotti , as far as I know, below means it is a shared appdomain

[2022-08-21T15:54:07.404761800Z] [33532|35180] [debug] ModuleLoadFinished stored metadata for 140712098334424 System.Data AppDomain 140713692092832 EE Shared Assembly Repository

Attached please find the full logs dotnet-tracer-native-w3wp-33532.log

muhaook avatar Aug 27 '22 09:08 muhaook

@muhaook thanks for the logs. I think the root of the problem is:

[2022-08-21T15:54:05.429461400Z] [33532|36148] [info] AssemblyLoadFinished: OpenTelemetry.AutoInstrumentation.dll was not loaded domain-neutral

We still have to understand why this is happening in this case...

pjanotti avatar Aug 28 '22 03:08 pjanotti

Hi @muhaook, this was fixed, see #1134 and respective PR #1234. In order for the instrumentation assembly (OpenTelemetry.AutoInstrumentation.dll) to be loaded as domain neutral you need to registry it in the GAC.

I'm going to close this issue. Let's know if you hit other problems.

pjanotti avatar Oct 26 '22 19:10 pjanotti

@RassK @pellared adding/removing OpenTelemetry.AutoInstrumentation.dll to the GAC via the setup script seems a good idea (see previous comment).

pjanotti avatar Oct 26 '22 19:10 pjanotti

@pjanotti I am not sure if this issue should be closed. The issue reported by @muhaook was reported (and closed) here: https://github.com/open-telemetry/opentelemetry-dotnet-instrumentation/issues/1117

This issue is about adding generic bytecode instrumentation for System.Data.Common.DbCommand.

pellared avatar Oct 26 '22 20:10 pellared

Makes sense @pellared I was thinking about failing to load as domain-neutral and that is fixed, but, the issue is to track adding DbCommand. Now it is unblocked, one can write it :)

pjanotti avatar Oct 27 '22 16:10 pjanotti

Facilitating installation of required assemblies in the GAC is tracked via #1823

pjanotti avatar Dec 21 '22 23:12 pjanotti