Skip to content

pass module version id to instrumentation wrappers #488

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 33 additions & 33 deletions integrations.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=1.6.2.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
"type": "Datadog.Trace.ClrProfiler.Integrations.AdoNetIntegration",
"method": "ExecuteDbDataReader",
"signature": "00 04 1C 1C 08 08 08"
"signature": "00 05 1C 1C 08 08 08 0A"
}
},
{
Expand All @@ -47,7 +47,7 @@
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=1.6.2.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
"type": "Datadog.Trace.ClrProfiler.Integrations.AdoNetIntegration",
"method": "ExecuteDbDataReader",
"signature": "00 04 1C 1C 08 08 08"
"signature": "00 05 1C 1C 08 08 08 0A"
}
},
{
Expand All @@ -72,7 +72,7 @@
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=1.6.2.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
"type": "Datadog.Trace.ClrProfiler.Integrations.AdoNetIntegration",
"method": "ExecuteDbDataReaderAsync",
"signature": "00 05 1C 1C 08 1C 08 08"
"signature": "00 06 1C 1C 08 1C 08 08 0A"
}
},
{
Expand All @@ -97,7 +97,7 @@
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=1.6.2.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
"type": "Datadog.Trace.ClrProfiler.Integrations.AdoNetIntegration",
"method": "ExecuteDbDataReaderAsync",
"signature": "00 05 1C 1C 08 1C 08 08"
"signature": "00 06 1C 1C 08 1C 08 08 0A"
}
}
]
Expand Down Expand Up @@ -131,7 +131,7 @@
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=1.6.2.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
"type": "Datadog.Trace.ClrProfiler.Integrations.AspNetCoreMvc2Integration",
"method": "BeforeAction",
"signature": "00 06 01 1C 1C 1C 1C 08 08"
"signature": "00 07 01 1C 1C 1C 1C 08 08 0A"
}
},
{
Expand Down Expand Up @@ -160,7 +160,7 @@
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=1.6.2.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
"type": "Datadog.Trace.ClrProfiler.Integrations.AspNetCoreMvc2Integration",
"method": "AfterAction",
"signature": "00 06 01 1C 1C 1C 1C 08 08"
"signature": "00 07 01 1C 1C 1C 1C 08 08 0A"
}
},
{
Expand All @@ -186,7 +186,7 @@
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=1.6.2.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
"type": "Datadog.Trace.ClrProfiler.Integrations.AspNetCoreMvc2Integration",
"method": "Rethrow",
"signature": "00 03 01 1C 08 08"
"signature": "00 04 01 1C 08 08 0A"
}
}
]
Expand Down Expand Up @@ -220,7 +220,7 @@
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=1.6.2.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
"type": "Datadog.Trace.ClrProfiler.Integrations.AspNetMvcIntegration",
"method": "BeginInvokeAction",
"signature": "00 07 1C 1C 1C 1C 1C 1C 08 08"
"signature": "00 08 1C 1C 1C 1C 1C 1C 08 08 0A"
}
},
{
Expand All @@ -246,7 +246,7 @@
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=1.6.2.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
"type": "Datadog.Trace.ClrProfiler.Integrations.AspNetMvcIntegration",
"method": "EndInvokeAction",
"signature": "00 04 02 1C 1C 08 08"
"signature": "00 05 02 1C 1C 08 08 0A"
}
}
]
Expand Down Expand Up @@ -276,7 +276,7 @@
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=1.6.2.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
"type": "Datadog.Trace.ClrProfiler.Integrations.AspNetWebApi2Integration",
"method": "ExecuteAsync",
"signature": "00 05 1C 1C 1C 1C 08 08"
"signature": "00 06 1C 1C 1C 1C 08 08 0A"
}
}
]
Expand Down Expand Up @@ -307,7 +307,7 @@
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=1.6.2.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
"type": "Datadog.Trace.ClrProfiler.Integrations.ElasticsearchNet5Integration",
"method": "CallElasticsearch",
"signature": "10 01 04 1C 1C 1C 08 08"
"signature": "10 01 05 1C 1C 1C 08 08 0A"
}
},
{
Expand All @@ -334,7 +334,7 @@
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=1.6.2.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
"type": "Datadog.Trace.ClrProfiler.Integrations.ElasticsearchNet5Integration",
"method": "CallElasticsearchAsync",
"signature": "10 01 05 1C 1C 1C 1C 08 08"
"signature": "10 01 06 1C 1C 1C 1C 08 08 0A"
}
}
]
Expand Down Expand Up @@ -365,7 +365,7 @@
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=1.6.2.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
"type": "Datadog.Trace.ClrProfiler.Integrations.ElasticsearchNet6Integration",
"method": "CallElasticsearch",
"signature": "10 01 04 1C 1C 1C 08 08"
"signature": "10 01 05 1C 1C 1C 08 08 0A"
}
},
{
Expand All @@ -392,7 +392,7 @@
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=1.6.2.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
"type": "Datadog.Trace.ClrProfiler.Integrations.ElasticsearchNet6Integration",
"method": "CallElasticsearchAsync",
"signature": "10 01 05 1C 1C 1C 1C 08 08"
"signature": "10 01 06 1C 1C 1C 1C 08 08 0A"
}
}
]
Expand Down Expand Up @@ -426,7 +426,7 @@
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=1.6.2.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
"type": "Datadog.Trace.ClrProfiler.Integrations.GraphQLIntegration",
"method": "Validate",
"signature": "00 09 1C 1C 1C 1C 1C 1C 1C 1C 08 08"
"signature": "00 0A 1C 1C 1C 1C 1C 1C 1C 1C 08 08 0A"
}
},
{
Expand All @@ -450,7 +450,7 @@
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=1.6.2.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
"type": "Datadog.Trace.ClrProfiler.Integrations.GraphQLIntegration",
"method": "ExecuteAsync",
"signature": "00 04 1C 1C 1C 08 08"
"signature": "00 05 1C 1C 1C 08 08 0A"
}
}
]
Expand Down Expand Up @@ -480,7 +480,7 @@
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=1.6.2.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
"type": "Datadog.Trace.ClrProfiler.Integrations.HttpMessageHandlerIntegration",
"method": "HttpMessageHandler_SendAsync",
"signature": "00 05 1C 1C 1C 1C 08 08"
"signature": "00 06 1C 1C 1C 1C 08 08 0A"
}
},
{
Expand All @@ -505,7 +505,7 @@
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=1.6.2.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
"type": "Datadog.Trace.ClrProfiler.Integrations.HttpMessageHandlerIntegration",
"method": "HttpClientHandler_SendAsync",
"signature": "00 05 1C 1C 1C 1C 08 08"
"signature": "00 06 1C 1C 1C 1C 08 08 0A"
}
}
]
Expand Down Expand Up @@ -535,7 +535,7 @@
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=1.6.2.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
"type": "Datadog.Trace.ClrProfiler.Integrations.MongoDbIntegration",
"method": "Execute",
"signature": "00 05 1C 1C 1C 1C 08 08"
"signature": "00 06 1C 1C 1C 1C 08 08 0A"
}
},
{
Expand All @@ -560,7 +560,7 @@
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=1.6.2.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
"type": "Datadog.Trace.ClrProfiler.Integrations.MongoDbIntegration",
"method": "ExecuteGeneric",
"signature": "00 05 1C 1C 1C 1C 08 08"
"signature": "00 06 1C 1C 1C 1C 08 08 0A"
}
},
{
Expand All @@ -585,7 +585,7 @@
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=1.6.2.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
"type": "Datadog.Trace.ClrProfiler.Integrations.MongoDbIntegration",
"method": "ExecuteAsync",
"signature": "00 05 1C 1C 1C 1C 08 08"
"signature": "00 06 1C 1C 1C 1C 08 08 0A"
}
},
{
Expand All @@ -610,7 +610,7 @@
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=1.6.2.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
"type": "Datadog.Trace.ClrProfiler.Integrations.MongoDbIntegration",
"method": "ExecuteAsyncGeneric",
"signature": "00 05 1C 1C 1C 1C 08 08"
"signature": "00 06 1C 1C 1C 1C 08 08 0A"
}
}
]
Expand Down Expand Up @@ -644,7 +644,7 @@
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=1.6.2.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
"type": "Datadog.Trace.ClrProfiler.Integrations.ServiceStackRedisIntegration",
"method": "SendReceive",
"signature": "10 01 07 1E 00 1C 1D 1D 05 1C 1C 02 08 08"
"signature": "10 01 08 1E 00 1C 1D 1D 05 1C 1C 02 08 08 0A"
}
}
]
Expand Down Expand Up @@ -677,7 +677,7 @@
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=1.6.2.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
"type": "Datadog.Trace.ClrProfiler.Integrations.StackExchange.Redis.ConnectionMultiplexer",
"method": "ExecuteSyncImpl",
"signature": "10 01 06 1E 00 1C 1C 1C 1C 08 08"
"signature": "10 01 07 1E 00 1C 1C 1C 1C 08 08 0A"
}
},
{
Expand Down Expand Up @@ -705,7 +705,7 @@
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=1.6.2.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
"type": "Datadog.Trace.ClrProfiler.Integrations.StackExchange.Redis.ConnectionMultiplexer",
"method": "ExecuteSyncImpl",
"signature": "10 01 06 1E 00 1C 1C 1C 1C 08 08"
"signature": "10 01 07 1E 00 1C 1C 1C 1C 08 08 0A"
}
},
{
Expand Down Expand Up @@ -734,7 +734,7 @@
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=1.6.2.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
"type": "Datadog.Trace.ClrProfiler.Integrations.StackExchange.Redis.ConnectionMultiplexer",
"method": "ExecuteAsyncImpl",
"signature": "10 01 07 1C 1C 1C 1C 1C 1C 08 08"
"signature": "10 01 08 1C 1C 1C 1C 1C 1C 08 08 0A"
}
},
{
Expand Down Expand Up @@ -763,7 +763,7 @@
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=1.6.2.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
"type": "Datadog.Trace.ClrProfiler.Integrations.StackExchange.Redis.ConnectionMultiplexer",
"method": "ExecuteAsyncImpl",
"signature": "10 01 07 1C 1C 1C 1C 1C 1C 08 08"
"signature": "10 01 08 1C 1C 1C 1C 1C 1C 08 08 0A"
}
},
{
Expand Down Expand Up @@ -791,7 +791,7 @@
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=1.6.2.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
"type": "Datadog.Trace.ClrProfiler.Integrations.StackExchange.Redis.RedisBatch",
"method": "ExecuteAsync",
"signature": "10 01 06 1C 1C 1C 1C 1C 08 08"
"signature": "10 01 07 1C 1C 1C 1C 1C 08 08 0A"
}
},
{
Expand Down Expand Up @@ -819,7 +819,7 @@
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=1.6.2.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
"type": "Datadog.Trace.ClrProfiler.Integrations.StackExchange.Redis.RedisBatch",
"method": "ExecuteAsync",
"signature": "10 01 06 1C 1C 1C 1C 1C 08 08"
"signature": "10 01 07 1C 1C 1C 1C 1C 08 08 0A"
}
}
]
Expand Down Expand Up @@ -849,7 +849,7 @@
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=1.6.2.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
"type": "Datadog.Trace.ClrProfiler.Integrations.WcfIntegration",
"method": "HandleRequest",
"signature": "00 05 02 1C 1C 1C 08 08"
"signature": "00 06 02 1C 1C 1C 08 08 0A"
}
}
]
Expand Down Expand Up @@ -877,7 +877,7 @@
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=1.6.2.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
"type": "Datadog.Trace.ClrProfiler.Integrations.WebRequestIntegration",
"method": "GetResponse",
"signature": "00 03 1C 1C 08 08"
"signature": "00 04 1C 1C 08 08 0A"
}
},
{
Expand All @@ -900,7 +900,7 @@
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=1.6.2.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
"type": "Datadog.Trace.ClrProfiler.Integrations.WebRequestIntegration",
"method": "GetResponse",
"signature": "00 03 1C 1C 08 08"
"signature": "00 04 1C 1C 08 08 0A"
}
},
{
Expand All @@ -923,7 +923,7 @@
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=1.6.2.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
"type": "Datadog.Trace.ClrProfiler.Integrations.WebRequestIntegration",
"method": "GetResponseAsync",
"signature": "00 03 1C 1C 08 08"
"signature": "00 04 1C 1C 08 08 0A"
}
}
]
Expand Down
18 changes: 14 additions & 4 deletions src/Datadog.Trace.ClrProfiler.Managed/Emit/MethodBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.InteropServices;
using Datadog.Trace.ClrProfiler.Helpers;
using Datadog.Trace.Logging;
using Sigil;
Expand Down Expand Up @@ -53,14 +54,23 @@ private MethodBuilder(Module resolutionModule, int mdToken, int opCode, string m
_forceMethodDefResolve = false;
}

public static MethodBuilder<TDelegate> Start(Assembly resolutionAssembly, int mdToken, int opCode, string methodName)
public static MethodBuilder<TDelegate> Start(Guid moduleVersionId, int mdToken, int opCode, string methodName)
{
// This method is deprecated in favor of the newer ModuleVersionId lookup
return new MethodBuilder<TDelegate>(resolutionAssembly.ManifestModule, mdToken, opCode, methodName);
return new MethodBuilder<TDelegate>(moduleVersionId, mdToken, opCode, methodName);
}

public static MethodBuilder<TDelegate> Start(Guid moduleVersionId, int mdToken, int opCode, string methodName)
public static MethodBuilder<TDelegate> Start(long moduleVersionPtr, int mdToken, int opCode, string methodName)
{
var ptr = new IntPtr(moduleVersionPtr);

#if NET45
// deprecated
var moduleVersionId = (Guid)Marshal.PtrToStructure(ptr, typeof(Guid));
#else
// added in net451
var moduleVersionId = Marshal.PtrToStructure<Guid>(ptr);
#endif

return new MethodBuilder<TDelegate>(moduleVersionId, mdToken, opCode, methodName);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public static class AdoNetIntegration
/// <param name="behavior">A value from <see cref="CommandBehavior"/>.</param>
/// <param name="opCode">The OpCode used in the original method call.</param>
/// <param name="mdToken">The mdToken of the original method call.</param>
/// <param name="moduleVersionPtr">A pointer to the module version GUID.</param>
/// <returns>The value returned by the instrumented method.</returns>
[InterceptMethod(
TargetAssembly = "System.Data", // .NET Framework
Expand All @@ -39,7 +40,12 @@ public static class AdoNetIntegration
TargetSignatureTypes = new[] { "System.Data.Common.DbDataReader", "System.Data.CommandBehavior" },
TargetMinimumVersion = Major4,
TargetMaximumVersion = Major4)]
public static object ExecuteDbDataReader(object @this, int behavior, int opCode, int mdToken)
public static object ExecuteDbDataReader(
object @this,
int behavior,
int opCode,
int mdToken,
long moduleVersionPtr)
{
var command = (DbCommand)@this;
var commandBehavior = (CommandBehavior)behavior;
Expand Down Expand Up @@ -72,6 +78,7 @@ public static object ExecuteDbDataReader(object @this, int behavior, int opCode,
/// <param name="cancellationTokenSource">A cancellation token source that can be used to cancel the async operation.</param>
/// <param name="opCode">The OpCode used in the original method call.</param>
/// <param name="mdToken">The mdToken of the original method call.</param>
/// <param name="moduleVersionPtr">A pointer to the module version GUID.</param>
/// <returns>The value returned by the instrumented method.</returns>
[InterceptMethod(
TargetAssembly = "System.Data", // .NET Framework
Expand All @@ -85,7 +92,13 @@ public static object ExecuteDbDataReader(object @this, int behavior, int opCode,
TargetSignatureTypes = new[] { "System.Threading.Tasks.Task`1<System.Data.Common.DbDataReader>", "System.Data.CommandBehavior", "System.Threading.CancellationToken" },
TargetMinimumVersion = Major4,
TargetMaximumVersion = Major4)]
public static object ExecuteDbDataReaderAsync(object @this, int behavior, object cancellationTokenSource, int opCode, int mdToken)
public static object ExecuteDbDataReaderAsync(
object @this,
int behavior,
object cancellationTokenSource,
int opCode,
int mdToken,
long moduleVersionPtr)
{
var tokenSource = cancellationTokenSource as CancellationTokenSource;
var cancellationToken = tokenSource?.Token ?? CancellationToken.None;
Expand Down
Loading