# Incorrect Error Grouping for java apm client v 1.13

**URL:** <https://discuss.elastic.co/t/incorrect-error-grouping-for-java-apm-client-v-1-13/221578>\
**Category:** APM\
**Tags:** java, server\
**Created:** [March 1, 2020, 3:56pm UTC](https://discuss.elastic.co/t/incorrect-error-grouping-for-java-apm-client-v-1-13/221578 "2020-03-01T15:56:30Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![suikast42](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/suikast42/32/29865_2.png) [@suikast42](https://discuss.elastic.co/u/suikast42)\
**Post date:** [March 1, 2020, 3:56pm UTC](https://discuss.elastic.co/t/incorrect-error-grouping-for-java-apm-client-v-1-13/221578/1 "2020-03-01T15:56:31Z")

</div>

I have the same issue with the 7.6.0 stack and java apm agent 1.13.

like [Incorrect Error Grouping](https://discuss.elastic.co/t/incorrect-error-grouping/215939/2):

The errors is grouped by the excpetion class types. The messages are not considired.

The apm java agent provides only a single captureException method.

---

<div class="post-metadata">

**Author:** ![Sylvain\_Juge](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sylvain_juge/32/55521_2.png) [@Sylvain\_Juge](https://discuss.elastic.co/u/Sylvain_Juge)\
**Post date:** [March 2, 2020, 3:29pm UTC](https://discuss.elastic.co/t/incorrect-error-grouping-for-java-apm-client-v-1-13/221578/2 "2020-03-02T15:29:35Z")

</div>

Hi @suikast42,

Errors are grouped by exception types and stack traces, which means that two exceptions with same exception type thrown from different places will not be the same.

If those exceptions differ only by the error message, can you explain a bit the code structure that throws and captures the exceptions ? Properly chained exceptions (that are created with a cause) will result in distinct stack traces.

Also, do you have any JSON documents for such errors that have the same `grouping_key` but are actually different exceptions ?

---

<div class="post-metadata">

**Author:** ![suikast42](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/suikast42/32/29865_2.png) [@suikast42](https://discuss.elastic.co/u/suikast42)\
**Post date:** [March 6, 2020, 8:34am UTC](https://discuss.elastic.co/t/incorrect-error-grouping-for-java-apm-client-v-1-13/221578/3 "2020-03-06T08:34:54Z")

</div>

That's my apm testcase

```
        final Transaction transaction = ElasticApm.startTransaction();
        transaction.setType("custom");
        transaction.setName("Foo");
        try (Scope trScope = transaction.activate()) {

            try {
                throw new RuntimeException("In tr");
            } catch (Exception e) {
// logger.error("In tr", e);
                transaction.captureException(e);
            }

            {
                final Span span = transaction.startSpan("a", "b", "c");
                try (Scope spnScope = span.activate()) {
                    throw new RuntimeException("In Span 1");
                } catch (Exception e) {
// logger.error("In span", e);
                    span.captureException(e);
                } finally {
                    span.end();
                }

            }

            {
                final Span span = transaction.startSpan("a", "b", "c");
                try (Scope spnScope = span.activate()) {
                    throw new RuntimeException("In Span 2");
                } catch (Exception e) {
// logger.error("In span", e);
                    span.captureException(e);
                } finally {
                    span.end();
                }
            }

        } finally {
            transaction.end();
        }
    }

```

So the stack traces are diffrent and the messages as well.

This is the result of APM view

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/0/5/05c3fabdf61db680f731d6e685b1fbcd68a28107.png)

---

<div class="post-metadata">

**Author:** ![suikast42](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/suikast42/32/29865_2.png) [@suikast42](https://discuss.elastic.co/u/suikast42)\
**Post date:** [March 10, 2020, 7:24am UTC](https://discuss.elastic.co/t/incorrect-error-grouping-for-java-apm-client-v-1-13/221578/4 "2020-03-10T07:24:58Z")

</div>

@felixbarny do you have a suggestion on this topic ?

---

<div class="post-metadata">

**Author:** ![felixbarny](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/felixbarny/32/27341_2.png) [@felixbarny](https://discuss.elastic.co/u/felixbarny)\
**Post date:** [March 10, 2020, 8:00am UTC](https://discuss.elastic.co/t/incorrect-error-grouping-for-java-apm-client-v-1-13/221578/5 "2020-03-10T08:00:48Z")

</div>

This is a bit of a contrived example. In a real world application you would likely throw those exceptions in different methods. When you do that the exceptions have different stack traces and, hence, a different error Group ID. The message of the exception is not taken into consideration as it often contains dynamic parameters. Example form the JDK:

```auto
    static NumberFormatException forInputString(String s) {
        return new NumberFormatException("For input string: \"" + s + "\"");
    }

```

You wouldn't want to have different grouping keys for different inputs that have been thrown in the same method.

---

<div class="post-metadata">

**Author:** ![suikast42](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/suikast42/32/29865_2.png) [@suikast42](https://discuss.elastic.co/u/suikast42)\
**Post date:** [March 10, 2020, 8:05am UTC](https://discuss.elastic.co/t/incorrect-error-grouping-for-java-apm-client-v-1-13/221578/6 "2020-03-10T08:05:38Z")

</div>

I am not agree with that.

I can catch and log some business exceptions in the same boundary call. But they will have the same grouping key ?

---

<div class="post-metadata">

**Author:** ![felixbarny](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/felixbarny/32/27341_2.png) [@felixbarny](https://discuss.elastic.co/u/felixbarny)\
**Post date:** [March 10, 2020, 8:20am UTC](https://discuss.elastic.co/t/incorrect-error-grouping-for-java-apm-client-v-1-13/221578/7 "2020-03-10T08:20:22Z")

</div>

If they have the same exception type, the same stack trace (including same cause), then yes, they'll have the same grouping key.

> [@suikast42](#):
>
> I can catch and log some business exceptions in the same boundary call.

In that case the exception type or stack trace would likely be different as they'd be thrown by different methods, right?

---

<div class="post-metadata">

**Author:** ![felixbarny](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/felixbarny/32/27341_2.png) [@felixbarny](https://discuss.elastic.co/u/felixbarny)\
**Post date:** [March 10, 2020, 8:40am UTC](https://discuss.elastic.co/t/incorrect-error-grouping-for-java-apm-client-v-1-13/221578/8 "2020-03-10T08:40:57Z")

</div>

To add to that: the line number of stack traces are not considered in the grouping key. The reason is that line numbers change much more frequently in-between releases than method names. And you wouldn't want to see a new grouping key when just an empty line has been removed, for example.

---

<div class="post-metadata">

**Author:** ![suikast42](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/suikast42/32/29865_2.png) [@suikast42](https://discuss.elastic.co/u/suikast42)\
**Post date:** [March 10, 2020, 8:46am UTC](https://discuss.elastic.co/t/incorrect-error-grouping-for-java-apm-client-v-1-13/221578/9 "2020-03-10T08:46:08Z")

</div>

Ok I am agree with that now 😃

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [March 31, 2020, 4:46am UTC](https://discuss.elastic.co/t/incorrect-error-grouping-for-java-apm-client-v-1-13/221578/10 "2020-03-31T04:46:11Z")

</div>

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.
