Generate constants for metric definitions#317
Closed
trask wants to merge 3 commits into
Closed
Conversation
jack-berg
reviewed
Oct 8, 2025
Member
jack-berg
left a comment
There was a problem hiding this comment.
I'm very supportive of this idea! Some thoughts:
- I think we should only generate incubating constants to start (but include stable metrics in the incubating files) to start.
- In this proposal we generate metric name, unit description. Its still possible to misuse the conventions by choosing the wrong instrument type. Have you considered generating functions which return fully resolved metrics? I.e. something like:
public static DoubleHistogram httpServerRequestDurationMetric(Meter) { ... }
We could of course do both. Generating the name, unit, description constants is more flexible in the sense that it allows you to more easily create metrics matching a particular metric convention's name and description, but with a custom unit. I.e. http.server.request.duration with ms unit instead of the default s. But this greases the tracks to not conform to the conventions, which I'd argue we ought not to do.
Member
Author
will do |
This was referenced Oct 16, 2025
Merged
trask
commented
Oct 17, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related to open-telemetry/opentelemetry-java-instrumentation#9478
Another option is to provide an API that creates the metric using these constants internally, though that doesn't help us in library instrumentation for all of the unstable metrics at least where we don't want to have a dependency on unstable semconv artifact, but we still want the constants for verification in tests.