Skip to content

Generate incubating metric name, unit, and description constants#483

Draft
ADITYA-CODE-SOURCE wants to merge 1 commit into
open-telemetry:mainfrom
ADITYA-CODE-SOURCE:metric-constants
Draft

Generate incubating metric name, unit, and description constants#483
ADITYA-CODE-SOURCE wants to merge 1 commit into
open-telemetry:mainfrom
ADITYA-CODE-SOURCE:metric-constants

Conversation

@ADITYA-CODE-SOURCE
Copy link
Copy Markdown

@ADITYA-CODE-SOURCE ADITYA-CODE-SOURCE commented May 13, 2026

Summary

Add metric constant code generation to the incubating semconv artifact.

This introduces {Namespace}IncubatingMetrics classes 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

  • adds IncubatingSemanticMetrics.java.j2 for incubating metric constant generation
  • wires incubating metrics generation into buildscripts/templates/registry/incubating_java/weaver.yaml
  • adds a stable SemanticMetrics.java.j2 scaffold for follow-up work
  • keeps stable metrics generation disabled for now by leaving the buildscripts/templates/registry/java/weaver.yaml entry commented out
  • generates new *IncubatingMetrics.java classes under semconv-incubating

Generated API shape

Each metric generates three constants:

public static final String HTTP_SERVER_REQUEST_DURATION_NAME =
    "http.server.request.duration";
public static final String HTTP_SERVER_REQUEST_DURATION_UNIT = "s";
public static final String HTTP_SERVER_REQUEST_DURATION_DESCRIPTION =
    "Duration of HTTP server requests.";

Example generated class:

public final class HttpIncubatingMetrics {
  /** Name of the {@code http.server.request.duration} metric. */
  public static final String HTTP_SERVER_REQUEST_DURATION_NAME =
      "http.server.request.duration";

  /** Unit of the {@code http.server.request.duration} metric. */
  public static final String HTTP_SERVER_REQUEST_DURATION_UNIT = "s";

  /** Description of the {@code http.server.request.duration} metric. */
  public static final String HTTP_SERVER_REQUEST_DURATION_DESCRIPTION =
      "Duration of HTTP server requests.";

  private HttpIncubatingMetrics() {}
}

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-incubating first so the class layout, naming, and API shape can be reviewed before promoting stable generation into opentelemetry-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:spotlessCheck

Follow-up

Once the pattern is approved, a follow-up PR can:

  • enable stable metrics generation in semconv
  • decide whether incubating stable copies should be deprecated
  • build any richer metric helper APIs on top of these constants

References

cc @jack-berg

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.

1 participant