# Span.End() method seems to lock the application in certain cases

**URL:** <https://discuss.elastic.co/t/span-end-method-seems-to-lock-the-application-in-certain-cases/271960>\
**Category:** APM\
**Tags:** go\
**Created:** [May 3, 2021, 10:01am UTC](https://discuss.elastic.co/t/span-end-method-seems-to-lock-the-application-in-certain-cases/271960 "2021-05-03T10:01:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![javiersotodev](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/javiersotodev/32/88121_2.png) [@javiersotodev](https://discuss.elastic.co/u/javiersotodev)\
**Post date:** [May 3, 2021, 10:01am UTC](https://discuss.elastic.co/t/span-end-method-seems-to-lock-the-application-in-certain-cases/271960/1 "2021-05-03T10:01:24Z")

</div>

We recently implemented our apm Custom spans in our code (that processes kafka messages in a high speed) and thanks to one of our processes timeouts and further debug logging we catch that a custom Span End method was causing the program to freeze in that line of code.  
We tried with the `defer span.End()` and as a normal function called and the application froze regardless. After removing the span, we did not see the problem anymore, confirming it was there the problem.  
We have set up a 60 s timeout in our parent transaction timeout, but does nothing in relation to that issue.  
Any idea what may cause this?  
APM Agent Golang version v1.11.0

---

<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:** [May 3, 2021, 12:03pm UTC](https://discuss.elastic.co/t/span-end-method-seems-to-lock-the-application-in-certain-cases/271960/2 "2021-05-03T12:03:39Z")

</div>

@javiersotodev welcome to the forum! Sorry to hear you're experiencing this issue.

This is certainly not expected, and we haven't had any similar reports. We'll need some more information to debug.

Can you please share a stack trace dump? If you're not familiar with how to do this, [Debugging Go with stack traces (evanjones.ca)](https://www.evanjones.ca/go-stack-traces.html) has some tips.

---

<div class="post-metadata">

**Author:** ![javiersotodev](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/javiersotodev/32/88121_2.png) [@javiersotodev](https://discuss.elastic.co/u/javiersotodev)\
**Post date:** [May 3, 2021, 7:51pm UTC](https://discuss.elastic.co/t/span-end-method-seems-to-lock-the-application-in-certain-cases/271960/3 "2021-05-03T19:51:35Z")

</div>

It has been hard to reproduce in our lower environments as it happened in production (probably due to a high volume) While i implement the debug stack trace and replicating the incident:

- What is it the better way to implement custom spans, implementing them from the transaction or the parent's transaction context? Because it doesnt throw any errors when it freezes, we are mostly blind in this.
- We send our contexts into go routines to track spans inside the main transaction, with their respectives `end()` methods in defer.  
Any Help or advice would be appreciated while i get the trace stack for you  
Thank you

---

<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:** [May 4, 2021, 1:42am UTC](https://discuss.elastic.co/t/span-end-method-seems-to-lock-the-application-in-certain-cases/271960/4 "2021-05-04T01:42:52Z")

</div>

> [@](#):
>
> - What is it the better way to implement custom spans, implementing them from the transaction or the parent's transaction context? Because it doesnt throw any errors when it freezes, we are mostly blind in this.

Are you asking if it's better to use `Transaction.StartSpan(...)` vs. `apm.StartSpan(ctx, ...)`? If so, neither is generally better than the other. `apm.StartSpan` will internally call `Transaction.StartSpan`. I would say the context approach is typically most appropriate though.

> We send our contexts into go routines to track spans inside the main transaction, with their respectives `end()` methods in defer.

This should be fine.

---

<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:** [May 24, 2021, 9:43pm UTC](https://discuss.elastic.co/t/span-end-method-seems-to-lock-the-application-in-certain-cases/271960/5 "2021-05-24T21:43:27Z")

</div>

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