# Ruby: APM custom intrumentation not showing span in cronilogical order

**URL:** <https://discuss.elastic.co/t/ruby-apm-custom-intrumentation-not-showing-span-in-cronilogical-order/211335>\
**Category:** APM\
**Tags:** ruby\
**Created:** [December 10, 2019, 4:33pm UTC](https://discuss.elastic.co/t/ruby-apm-custom-intrumentation-not-showing-span-in-cronilogical-order/211335 "2019-12-10T16:33:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joe\_Santini](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/joe_santini/32/47985_2.png) [@Joe\_Santini](https://discuss.elastic.co/u/Joe_Santini)\
**Post date:** [December 10, 2019, 4:33pm UTC](https://discuss.elastic.co/t/ruby-apm-custom-intrumentation-not-showing-span-in-cronilogical-order/211335/1 "2019-12-10T16:33:28Z")

</div>

If you are asking about a problem you are experiencing, please use the following template, as it will help us help you. If you have a different problem, please delete all of this text 🙂

**Kibana version** : 7.5

**Elasticsearch version** : 7.5

**APM Server version** : 7.5

**APM Agent language and version** : Ruby 3.2.0

**Browser version** : Firefox

**Fresh install or upgraded from other version?**  
Fresh install

**Is there anything special in your setup?** For example, are you using the Logstash or Kafka outputs? Are you using a load balancer in front of the APM Servers? Have you changed index pattern, generated custom templates, changed agent configuration etc.  
We added a custom span for Typhoeus, as well as we had to add the transaction to any threads we spawn in our Rails transaction. We are using ConcurrentRuby for the threading.

**Description of the problem including expected versus actual behavior. Please include screenshots (if relevant)**:

View in Timeline shows spans out of order. It looks like the spans that are out of order are in the spans that come from the new threads. The main Rails thread shows all the span with a gap where the spawned threads are. Then after the Rails spans the threaded spans are shown. The environment in which this is happening does not allow me to take screenshots.  
I can add more information if needed. Also this could be the way I set up the Transaction in the thread. Is there any information for how to pass on the transaction?

We add the transaction to the thread as follows  
ElasticAPM.agent.instrumenter.current\_transaction = current\_transaction  
Where current\_transaction is  
current\_transaction = ElasticAPM.current\_transaction

---

<div class="post-metadata">

**Author:** ![mikker](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mikker/32/22118_2.png) [@mikker](https://discuss.elastic.co/u/mikker)\
**Post date:** [December 11, 2019, 12:27pm UTC](https://discuss.elastic.co/t/ruby-apm-custom-intrumentation-not-showing-span-in-cronilogical-order/211335/2 "2019-12-11T12:27:10Z")

</div>

Support for multi-threaded spans was just merged actually, [https://github.com/elastic/apm-agent-ruby/pull/571](https://github.com/elastic/apm-agent-ruby/pull/571).

Can you try setting it up with the master branch of the agent and see if it solves your problem?

---

<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:** [January 1, 2020, 8:27am UTC](https://discuss.elastic.co/t/ruby-apm-custom-intrumentation-not-showing-span-in-cronilogical-order/211335/3 "2020-01-01T08:27:16Z")

</div>

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