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

Semconv codegen should produce different constant names if attribute is renamed _ -> `` #75

Conversation

lmolkova
Copy link
Contributor

@lmolkova lmolkova commented Jun 6, 2024

Code generator generates the same attribute name constant for attribute.name and attribute_name. As a result, if attribute is renamed (_ is changed to . or vice versa), the value of attribute changes, but the name stays the same.

It's ambiguous - see open-telemetry/semantic-conventions#1031 and open-telemetry/semantic-conventions#1118 for the discussion.

Based on open-telemetry/semantic-conventions#1118, the semconv recommendation would be to:

  • Remove _ when generating any constants in the code (fields, methods, class names, etc)
  • Semconv will prohibit attribute renames that are limited to adding/removing _

This PR demonstrates the result of such naming policy change.

@@ -113,7 +113,7 @@ public static final class JvmMemoryTypeValues {
public static final String HEAP = "heap";

/** Non-heap memory. */
public static final String NON_HEAP = "non_heap";
public static final String NONHEAP = "non_heap";
Copy link
Member

Choose a reason for hiding this comment

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

do we want to apply this change here (and other values)?

/** Values for {@link #DB_CASSANDRA_CONSISTENCY_LEVEL}. */
public static final class DbCassandraConsistencyLevelValues {
/** Values for {@link #DB_CASSANDRA_CONSISTENCYLEVEL}. */
public static final class DbCassandraConsistencylevelValues {
Copy link
Member

Choose a reason for hiding this comment

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

😢

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree, the only way it can be tolerated is if we avoided multi_word_names as much as possible.

Comment on lines +127 to 128
public static final AttributeKey<Long> HTTP_REQUEST_RESENDCOUNT =
longKey("http.request.resend_count");
Copy link
Member

Choose a reason for hiding this comment

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

from an API user perspective, it looks like a typo that we forgot some underscore(s) in the constant name 😢

Copy link
Member

Choose a reason for hiding this comment

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

what do you think about alternative proposal:

  • first one gets the good constant name: MESSAGING_CLIENT_ID = "messaging.client_id"
  • next one (after rename) gets a "bad" constant name: MESSAGING_CLIENT_ID2 = "messaging.client.id"
  • when stabilizing, we are moving from MessagingIncubatingAttributes to MessagingAttributes and so the stable one can get the good constant name at that time: MESSAGING_CLIENT_ID = "messaging.client.id"
  • if anything is renamed after stability, we'd need to do a major version bump anyways (although users of the previously stable constant name would silently get the new constant value without any compilation warnings, which is not great, but really hoping this kind of rename after marking something stable is a rarity 😬)

Copy link
Contributor

Choose a reason for hiding this comment

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

I prefer this plan.

Copy link
Contributor Author

@lmolkova lmolkova Jun 7, 2024

Choose a reason for hiding this comment

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

we could also just tolerate it (for experimental ones):

  • generate both as MESSAGING_CLIENT_ID, override the value (non-deprecated wins) - it's tolerable for experimental attributes
  • as you mentioned, we'd probably never do a rename like this for a stable attribute - the value would be too low to justify the cost.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not excited about MESSAGING_CLIENT_ID2 since it would either need to be stabilized with this const name or users would need to update IncubatingAttributes.MESSAGING_CLIENT_ID2 -> Attributes.MESSAGING_CLIENT_ID

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The problem still remains - we don't really know the order in which attributes were added and which one should become MESSAGING_CLIENT_ID2. We can assume that deprecated should get MESSAGING_CLIENT_ID, but what if we deprecated both?

Copy link
Member

Choose a reason for hiding this comment

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

What would we put into stable artifact when it's stabilized? MESSAGING_CLIENT_ID?

👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we can do it with some manual interventions.
Given that collisions are rare, it should be ok.

Trying it out here 6390847

Copy link
Member

Choose a reason for hiding this comment

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

I don't mind the approach 3.5 where we accept breaking changes in the incubating artifact, but wondering if this solution could work better for folks who are more apprehensive about the breaking changes (and the strategy could also be used to mitigate the even rarer attribute type changes on experimental attributes)

Copy link
Contributor Author

@lmolkova lmolkova Jun 11, 2024

Choose a reason for hiding this comment

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

#76 shows manual conflict resolution:

  • it allows to change constant names for experimental attributes. E.g. say that messaging.client.id constant names should be generated as if it was messaging.client.id_new (preserving the const value)
  • or drop an attribute based on the name

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.

3 participants