When implementing observability features, always ensure consistency in your data model, especially with tags and attributes. This helps prevent issues with backends that expect consistent tag sets.
When implementing observability features, always ensure consistency in your data model, especially with tags and attributes. This helps prevent issues with backends that expect consistent tag sets.
Use consistent tag sets across metrics: Always include the same set of tag keys for metrics of the same type, even when some values are missing.
Provide defaults for missing values: Use standardized defaults like “unknown” or “N/A” rather than omitting tags when values are unavailable.
// INCORRECT: Inconsistent tag sets
Gauge.builder("git.info", () -> 1L)
.tag("branch", props.getBranch()) // May be omitted if null
.tag("id", props.getShortCommitId())
.register(registry);
// CORRECT: Consistent tag sets with defaults
Gauge.builder("git.info", () -> 1L)
.tag("branch", props.getBranch() != null ? props.getBranch() : "unknown")
.tag("id", props.getShortCommitId() != null ? props.getShortCommitId() : "unknown")
.register(registry);
// INCORRECT: Ambiguous description
builder.description("Duration of requests made to HTTP Server")
// CORRECT: Clear perspective
builder.description("Duration of HTTP server request handling")
These practices help avoid issues with observability backends (like Prometheus) that may not handle inconsistent tag sets well and improve the overall reliability and usability of your observability data.
Enter the URL of a public GitHub repository