-
Notifications
You must be signed in to change notification settings - Fork 821
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 some namespacing in API #1750
Comments
We already have this unless I'm misunderstanding what you ask for. import { trace, metrics } from "@opentelemetry/api";
// These API calls are separated
trace.someApiCall();
metrics.someApiCall(); |
If you have suggestions, now is the time to bring them up. |
The most confusing exports for me are There are a lot helper exported on top level: examples for context relevant exports: Besides that one could argue that propagation and context is bound to trace. I assume here that all these top level exports are seen as part of public API and follow semver. To much namespacing is for sure not the best thing. But I think having e.g. see also #1749 (comment) |
As discussed in the SIG, while simply wrapping functions into a namespace can make it clear, but it has several downsides on the Web community, specifically around minification and tree-shaking. For minification a simplistic overview of what can't get minified are
And on the tree-shaking side of things, when you have functions linked with (on) a namespace (especially helper functions), when that namespace is included into the code, even if you are only using a single function from the namespace all of the code referenced is (by default) not available for removal and therefore the resulting bundle size created by whatever packaging system being used (webpack, rollup, etc) includes all of the functions. A better suggestion (in my view) would be to following the following
|
Definitely understandable. Do you have a naming suggestion for these?
The interfaces, classes, and helpers are exported on the top level, and most of the API interactions are exported in the namespace structure. Maybe we could remove some of the top level exports not needed to interact with the API and rename ones like
The spec doesn't support this. Context will be used for all signals including metrics/baggage, and baggage will also need to be propagated.
yes
Given @MSNev's concerns around minification, would you prefer we namespace these types of things like @MSNev you mention keeping functions at the top level, but most of the exports are actually interfaces which don't matter for tree shaking anyways. Most external interaction with the API will be through the
I am hesitant to abbreviate names unless it is exceedingly obvious what the abbreviations stand for. New users may not know that suppressInstr means suppress instrumentation. Takeaway
|
I was never the best contact to ask for good API names...
Personally I prefer namespaces as this allows to import the relevant one where needed and then go on and work with short names. I guess that typically just one or two aspects are needed within one module and only in rare cases the whole Api. |
Just a couple of minor comments
By declaring them on the interface it means that the real implementations will have to have them and therefore application code will need to use them and they won't be minified.
Agree, was just providing an example
Also agree, I think I'm coming late to the party on this one, but as above there are non-elegant solutions like using local variables (for multiple usages) and string name based indexed lookups if size issues are really an issue |
If we want to squeeze and minify as much as possible from the api I think we should ignore the namespaces in favor of having more descriptive function name. So with regards to mentioned example
we could have instead
and of course only if both trace and metrics will have the same function name. |
Closing as API release candidate is ready therefore no breaking changes like moving something around will be done. |
Currently most functions in API are exported on top level. The API covers quite orithogonal topics - currently metrics and traces - but more may come.
Should we consider to add some namespacing to allow us to keep function names short but still have some context to distinguish between metric, trace,... related APIs?
By the way, is there some API polishing round planed before the GA release to cover topics like this? I assume once trace is GA it's hard to change the look and feel.
The text was updated successfully, but these errors were encountered: