Skip to content

Metrics Annotations #7030

Open
Open
@fstab

Description

@fstab

Frameworks like Spring Boot, MicroProfile, and Dropwizard offer annotations like @Timed or @Counted for creating metrics from method calls.

The benefit is that developers can provide metrics for their business logic while still separating business code from metrics tracking.

@Timed
@Counted
public void processPayment() {
    // business code here
}

The OpenTelemetry Java auto instrumentation supports the @WithSpan annotation for tracing, but has nothing equivalent for metrics yet.

Brainstorming of a few ideas:

  • For @Timed the type of histogram should be configurable, like @Timed(histogramType = EXPONENTIAL). Other histogram types would be explicit buckets and default buckets.
  • Explicit buckets should be configurable: @Timed(buckets = { 0.001, 0.002, 0.003, 0.004 })
  • For exponential histograms the resolution should be configurable.
  • Static attributes should be configurable: @Counted(attributes = { "key", "value" })
  • Dynamic attributes should be configurable similar to OpenTelemetry's @SpanAttribute.
  • Dynamic attributes based on the return value and on an exception thrown would be great.

Moreover, it would be awesome to integrate this with @WithSpan so that develpers can say "I want to time this method AND have a Span". However, it should also be possible to use tracing without metrics, because histograms may introduce a lot of cardinality, and users might just want to create a Span without creating a histogram.

What do you think, is it worthwhile to put some more thoughts into this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    contribution welcomeRequest makes sense, maintainers probably won't have time, contribution would be welcomeenhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions