Generate incubating metric name, unit, and description constants#483
Generate incubating metric name, unit, and description constants#483ADITYA-CODE-SOURCE wants to merge 1 commit into
Conversation
|
✅ Verified with a local gradle build that I am now able to reference the previously-unavailable semconv metric name: |
Thanks for testing, @geekdave! Glad it works for your use case. |
|
|
||
| // DO NOT EDIT, this is an Auto-generated file from buildscripts/templates/registry/incubating_java/IncubatingSemanticMetrics.java.j2 | ||
| @SuppressWarnings("unused") | ||
| public final class {{ my_class_name }} { |
There was a problem hiding this comment.
@trask's code in from #317 has additional logic to add deprecated javadoc tags which link to the stable class if available. This will be necessary once we enable enable generation of stable classes.
I pushed a commit which ports those changes to this branch: jack-berg@0ef14f8
Should probably just leave the code, but comment out the bit that makes the linking work with a TODO reminder to enable when generation of stable classes is enabled.
Speaking of which, given our experience with generating attribute constants, I'm much less worried about us getting the generation pattern wrong in some key way we'll regret. @trask / @laurit WDYT about just enabling generation of stable metrics out of the gate?
There was a problem hiding this comment.
Thanks @jack-berg — this is very helpful.
I can bring over the deprecated-javadoc logic from #317 as you suggested.
On the broader question of enabling stable metrics in this PR as well, I’m happy to follow whichever direction you all prefer. The stable path is already scaffolded, so I can either keep this incubating-only for now or fold stable generation into this PR if that seems like the better direction.
Summary
Add metric constant code generation to the incubating semconv artifact.
This introduces
{Namespace}IncubatingMetricsclasses that expose metric name, unit, and description constants from the semconv metric model, following the existing Java semconv codegen organization and incubating-first rollout.What this changes
IncubatingSemanticMetrics.java.j2for incubating metric constant generationbuildscripts/templates/registry/incubating_java/weaver.yamlSemanticMetrics.java.j2scaffold for follow-up workbuildscripts/templates/registry/java/weaver.yamlentry commented out*IncubatingMetrics.javaclasses undersemconv-incubatingGenerated API shape
Each metric generates three constants:
Example generated class:
Why incubating only
Per maintainer guidance, the pattern itself is being introduced experimentally first.
Even when the underlying metric semconv is stable, the generated Java metric constants are introduced in
opentelemetry-semconv-incubatingfirst so the class layout, naming, and API shape can be reviewed before promoting stable generation intoopentelemetry-semconv.Validation
Locally verified with:
./gradlew clean generateSemanticConventions --console=plain./gradlew spotlessApply:semconv-incubating:compileJava:semconv-incubating:checkstyleMain:semconv-incubating:spotlessCheck:semconv:compileJava:semconv:checkstyleMain:semconv:spotlessCheckFollow-up
Once the pattern is approved, a follow-up PR can:
semconvReferences
cc @jack-berg