-
Notifications
You must be signed in to change notification settings - Fork 183
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
codegen question: how to handle enum values as constants #1064
Comments
@MSNev CC |
I think
|
So you're suggesting |
Almost, I'm suggesting |
|
We don't allow to register an attribute that uses another attribute name as a prefix. So it should be safe to create a constant like Am I missing something? UPDATE: oops, we don't have a check for it - #1068, will fix |
@lmolkova I also thought this, but the problem here is that in JS, for attributes that are enums they generate constants for both the attribute name + the enum values. So the attribute
and its values have the format of
And it's not great because it's all together and hard to read. So they thought about adding Just thinking now, @dyladan what about generate the constant for the enum values as |
@joaopgrassi adding semantic-conventions/docs/general/attribute-naming.md Lines 52 to 58 in e299079
So there is no collision issue, at least I don't see it. |
@lmolkova it's not about the attribute in our yaml models, but how they will be mapped to JS constants when passing them in codegen. For example, if JS adopts the solution of adding Then say, we decided to add a |
I think @lmolkova is saying |
The only risk of collision here would be if an attribute was renamed to cause a collision similar to #1031, but that can happen no matter what the rules are. |
Ah right, I got it now, I somehow thought it was just a namespace and not an actual attribute. I guess for this case then we should be fine with
Yep :/ |
Because of package size issues in JavaScript we explicitly moved away from any form of namespace, so that any code that only references a single value only needs to include that single value in any generated packages. |
Area(s)
No response
Is your change request related to a problem? Please describe.
In JS we generate our code as constants. In order to be friendly to bundlers and minifiers, we avoid using object or enums; everything is a plain constant with a primitive, non-object, type value. Currently, we are generating our enums like this:
For enum values, the attribute name is squished together into a single all-caps word in order to avoid possible collisions with other attribute names. There is currently a PR open to deprecate that in favor of using normal all-caps snake case and infixing
_VALUES_
before the value name like this:During review of that change, the issue was raised that this might cause collisions if an attribute like
log.iostream.values.stdout
was ever registered (note: we know this specific case is not likely, but the general problem is possible).Describe the solution you'd like
Please provide guidance as to how we should move forward with this. It seems there are a couple ways we could move forward:
_VALUES_
infix option above. Some people think it is sufficiently unlikely to cause collisions (I am in this group).ENUM_
or similar?Describe alternatives you've considered
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: