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

fix auto instrumentation of loaded modules without an entrypoint defined #587

Merged
merged 3 commits into from
Jun 18, 2019

Conversation

BrunoBerisso
Copy link
Contributor

The automatic instrumentation works well but enforces the API consumer to follow a fixed lifecycle on his side. The intention of these changes is to add means to instrument already supported modules manually at any point in time.

I believe this PR would close handle issue #560, at least for my case.

Thanks for maintaining this project.

Note: this is a WIP to validate the approach. If the owners think this make sense I will be happy to push the feature during the review process.

@BrunoBerisso BrunoBerisso requested a review from a team as a code owner June 13, 2019 14:41
@rochdev
Copy link
Member

rochdev commented Jun 13, 2019

I'm not sure I understand the difference between this approach and calling tracer.use() later in the lifecycle, which should work but is definitely not recommended.

@BrunoBerisso
Copy link
Contributor Author

In my case, tracer.use() fail because getModules didn't return any result for Express 4.16.4

@rochdev
Copy link
Member

rochdev commented Jun 13, 2019

Were you able to find the reason for this? I would rather have this fixed in tracer.use() if possible so that it covers more use cases.

@BrunoBerisso
Copy link
Contributor Author

Yes. I think the reason is instrumentation doesn't have a file value set and rely on the project.json main field to match the module id.

The final result is that it doesn't find anything... If you think it's better to fix tracer.use() I will be happy to do it.

@rochdev
Copy link
Member

rochdev commented Jun 13, 2019

Yes. I think the reason is instrumentation doesn't have a file value set and rely on the project.json main field to match the module id.

I assumed this would always be set but I guess it can default to index.js when not present.

The final result is that it doesn't find anything... If you think it's better to fix tracer.use() I will be happy to do it.

I would definitely prefer that to introducing a new method, at least for now. Thanks for looking into this!

@BrunoBerisso
Copy link
Contributor Author

FYI: I just add index.js to instrumentation object for Express and I don't even need to call use() for the module to be patched. The initialization process gets the modules to patch from require.cache so any supported module already loaded will be processed.

I believe this load process has some important things to address (like checking for versions set on the instrumentation object before patching, etc) and I need this fixed to move forward with my integration.

Can I open another PR to set file: 'index.js' in the instrumentation for Express and then continue working on this one?

@rochdev
Copy link
Member

rochdev commented Jun 14, 2019

Can I open another PR to set file: 'index.js' in the instrumentation for Express and then continue working on this one?

Sure, please do! I would however suggest adding a default to the instrumenter instead, so that any library without a main field in package.json would default to index.js like Node is doing.

@BrunoBerisso BrunoBerisso force-pushed the manual-plugin-instrumentation branch from 850525e to 2d3b5bf Compare June 17, 2019 14:31
@BrunoBerisso
Copy link
Contributor Author

I would however suggest adding a default to the instrumenter instead

I did just what you suggested and works as expected on my side, thanks!
This branch is updated with the latest changes, I can't check the conflicts on src/instrumenter.js as it says here. I pull and rebase before pushing so not sure what's wrong...

Let me know if it looks good and if possible an eta to know when this could be available on my side. Thanks

@rochdev
Copy link
Member

rochdev commented Jun 17, 2019

Could you add a test to avoid any regression in the future?

For the merge conflict, the issue is that we changed the structure of the project, so the file that should be changed is now packages/dd-trace/src/instrumenter.js.

@rochdev
Copy link
Member

rochdev commented Jun 17, 2019

Let me know if it looks good and if possible an eta to know when this could be available on my side.

We don't have a well defined release cycle, but I plan to do a minor release this week. If that ends up not being possible I'll simply release a patch release instead.

@rochdev rochdev changed the title Add manual instrumentation fix auto instrumentation of loaded modules without an entrypoint defined Jun 17, 2019
@BrunoBerisso BrunoBerisso force-pushed the manual-plugin-instrumentation branch from 2d3b5bf to de19c4f Compare June 17, 2019 17:01
@BrunoBerisso BrunoBerisso force-pushed the manual-plugin-instrumentation branch from de19c4f to 441abe6 Compare June 18, 2019 12:28
@rochdev rochdev merged commit f4f790f into DataDog:master Jun 18, 2019
@BrunoBerisso
Copy link
Contributor Author

Thanks @rochdev Was a pleasure 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants