Skip to content

Commit 24adfab

Browse files
autogenerate integrations.json (#232)
* add [InterceptMethodAttribute] and [InterceptTypeAttribute] * add new project to generate integration definitions JSON from attributes * remove Samples.MongoDB project (that was meant for a different branch) * reorder integrations alphabetically * wip * add [InterceptMethod] to all integrations * rename RedisNativeClient to ServiceStackRedisIntegration and move up to Integrations folder * rename Pipeline to ElasticsearchNetIntegration and move up to Integrations folder * rename Base to StackExchangeRedisHelper and make it a static class * rename static class Redis to RedisHelper * target .NET Framework so we can export the ASP.NET integrations (MVC, Web API) * order integrations alphabetically (second attempt) * fix integration name * add missing integration attribute * clean up code * clean up code * revert method name because we look up by name and we don't use signature for overload resolution * fix signature for generic methods * replace generate integration.json * fix brace location (StyleCop) * add missing xml-doc comments * add comments * add IMAGE_CEE_CS_CALLCONV_GENERIC constant
1 parent fc4233f commit 24adfab

21 files changed

+405
-102
lines changed

.gitignore

-2
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,6 @@ paket-files/
259259
# Python Tools for Visual Studio (PTVS)
260260
__pycache__/
261261
*.pyc
262-
# Cake binaries
263-
tools/
264262
# vscode
265263
.vscode/
266264
# Benchmark results

Datadog.Trace.sln

+21
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,14 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Samples.Elasticsearch", "sa
125125
EndProject
126126
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Samples.AspNetMvc4", "samples\Samples.AspNetMvc4\Samples.AspNetMvc4.csproj", "{6D86109F-B7C9-477D-86D7-45735A3A0818}"
127127
EndProject
128+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tools", "tools", "{5D8E1F81-B820-4736-B797-271B0FE787EE}"
129+
ProjectSection(SolutionItems) = preProject
130+
tools\Directory.Build.props = tools\Directory.Build.props
131+
tools\GlobalSuppressions.cs = tools\GlobalSuppressions.cs
132+
EndProjectSection
133+
EndProject
134+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GenerateIntegrationDefinitions", "tools\GenerateIntegrationDefinitions\GenerateIntegrationDefinitions.csproj", "{5B844A49-CA3C-42CB-AD31-E44CD73FD1A3}"
135+
EndProject
128136
Global
129137
GlobalSection(SolutionConfigurationPlatforms) = preSolution
130138
Debug|Any CPU = Debug|Any CPU
@@ -399,6 +407,18 @@ Global
399407
{6D86109F-B7C9-477D-86D7-45735A3A0818}.Release|x64.Build.0 = Release|Any CPU
400408
{6D86109F-B7C9-477D-86D7-45735A3A0818}.Release|x86.ActiveCfg = Release|Any CPU
401409
{6D86109F-B7C9-477D-86D7-45735A3A0818}.Release|x86.Build.0 = Release|Any CPU
410+
{5B844A49-CA3C-42CB-AD31-E44CD73FD1A3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
411+
{5B844A49-CA3C-42CB-AD31-E44CD73FD1A3}.Debug|Any CPU.Build.0 = Debug|Any CPU
412+
{5B844A49-CA3C-42CB-AD31-E44CD73FD1A3}.Debug|x64.ActiveCfg = Debug|Any CPU
413+
{5B844A49-CA3C-42CB-AD31-E44CD73FD1A3}.Debug|x64.Build.0 = Debug|Any CPU
414+
{5B844A49-CA3C-42CB-AD31-E44CD73FD1A3}.Debug|x86.ActiveCfg = Debug|Any CPU
415+
{5B844A49-CA3C-42CB-AD31-E44CD73FD1A3}.Debug|x86.Build.0 = Debug|Any CPU
416+
{5B844A49-CA3C-42CB-AD31-E44CD73FD1A3}.Release|Any CPU.ActiveCfg = Release|Any CPU
417+
{5B844A49-CA3C-42CB-AD31-E44CD73FD1A3}.Release|Any CPU.Build.0 = Release|Any CPU
418+
{5B844A49-CA3C-42CB-AD31-E44CD73FD1A3}.Release|x64.ActiveCfg = Release|Any CPU
419+
{5B844A49-CA3C-42CB-AD31-E44CD73FD1A3}.Release|x64.Build.0 = Release|Any CPU
420+
{5B844A49-CA3C-42CB-AD31-E44CD73FD1A3}.Release|x86.ActiveCfg = Release|Any CPU
421+
{5B844A49-CA3C-42CB-AD31-E44CD73FD1A3}.Release|x86.Build.0 = Release|Any CPU
402422
EndGlobalSection
403423
GlobalSection(SolutionProperties) = preSolution
404424
HideSolutionNode = FALSE
@@ -427,6 +447,7 @@ Global
427447
{F5B27CC4-1DF6-4ECD-A4FD-8200152F9A5A} = {AA6F5582-3B71-49AC-AA39-8F7815AC46BE}
428448
{C98950B1-DC4B-43DA-974F-EF2CF325EC2B} = {AA6F5582-3B71-49AC-AA39-8F7815AC46BE}
429449
{6D86109F-B7C9-477D-86D7-45735A3A0818} = {AA6F5582-3B71-49AC-AA39-8F7815AC46BE}
450+
{5B844A49-CA3C-42CB-AD31-E44CD73FD1A3} = {5D8E1F81-B820-4736-B797-271B0FE787EE}
430451
EndGlobalSection
431452
GlobalSection(ExtensibilityGlobals) = postSolution
432453
SolutionGuid = {160A1D00-1F5B-40F8-A155-621B4459D78F}

integrations.json

+71-71
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[
22
{
3-
"name": "aspNetCoreMvc2",
3+
"name": "AspNetCoreMvc2",
44
"method_replacements": [
55
{
66
"caller": {
@@ -15,7 +15,7 @@
1515
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=0.5.2.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
1616
"type": "Datadog.Trace.ClrProfiler.Integrations.AspNetCoreMvc2Integration",
1717
"method": "BeforeAction",
18-
"signature": [ 0, 4, 1, 28, 28, 28, 28 ]
18+
"signature": "00 04 01 1C 1C 1C 1C"
1919
}
2020
},
2121
{
@@ -31,13 +31,13 @@
3131
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=0.5.2.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
3232
"type": "Datadog.Trace.ClrProfiler.Integrations.AspNetCoreMvc2Integration",
3333
"method": "AfterAction",
34-
"signature": [ 0, 4, 1, 28, 28, 28, 28 ]
34+
"signature": "00 04 01 1C 1C 1C 1C"
3535
}
3636
}
3737
]
3838
},
3939
{
40-
"name": "aspNetMvc",
40+
"name": "AspNetMvc",
4141
"method_replacements": [
4242
{
4343
"caller": {
@@ -52,7 +52,7 @@
5252
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=0.5.2.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
5353
"type": "Datadog.Trace.ClrProfiler.Integrations.AspNetMvcIntegration",
5454
"method": "BeginInvokeAction",
55-
"signature": [ 0, 5, 28, 28, 28, 28, 28, 28 ]
55+
"signature": "00 05 1C 1C 1C 1C 1C 1C"
5656
}
5757
},
5858
{
@@ -68,13 +68,13 @@
6868
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=0.5.2.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
6969
"type": "Datadog.Trace.ClrProfiler.Integrations.AspNetMvcIntegration",
7070
"method": "EndInvokeAction",
71-
"signature": [ 0, 2, 2, 28, 28 ]
71+
"signature": "00 02 02 1C 1C"
7272
}
7373
}
7474
]
7575
},
7676
{
77-
"name": "aspNetWebApi2",
77+
"name": "AspNetWebApi2",
7878
"method_replacements": [
7979
{
8080
"caller": {},
@@ -87,7 +87,65 @@
8787
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=0.5.2.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
8888
"type": "Datadog.Trace.ClrProfiler.Integrations.AspNetWebApi2Integration",
8989
"method": "ExecuteAsync",
90-
"signature": [ 0, 3, 28, 28, 28, 28 ]
90+
"signature": "00 03 1C 1C 1C 1C"
91+
}
92+
}
93+
]
94+
},
95+
{
96+
"name": "ElasticsearchNet",
97+
"method_replacements": [
98+
{
99+
"caller": {
100+
"assembly": "Elasticsearch.Net"
101+
},
102+
"target": {
103+
"assembly": "Elasticsearch.Net",
104+
"type": "Elasticsearch.Net.IRequestPipeline",
105+
"method": "CallElasticsearch"
106+
},
107+
"wrapper": {
108+
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=0.5.2.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
109+
"type": "Datadog.Trace.ClrProfiler.Integrations.ElasticsearchNetIntegration",
110+
"method": "CallElasticsearch",
111+
"signature": "10 01 02 1C 1C 1C"
112+
}
113+
},
114+
{
115+
"caller": {
116+
"assembly": "Elasticsearch.Net"
117+
},
118+
"target": {
119+
"assembly": "Elasticsearch.Net",
120+
"type": "Elasticsearch.Net.IRequestPipeline",
121+
"method": "CallElasticsearchAsync"
122+
},
123+
"wrapper": {
124+
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=0.5.2.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
125+
"type": "Datadog.Trace.ClrProfiler.Integrations.ElasticsearchNetIntegration",
126+
"method": "CallElasticsearchAsync",
127+
"signature": "10 01 03 1C 1C 1C 1C"
128+
}
129+
}
130+
]
131+
},
132+
{
133+
"name": "ServiceStackRedis",
134+
"method_replacements": [
135+
{
136+
"caller": {
137+
"assembly": "ServiceStack.Redis"
138+
},
139+
"target": {
140+
"assembly": "ServiceStack.Redis",
141+
"type": "ServiceStack.Redis.RedisNativeClient",
142+
"method": "SendReceive"
143+
},
144+
"wrapper": {
145+
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=0.5.2.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
146+
"type": "Datadog.Trace.ClrProfiler.Integrations.ServiceStackRedisIntegration",
147+
"method": "SendReceive",
148+
"signature": "10 01 05 1E 00 1C 1D 1D 05 1C 1C 02"
91149
}
92150
}
93151
]
@@ -104,13 +162,13 @@
104162
"assembly": "System.Data",
105163
"type": "System.Data.SqlClient.SqlCommand",
106164
"method": "ExecuteReader",
107-
"signature": [ 32, 2, 12, 82, 8, 11, 82, 91, 14 ]
165+
"signature": "20 02 0C 52 08 0B 52 5B 0E"
108166
},
109167
"wrapper": {
110168
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=0.5.2.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
111169
"type": "Datadog.Trace.ClrProfiler.Integrations.SqlServer",
112170
"method": "ExecuteReaderWithMethod",
113-
"signature": [ 0, 3, 28, 28, 8, 14 ]
171+
"signature": "00 03 1C 1C 08 0E"
114172
}
115173
},
116174
{
@@ -119,13 +177,13 @@
119177
"assembly": "System.Data.SqlClient",
120178
"type": "System.Data.SqlClient.SqlCommand",
121179
"method": "ExecuteReader",
122-
"signature": [ 32, 1, 12, 87, 12, 11, 92 ]
180+
"signature": "20 01 0C 57 0C 0B 5C"
123181
},
124182
"wrapper": {
125183
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=0.5.2.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
126184
"type": "Datadog.Trace.ClrProfiler.Integrations.SqlServer",
127185
"method": "ExecuteReader",
128-
"signature": [ 0, 2, 28, 28, 8 ]
186+
"signature": "00 02 1C 1C 08"
129187
}
130188
}
131189
]
@@ -182,63 +240,5 @@
182240
}
183241
}
184242
]
185-
},
186-
{
187-
"name": "ServiceStackRedis",
188-
"method_replacements": [
189-
{
190-
"caller": {
191-
"assembly": "ServiceStack.Redis"
192-
},
193-
"target": {
194-
"assembly": "ServiceStack.Redis",
195-
"type": "ServiceStack.Redis.RedisNativeClient",
196-
"method": "SendReceive"
197-
},
198-
"wrapper": {
199-
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=0.5.2.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
200-
"type": "Datadog.Trace.ClrProfiler.Integrations.ServiceStack.Redis.RedisNativeClient",
201-
"method": "SendReceive",
202-
"signature": "10 01 05 1E 00 1C 1D 1D 05 1C 1C 02"
203-
}
204-
}
205-
]
206-
},
207-
{
208-
"name": "Elasticsearch",
209-
"method_replacements": [
210-
{
211-
"caller": {
212-
"assembly": "Elasticsearch.Net"
213-
},
214-
"target": {
215-
"assembly": "Elasticsearch.Net",
216-
"type": "Elasticsearch.Net.IRequestPipeline",
217-
"method": "CallElasticsearch"
218-
},
219-
"wrapper": {
220-
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=0.5.2.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
221-
"type": "Datadog.Trace.ClrProfiler.Integrations.Elasticsearch.Net.Pipeline",
222-
"method": "CallElasticsearch",
223-
"signature": "10 01 02 1C 1C 1C"
224-
}
225-
},
226-
{
227-
"caller": {
228-
"assembly": "Elasticsearch.Net"
229-
},
230-
"target": {
231-
"assembly": "Elasticsearch.Net",
232-
"type": "Elasticsearch.Net.IRequestPipeline",
233-
"method": "CallElasticsearchAsync"
234-
},
235-
"wrapper": {
236-
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=0.5.2.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
237-
"type": "Datadog.Trace.ClrProfiler.Integrations.Elasticsearch.Net.Pipeline",
238-
"method": "CallElasticsearchAsync",
239-
"signature": "10 01 03 1C 1C 1C 1C"
240-
}
241-
}
242-
]
243243
}
244-
]
244+
]

src/Datadog.Trace.ClrProfiler.Managed/Integrations/AspNetCoreMvc2Integration.cs

+8
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ public AspNetCoreMvc2Integration(object actionDescriptorObj, object httpContextO
5858
/// <param name="actionDescriptor">An ActionDescriptor with information about the current action.</param>
5959
/// <param name="httpContext">The HttpContext for the current request.</param>
6060
/// <param name="routeData">A RouteData with information about the current route.</param>
61+
[InterceptMethod(
62+
CallerAssembly = "Microsoft.AspNetCore.Mvc.Core",
63+
TargetAssembly = "Microsoft.AspNetCore.Mvc.Core",
64+
TargetType = "Microsoft.AspNetCore.Mvc.Internal.MvcCoreDiagnosticSourceExtensions")]
6165
public static void BeforeAction(
6266
object diagnosticSource,
6367
object actionDescriptor,
@@ -114,6 +118,10 @@ public static void BeforeAction(
114118
/// <param name="actionDescriptor">An ActionDescriptor with information about the current action.</param>
115119
/// <param name="httpContext">The HttpContext for the current request.</param>
116120
/// <param name="routeData">A RouteData with information about the current route.</param>
121+
[InterceptMethod(
122+
CallerAssembly = "Microsoft.AspNetCore.Mvc.Core",
123+
TargetAssembly = "Microsoft.AspNetCore.Mvc.Core",
124+
TargetType = "Microsoft.AspNetCore.Mvc.Internal.MvcCoreDiagnosticSourceExtensions")]
117125
public static void AfterAction(
118126
object diagnosticSource,
119127
object actionDescriptor,

src/Datadog.Trace.ClrProfiler.Managed/Integrations/AspNetMvcIntegration.cs

+8
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ public AspNetMvcIntegration(object controllerContextObj)
102102
/// <param name="callback">An <see cref="AsyncCallback"/> delegate.</param>
103103
/// <param name="state">An object that holds the state of the async operation.</param>
104104
/// <returns>Returns the <see cref="IAsyncResult "/> returned by the original BeginInvokeAction() that is later passed to <see cref="EndInvokeAction"/>.</returns>
105+
[InterceptMethod(
106+
CallerAssembly = "System.Web.Mvc",
107+
TargetAssembly = "System.Web.Mvc",
108+
TargetType = "System.Web.Mvc.Async.IAsyncActionInvoker")]
105109
public static object BeginInvokeAction(
106110
dynamic asyncControllerActionInvoker,
107111
dynamic controllerContext,
@@ -142,6 +146,10 @@ public static object BeginInvokeAction(
142146
/// <param name="asyncControllerActionInvoker">The AsyncControllerActionInvoker instance.</param>
143147
/// <param name="asyncResult">The <see cref="IAsyncResult"/> returned by <see cref="BeginInvokeAction"/>.</param>
144148
/// <returns>Returns the <see cref="bool"/> returned by the original EndInvokeAction().</returns>
149+
[InterceptMethod(
150+
CallerAssembly = "System.Web.Mvc",
151+
TargetAssembly = "System.Web.Mvc",
152+
TargetType = "System.Web.Mvc.Async.IAsyncActionInvoker")]
145153
public static bool EndInvokeAction(dynamic asyncControllerActionInvoker, dynamic asyncResult)
146154
{
147155
AspNetMvcIntegration integration = null;

src/Datadog.Trace.ClrProfiler.Managed/Integrations/AspNetWebApi2Integration.cs

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ public static class AspNetWebApi2Integration
2323
/// <param name="controllerContext">The controller context for the call</param>
2424
/// <param name="cancellationTokenSource">The cancellation token source</param>
2525
/// <returns>A task with the result</returns>
26+
[InterceptMethod(
27+
TargetAssembly = "System.Web.Http",
28+
TargetType = "System.Web.Http.Controllers.IHttpController")]
2629
public static object ExecuteAsync(object apiController, object controllerContext, object cancellationTokenSource)
2730
{
2831
if (apiController == null) { throw new ArgumentNullException(nameof(apiController)); }

src/Datadog.Trace.ClrProfiler.Managed/Integrations/Elasticsearch.Net/Pipeline.cs src/Datadog.Trace.ClrProfiler.Managed/Integrations/ElasticsearchNetIntegration.cs

+11-3
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
using System.Threading;
33
using System.Threading.Tasks;
44

5-
namespace Datadog.Trace.ClrProfiler.Integrations.Elasticsearch.Net
5+
namespace Datadog.Trace.ClrProfiler.Integrations
66
{
77
/// <summary>
88
/// Traces an Elasticsearch pipeline
99
/// </summary>
10-
public static class Pipeline
10+
public static class ElasticsearchNetIntegration
1111
{
1212
private const string OperationName = "elasticsearch.query";
1313
private const string ServiceName = "elasticsearch";
@@ -32,13 +32,17 @@ public static class Pipeline
3232
/// <param name="pipeline">The pipeline for the original method</param>
3333
/// <param name="requestData">The request data</param>
3434
/// <returns>The original result</returns>
35+
[InterceptMethod(
36+
CallerAssembly = "Elasticsearch.Net",
37+
TargetAssembly = "Elasticsearch.Net",
38+
TargetType = "Elasticsearch.Net.IRequestPipeline")]
3539
public static object CallElasticsearch<TResponse>(object pipeline, object requestData)
3640
{
3741
var originalMethod = DynamicMethodBuilder<Func<object, object, TResponse>>
3842
.GetOrCreateMethodCallDelegate(
3943
pipeline.GetType(),
4044
"CallElasticsearch",
41-
methodGenericArguments: new Type[] { typeof(TResponse) });
45+
methodGenericArguments: new[] { typeof(TResponse) });
4246

4347
using (var scope = CreateScope(pipeline, requestData))
4448
{
@@ -62,6 +66,10 @@ public static object CallElasticsearch<TResponse>(object pipeline, object reques
6266
/// <param name="requestData">The request data</param>
6367
/// <param name="cancellationTokenSource">A cancellation token</param>
6468
/// <returns>The original result</returns>
69+
[InterceptMethod(
70+
CallerAssembly = "Elasticsearch.Net",
71+
TargetAssembly = "Elasticsearch.Net",
72+
TargetType = "Elasticsearch.Net.IRequestPipeline")]
6573
public static object CallElasticsearchAsync<TResponse>(object pipeline, object requestData, object cancellationTokenSource)
6674
{
6775
var cancellationToken = ((CancellationTokenSource)cancellationTokenSource)?.Token ?? CancellationToken.None;

src/Datadog.Trace.ClrProfiler.Managed/Integrations/Redis.cs src/Datadog.Trace.ClrProfiler.Managed/Integrations/RedisHelper.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace Datadog.Trace.ClrProfiler.Integrations
22
{
3-
internal static class Redis
3+
internal static class RedisHelper
44
{
55
internal const string OperationName = "redis.command";
66
internal const string ServiceName = "redis";

0 commit comments

Comments
 (0)