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

autogenerate integrations.json #232

Merged
merged 23 commits into from
Dec 13, 2018
Merged

Conversation

lucaspimentel
Copy link
Member

@lucaspimentel lucaspimentel commented Dec 12, 2018

This PR adds a tool that can generate the integrations.json file from declaration in code, reducing manual work when adding new integrations and reducing the chance of errors, since it can automatically determine many values, such as the wrapper method's signature blob.

Usage:

  • write a method that will replace the instrumented method
  • decorate the method with the [InterceptMethod] attribute

For example, to intercept method System.Web.Mvc.Async.IAsyncActionInvoker.BeginInvokeAction() in System.Web.Mvc.dll:

[InterceptMethod(TargetAssembly = "System.Web.Mvc",
                 TargetType = "System.Web.Mvc.Async.IAsyncActionInvoker")]
public static object BeginInvokeAction(/* ... */)
{
    // ...
}

This PR also renames some integrations and move them to the Integrations folder for consistency:

  • Pipeline to ElasticsearchNetIntegration
  • RedisNativeClient to ServiceStachRedisIntegration

For now, we will run this tool manually and check the results before committing changes to integrations.json. Later we can run it as part of the build process.

@lucaspimentel lucaspimentel self-assigned this Dec 12, 2018
@lucaspimentel lucaspimentel added this to the 0.5.3-beta milestone Dec 12, 2018
Copy link
Contributor

@palazzem palazzem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it makes sense, another pair of eyes is important :)

Copy link
Contributor

@bmermet bmermet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM


// find all methods in Datadog.Trace.ClrProfiler.Managed.dll with [InterceptMethod]
// and create objects that will generate correct JSON schema
var integrations = from wrapperType in integrationsAssembly.GetTypes()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the longest LINQ query I've seen 😄

var genericArguments = method.GetGenericArguments();

var newSignatureBytes = new byte[signatureBytes.Length + 1];
newSignatureBytes[0] = (byte)(signatureBytes[0] | 0x10);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: would be nice to name 0x10 IMAGE_CEE_CS_CALLCONV_GENERIC or something similar for code readability

@lucaspimentel lucaspimentel merged commit 24adfab into develop Dec 13, 2018
@lucaspimentel lucaspimentel deleted the lpimentel/intercept-attributes branch December 13, 2018 14:51
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

Successfully merging this pull request may close these issues.

3 participants