-
Notifications
You must be signed in to change notification settings - Fork 825
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
Add @opentelemetry/api as peerDependencies on @opentelemetry/sdk #885
Comments
Even if we could peer-dep it in our SDK modules, the issue I see here is that not everyone can have it as a peer dep. At the very least, this means that any end-user app needs to specify the same version of the API as their dependencies do in order to have any hope that it works. If The only way I see around this is to declare the API as an object property on the |
One more option I just thought of. Have the API module not implement the actual API, but just be the way it is accessed. You then have the API module peer-depend on another module that is the actual instance of the API, and proxies calls to it. If there is no API actually installed, the proxy calls no-op. You then have the SDK depend on that second module which is the actual instance of the API. In this case, the API delegate module can be duplicated as many times as needed and only the SDK depended on by the SDK is the real API. |
I think we should discuss this wednesday |
I believe we will need to use the global object. This article does a good job of explaining why. https://derickbailey.com/2016/03/09/creating-a-true-singleton-in-node-js-with-es6-symbols/ |
Agreed. Added to the agenda for the upcoming SIG meeting. |
This is the entire purpose of peerDependencies. They are the solution to "only one library."
npm then installs a single copy of @opentracing/api, and warns if the dependency is forgotten or incompatible with library requirements. This is how many ecosystems operate: react component libraries, webpack plugins, etc. You could mess with |
@pauldraper then in this situation, you end up with a broken install:
Now, the db-driver package will assume the end-user has installed the API, which of course they haven't because they are not opentelemetry users. When db-driver requires the API, the application crashes. |
npm warns the user of their broken install.
And the user would add @opentelemetry/api to their package.json. (Though never use it themselves.) But I now gather your preference/requirement is that @opentelemetry/api never appears directly in application package.json downstream. That is not a requirement for react or webpack or many other things because the user using them directly; opentelemetry is passive. In summary, OptionsA. OT users depend on @opentelemetry/api. SDK libraries peer depend on @opentelemetry/api. #885 (comment) Cons: Not just OT users, but all downstream applications must have @opentelemetry/api as a dependency. B. OT users depend on @opentelemetry/global. Instrumentations depend on @opentelemetry/api, which peer depends on @opentelemetry/global and binds to it if present. #885 (comment) Cons: npm issues warnings for non-OT downstream applications if they don't install @opentelemetry/global. (That said, npm warnings are already spammy, so maybe that doesn't matter.) C. OT users depend on @opentelemetry/global. Instrumentations depend on @opentelemetry/api, which does not depend on @opentelemetry/global but binds to it if present. Cons: There is no npm checking for version compatibility. (Though @opentelemetry/api itself could do that.) D. Instrumentations depend on @opentelemetry/api, which uses I think all these are workable. I slightly prefer the simplicity of D. P.S. https://derickbailey.com/2016/03/09/creating-a-true-singleton-in-node-js-with-es6-symbols/ is a strange read. |
I would like to avoid putting this burden on users of libraries that want to support opentelemetry, because it may slow adoption due to many libraries not wanting to put this random burden on their users. If I was a db library author, this would prevent me from supporting opentelemetry.
I do not want to add to the spam
This is probably OK, but I would probably change the names so that end-users depend on
This is the solution I recommended, but I could be talked into C.
The advantage of using a symbol is that it is then not an enumerable property on the global object, which prevents it from being listed using something like Also, if you use a string key then your property can be accessed from the global namespace without the global keyword which is not desireable. example:
With symbol this is not possible
|
I would move the
The likelihood of colliding by choosing same property name is the same as the likelihood of colliding with with the same symbol name.
True. Could be also done with Object.defineProperty.
True. You should have written that article. :) |
We talked about this again at the SIG meeting today. I am going to come up with a PR using the |
I ran into the same issue a couple of days ago when trying to run an Otel workshop. Node was neither parsing parsing propagation headers from incoming requests, nor injecting them into outgoing ones. Took quite some time to figure out what was going on. http plugins were using the global propagator from |
No longer needed after #943 |
Hey @dyladan, sorry for not replying. I somehow missed the notification. Would you still like me to test it? |
If you can that would be great! |
This is needed to set global
TracerProvider
and globalMeterProvider
correctly, especially when you use only@opentelemetry/api
module to instrument your application and want to provide ways for users to register OpenTelemetry or any other SDK, if they wish to.Looks like in the current state, every module will have their own copy of
@opentelemetry/api
. That means it is not really a global thing.My current test setup:
The alternative option is to use global objects, but in practice should generally be avoided.
The text was updated successfully, but these errors were encountered: