elastic / elastic/logstash

Metrics exceptions supply misleading stack trace

Open
#8,153 4 comments 0 reactions 0 assignees View on GitHub
metrics v7.0.0-alpha1
Dominant language
Java
Stars
14.9k
Forks
3.5k
Avg merge
1d 4h
Merged PRs (30d)
88

Description

While discussing an integration test failure, the following stack trace was observed:

https://github.com/elastic/logstash/issues/8142#issuecomment-327483836

which looks like a failure attempting to increment the metrics counter by a negative value. Unfortunately, the stack trace is lost because of the static initialization of the Exception, which causes the stack trace to be constructed at the point the Counter class was initialized, rather than where the increment call was made from

To verify this, run the `incrementByNegativeValue` test in LongCounterTest.java, and observe the stack trace shows the stack trace from the first instantiation of LongCounter.java, and not where the error occurs:

```
java.lang.IllegalArgumentException: Counters can not be incremented by negative values
at org.logstash.instrument.metrics.counter.LongCounter.(LongCounter.java:15)
at org.logstash.instrument.metrics.counter.LongCounterTest._setup(LongCounterTest.java:21)
```

cc @jakelandis, @original-brownbear

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.