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

feat(baseplugin): add internalfilesloader #240

Merged

Conversation

markwolff
Copy link
Member

Which problem is this PR solving?

Short description of the changes

  • Resolves TODO of Add gRPC plugin #158, which required this implementation. This PR moves the logic out of the grpc plugin to BasePlugin, in case future plugins also require this behavior.

protected _moduleExports!: T;
protected _tracer!: Tracer;
protected _logger!: Logger;
// tslint:disable-next-line:no-any
protected _internalFilesExports!: { [module: string]: any }; // output for internalFilesExports
Copy link
Member

Choose a reason for hiding this comment

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

could we use unknown instead of any there ?

Copy link
Member Author

@markwolff markwolff Sep 19, 2019

Choose a reason for hiding this comment

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

@vmarchaud With this, the expectation would be to load the types for the internal file in each plugin. Those typings probably probably won't exist if it isn't a typescript library and so the plugin would have to cast it to any anyways in that case. I'm okay with this behavior of encouraging trying to use types and passing along the burden of any casting to each plugin. Changed to unknown and made additional cast in grpc plugin. WDYT?

https://github.com/open-telemetry/opentelemetry-js/pull/240/files#diff-671cbf0fed27b96717e412e39a4dfc30R86

this._logger.debug('loading File %s', extraModulesList[moduleName]);
outExtraModules[moduleName] = require(path.join(
basedir,
extraModulesList[moduleName]
Copy link
Member Author

@markwolff markwolff Sep 17, 2019

Choose a reason for hiding this comment

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

This won't work in webpack because of the static import checking it does for tree shaking (hardcoding the path name works, but not the joining of basedir and the filepath. The internal file import shows up as not found). Ideally, we don't want people to muck with their webpack configs just to get plugins working in their browser bundling env.

AFAIK we don't have any plugins that would run outside of node.js, which makes me think this PR should live in PluginLoader instead? Ideally this functionality would be universal (node + browser) for any future "pure javascript" library we provide a plugin for, but it does not seem trivial from my first go at it.

/cc @mayurkale22 @draffensperger WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

I had a few conversations about the plugin loader system for the browser - my opinion is that this approach of treating packages like a runtime object isn't a good fit for the browser, where people can compile code using webpack or even Rollup + Closure Compiler and other approaches.

My opinion is that in the browser we should be monkey-patching not packages, but the browser APIs themselves (like XMLHttpRequest, etc.). Zone.js actually exists purely to monkey-patch all async browser APIs and we used it effectively in OpenCensus Web. I'm open to being wrong on this, but it's my understanding and opinion right now.

So I'm with this this being Node-specific.

As far as what package to put it in .... I'm open. I think there was a challenge with putting it in node-sdk because then we get circular dependency issues. I'm fine with leaving it in core. Maybe just explain in a comment that this way of dealing with plugins is designed to be Node-specific.

@mayurkale22
Copy link
Member

ping, for more reviews.

Copy link
Member

@mayurkale22 mayurkale22 left a comment

Choose a reason for hiding this comment

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

lgtm

@mayurkale22 mayurkale22 merged commit d6f669a into open-telemetry:master Sep 20, 2019
@markwolff markwolff deleted the baseplugin-add-internalfilesloader branch September 20, 2019 22:24
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.

[BasePlugin]: implement internalFilesExports
4 participants