-
Notifications
You must be signed in to change notification settings - Fork 795
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(@opentelemetry/semantic-conventions): change enum to object literals #2532
feat(@opentelemetry/semantic-conventions): change enum to object literals #2532
Conversation
Codecov Report
@@ Coverage Diff @@
## main #2532 +/- ##
=======================================
Coverage 93.05% 93.05%
=======================================
Files 139 139
Lines 5172 5172
Branches 1110 1110
=======================================
Hits 4813 4813
Misses 359 359 |
Would const enums behave much differently? |
Sorry, how does this impair debuggability? Wouldn't the benefits of using enums for code completions and type checking getting lost? Just found: https://www.typescriptlang.org/docs/handbook/enums.html#objects-vs-enums |
Const enum members are inlined at use sites, and they will be completely removed during compilation. We don't use the enums in semantic-conventions, so they won't exist in semantic-convention transpile outputs. Const enums seem not suitable for our 'export' scenario. I pack my app using vite , tree-shaking is enabled by default for vite. And I get the bundle size statistics with the help of rollup-plugin-visualizer . I have uploaded the simplified example-app just now to my repo,you may have a look :) |
It seems object is more straightforward and won't impair code completion. Do you mean 'const enums'?I tried const enums, however , they seem not suitable for our 'export' scenario, for const enums will be removed during compilation. Then the other app that imported semantic-convention (transpiled code) can't find the 'const enums'. I have tried to add the 'as const' as postfix for object to keep the original 'type checking' ability and it works, thanks for your advice! |
Great @echoontheway , thanks for taking the time to try it out :) I now also understand this is problem for when using it for client-side browsers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is really nice finding, lgtm
Line 17 tells if this is true this change will vanish on next generator run. Maybe the generator needs some fix? |
The template file has been updated too. Should be all good |
Which problem is this PR solving?
TS:
outputs:
As shown above, TS enums will be transpiled to self-executing anonymous functions, which won't be regarded as dead code and got eliminated by pack tools. So all these enum transpile outputs are left in the bundle even if they're not imported by the app.
bundle size of enum:
bundle size of object literal
(bundle size statistics are got with the help of rollup-plugin-visualizer . Detail pack config can be found in the simplified example-app in my repo)
Short description of the changes