question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Metrics Annotations

See original GitHub issue

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?

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
jkwatsoncommented, Mar 9, 2022

Thanks a lot for the explanation, this makes sense. In that case the annotations would be quite simple, as they only provide configuration options for the metric name and attributes.

I could open a PR to add them to extensions/annotations/ so that we can continue the discussion based on concrete examples. What do you think?

That would be fine. Since these annotations are generally implemented by the instrumentation folks, I’d love some feedback on this proposal from @trask @mateuszrzeszutek @anuraaga and others.

0reactions
fstabcommented, Mar 12, 2022

Opened PR open-telemetry/opentelemetry-java#4260.

Read more comments on GitHub >

github_iconTop Results From Across the Web

@Timed Annotation Using Metrics and AspectJ | Baeldung
In this tutorial, we will instrument a simple class using Metrics AspectJ, and the Dropwizard Metrics @Timed annotation.
Read more >
Use annotation metrics - - Rackspace
The post explains how they used annotations to make events like releases appear in the performance graph, which provided valuable information ...
Read more >
Metrics Annotations - Project - MicroProfile
Annotated metrics are registered into the application MetricRegistry with the name computed using the rules in the following tables. If the metric annotation...
Read more >
Adding Annotations To Your Metrics Catalog | Transform Data
Using Annotations in Transform's Metrics Catalog helps you add context and answer questions about a metric's behavior, definition or other ...
Read more >
Adding Annotations to Elements | Adding Context to Metrics
Annotations allow you to share your insights on a Metric or Report with other users. You can apply an annotation to a single...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found