# About the principle of error.grouping\_key

**URL:** <https://discuss.elastic.co/t/about-the-principle-of-error-grouping-key/283622>\
**Category:** APM\
**Tags:** dotnet, server\
**Created:** [September 8, 2021, 8:12am UTC](https://discuss.elastic.co/t/about-the-principle-of-error-grouping-key/283622 "2021-09-08T08:12:10Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![wajika](https://avatars.discourse-cdn.com/v4/letter/w/977dab/32.png) [@wajika](https://discuss.elastic.co/u/wajika)\
**Post date:** [September 8, 2021, 8:12am UTC](https://discuss.elastic.co/t/about-the-principle-of-error-grouping-key/283622/1 "2021-09-08T08:12:10Z")

</div>

When service.name, url\_path, and type are the same, why sometimes the id is the same, sometimes not the same id  
I want to know the error\_group\_id calculated according to what formula？

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/7/5/752a525cacb670530156fd9ddf14a7377a6c93f0.png)  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/c/2/c241178f4231e231048f68d6f54eae80c95c45d4.png)  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/5/e/5e1334a56c2e97aea073adc087c48091b9656376.png)

Is the same event generated at two time points an error\_group\_id?  
for example:

```auto
2021.9.6 01:01:01 
Lonsid_IOT_Web_Host	/api/iot/iOTDevice/getLSDIOTDeviceByNo	Abp.UI.UserFriendlyException	设备数据不存在！

2021.9.8 01:01:01 
Lonsid_IOT_Web_Host	/api/iot/iOTDevice/getLSDIOTDeviceByNo	Abp.UI.UserFriendlyException	设备数据不存在！

```

---

<div class="post-metadata">

**Author:** ![axw](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/axw/32/28197_2.png) [@axw](https://discuss.elastic.co/u/axw)\
**Post date:** [September 10, 2021, 2:14am UTC](https://discuss.elastic.co/t/about-the-principle-of-error-grouping-key/283622/2 "2021-09-10T02:14:50Z")

</div>

@wajika the error grouping key is used for grouping multiple instances of similar errors, using a hash of the stack trace and other properties. You can find the specific details of the algorithm at [https://github.com/elastic/apm-server/blob/master/model/modelprocessor/groupingkey.go](https://github.com/elastic/apm-server/blob/master/model/modelprocessor/groupingkey.go)

We use this in the APM UI, on the service errors page:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/7/2/72a55fd58060deb514ca514aef35ff5ad715c97e.png)

Each row corresponds to a unique `error.grouping_key` value. `Occurrences` counts how many errors have the same grouping key value, and `Last occurrence` shows the time since the most recent error with that grouping key value.

---

<div class="post-metadata">

**Author:** ![wajika](https://avatars.discourse-cdn.com/v4/letter/w/977dab/32.png) [@wajika](https://discuss.elastic.co/u/wajika)\
**Post date:** [September 10, 2021, 6:34am UTC](https://discuss.elastic.co/t/about-the-principle-of-error-grouping-key/283622/3 "2021-09-10T06:34:40Z")

</div>

Thank you for your reply, what you mean is similar to what I expected, but why in the third picture, the same service.name, url\_path, type, message will generate multiple error\_group\_id?

---

<div class="post-metadata">

**Author:** ![axw](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/axw/32/28197_2.png) [@axw](https://discuss.elastic.co/u/axw)\
**Post date:** [September 10, 2021, 8:02am UTC](https://discuss.elastic.co/t/about-the-principle-of-error-grouping-key/283622/4 "2021-09-10T08:02:49Z")

</div>

The grouping key will change if the exception stack trace is different, even if the message and exception type are the same. Maybe the exception is being thrown in two different code locations?

---

<div class="post-metadata">

**Author:** ![wajika](https://avatars.discourse-cdn.com/v4/letter/w/977dab/32.png) [@wajika](https://discuss.elastic.co/u/wajika)\
**Post date:** [September 12, 2021, 7:56am UTC](https://discuss.elastic.co/t/about-the-principle-of-error-grouping-key/283622/5 "2021-09-12T07:56:52Z")

</div>

I am a little bit understanding  
Maybe the exception is being thrown in two different code locations?  
If an exception is thrown in two code locations, why is the same error? For example, A function calls B function and C function calls B function. If an error occurs, is APM recorded as the code location of B function?  
Sorry, I may not be able to describe it clearly.

---

<div class="post-metadata">

**Author:** ![axw](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/axw/32/28197_2.png) [@axw](https://discuss.elastic.co/u/axw)\
**Post date:** [September 13, 2021, 2:12am UTC](https://discuss.elastic.co/t/about-the-principle-of-error-grouping-key/283622/6 "2021-09-13T02:12:31Z")

</div>

> If an exception is thrown in two code locations, why is the same error? For example, A function calls B function and C function calls B function. If an error occurs, is APM recorded as the code location of B function?

They should have different grouping keys in this case. The grouping key calculates a hash of the full stack trace: e.g. if A calls B, then the grouping key will include details of both A and B.

Example:

```go
func a() {
    c()
}

func b() {
    c()
}

func c() {
    panic("an error occurred")
}

```

- If `a` is called, it will call `c` and panic. The grouping key is a hash of "a" and "c"
- If `b` is called, it will call `c` and panic. The grouping key is a hash of "b" and "c"

So they will be different, because even though the error occurs in `c`, the stack trace is different -- the code took a different path to get there. But each time `a` is called, it will have the same grouping key as every other time `a` is called.

---

<div class="post-metadata">

**Author:** ![wajika](https://avatars.discourse-cdn.com/v4/letter/w/977dab/32.png) [@wajika](https://discuss.elastic.co/u/wajika)\
**Post date:** [September 15, 2021, 2:23am UTC](https://discuss.elastic.co/t/about-the-principle-of-error-grouping-key/283622/7 "2021-09-15T02:23:42Z")

</div>

Sorry for my late reply, because something was delayed.

As you said, in the following code, the error group id of a() and b() are the same, right?

```auto
func a() {
    c()
}

func b() {
    c()
}

func c() {
    d()
}

func d() {
    panic("an error occurred")
}

```

We plan to use the error group id to determine whether a function has been repaired. I think we can use this id. Now it should be possible.

---

<div class="post-metadata">

**Author:** ![axw](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/axw/32/28197_2.png) [@axw](https://discuss.elastic.co/u/axw)\
**Post date:** [September 15, 2021, 2:40am UTC](https://discuss.elastic.co/t/about-the-principle-of-error-grouping-key/283622/8 "2021-09-15T02:40:59Z")

</div>

> [@wajika](#):
>
> As you said, in the following code, the error group id of a() and b() are the same, right?

No, they will have two different grouping IDs.

- a(): `hash(a+c+d)`
- b(): `hash(b+c+d)`

---

<div class="post-metadata">

**Author:** ![wajika](https://avatars.discourse-cdn.com/v4/letter/w/977dab/32.png) [@wajika](https://discuss.elastic.co/u/wajika)\
**Post date:** [September 15, 2021, 3:30am UTC](https://discuss.elastic.co/t/about-the-principle-of-error-grouping-key/283622/9 "2021-09-15T03:30:38Z")

</div>

OK, thank you for your patience.

---

<div class="post-metadata">

**Author:** ![wajika](https://avatars.discourse-cdn.com/v4/letter/w/977dab/32.png) [@wajika](https://discuss.elastic.co/u/wajika)\
**Post date:** [September 17, 2021, 3:48am UTC](https://discuss.elastic.co/t/about-the-principle-of-error-grouping-key/283622/10 "2021-09-17T03:48:36Z")

</div>

![image](https://us1.discourse-cdn.com/elastic/original/3X/5/e/5e1334a56c2e97aea073adc087c48091b9656376.png)  
To interrupt, I would like to once again ask for your help, you can explain the situation again at this image?

---

<div class="post-metadata">

**Author:** ![axw](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/axw/32/28197_2.png) [@axw](https://discuss.elastic.co/u/axw)\
**Post date:** [September 20, 2021, 1:08am UTC](https://discuss.elastic.co/t/about-the-principle-of-error-grouping-key/283622/11 "2021-09-20T01:08:24Z")

</div>

I can only guess that the same exception is occurring in several different stack traces. You can confirm this by selecting error documents with different `error.grouping_key` values, and comparing their `error.exception.stacktrace` fields. If they are different, then that would explain why they have different grouping key values.

---

<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:** [October 10, 2021, 9:08pm UTC](https://discuss.elastic.co/t/about-the-principle-of-error-grouping-key/283622/12 "2021-10-10T21:08:35Z")

</div>

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