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

[plugins] modules loaded before tracer SDK #636

Closed
mayurkale22 opened this issue Dec 18, 2019 · 9 comments
Closed

[plugins] modules loaded before tracer SDK #636

mayurkale22 opened this issue Dec 18, 2019 · 9 comments
Assignees
Labels
Discussion Issue or PR that needs/is extended discussion.
Milestone

Comments

@mayurkale22
Copy link
Member

IMO initialization of NodeTracer module which provides automated tracing (instrumentation) for Node.js applications has to be the first line in the application code before loading actual modules like http, redis, grpc etc. Loading these modules before our tracer SDK may prevent
us from monkeypatching those modules for automatic tracing. I have verified that w/ current http example.

I am proposing to detect list of modules that were loaded using require() before our tracer SDK and log a warning or error to inform the users.

@mayurkale22 mayurkale22 added the Discussion Issue or PR that needs/is extended discussion. label Dec 18, 2019
@dyladan
Copy link
Member

dyladan commented Dec 18, 2019

Probably only warn on modules that would have been instrumented. for instance if http tracer is disabled, it doesn't matter that it was loaded before us.

@mayurkale22 mayurkale22 added this to the Alpha v0.4 milestone Dec 23, 2019
vmarchaud added a commit to vmarchaud/opentelemetry-js that referenced this issue Dec 29, 2019
@vmarchaud vmarchaud self-assigned this Dec 29, 2019
@vmarchaud
Copy link
Member

Totally agree (#654), it's already implemented in all vendor specific APMs because it's such a pain to debug for end users.

@naseemkullah
Copy link
Member

naseemkullah commented Dec 31, 2019

Can you please confirm that http needs to be loaded after tracer initialization, or that simply the http server must be instantiated after (but the http module could be loaded before) ? For express the latter is true and I would presume the same for all libs.

@vmarchaud
Copy link
Member

@naseemkullah Nope, the tracer should always be required before any module. In your example, the patch still works because we patch the prototype of the http server which works for already instanciated server, however sometimes it's not possible.

vmarchaud added a commit to vmarchaud/opentelemetry-js that referenced this issue Jan 1, 2020
@naseemkullah
Copy link
Member

Thanks @vmarchaud

@OlivierAlbertini
Copy link
Member

@naseemkullah Nope, the tracer should always be required before any module.

I'm agree with @vmarchaud. It's a good rule. I also encountered some issues as well during integrations with http if tracer was initialized after...

vmarchaud added a commit to vmarchaud/opentelemetry-js that referenced this issue Jan 5, 2020
vmarchaud added a commit to vmarchaud/opentelemetry-js that referenced this issue Jan 11, 2020
@mayurkale22 mayurkale22 modified the milestones: Alpha v0.3.3, Alpha v0.4 Jan 22, 2020
vmarchaud added a commit to vmarchaud/opentelemetry-js that referenced this issue Jan 26, 2020
vmarchaud added a commit to vmarchaud/opentelemetry-js that referenced this issue Feb 1, 2020
vmarchaud added a commit to vmarchaud/opentelemetry-js that referenced this issue Feb 8, 2020
mayurkale22 added a commit that referenced this issue Feb 10, 2020
…#654)

* feat: warn user when a instrumented package was already required #636

* chore: address PR comments

* chore: extract package name from require.cache

* chore: use find instead of some

* chore: use require.resolve to find already required modules

* chore: try/catch require.resolve

Co-authored-by: Mayur Kale <[email protected]>
@mayurkale22
Copy link
Member Author

I think we close this one via #654. @vmarchaud please confirm.

@vmarchaud
Copy link
Member

@mayurkale22 indeed its done

pichlermarc pushed a commit to dynatrace-oss-contrib/opentelemetry-js that referenced this issue Dec 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Discussion Issue or PR that needs/is extended discussion.
Projects
None yet
Development

No branches or pull requests

5 participants