# Applying APM transaction labels to child spans

**URL:** <https://discuss.elastic.co/t/applying-apm-transaction-labels-to-child-spans/258054>\
**Category:** APM\
**Tags:** java\
**Created:** [December 8, 2020, 9:41pm UTC](https://discuss.elastic.co/t/applying-apm-transaction-labels-to-child-spans/258054 "2020-12-08T21:41:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jaybee](https://avatars.discourse-cdn.com/v4/letter/j/6de8d8/32.png) [@Jaybee](https://discuss.elastic.co/u/Jaybee)\
**Post date:** [December 8, 2020, 9:41pm UTC](https://discuss.elastic.co/t/applying-apm-transaction-labels-to-child-spans/258054/1 "2020-12-08T21:41:51Z")

</div>

I'm currently setting transaction labels (e.g. user id and other transaction specific data) in my spring-boot based microservice, but that information doesn't get copied across to any subsequent child spans. Which means that when I view a collection of those child spans through Kibana I lose their context.

Ideally I'd like any labels I apply to a transaction to also be copied across to all child spans. Is this functionality already available in the APM agent?

At the moment I'm attempting to solve this problem with AspectJ, and trying to work out which methods in the agent I should be wrapping to detect when a new span has been created to allow me to set the labels on it. Unfortunately this is proving to be quite difficult.

---

<div class="post-metadata">

**Author:** ![Eyal\_Koren](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eyal_koren/32/36830_2.png) [@Eyal\_Koren](https://discuss.elastic.co/u/Eyal_Koren)\
**Post date:** [December 9, 2020, 7:19am UTC](https://discuss.elastic.co/t/applying-apm-transaction-labels-to-child-spans/258054/2 "2020-12-09T07:19:39Z")

</div>

Hi and welcome to our forum!

> [@Jaybee](#):
>
> Ideally I'd like any labels I apply to a transaction to also be copied across to all child spans. Is this functionality already available in the APM agent?

No, unfortunately it doesn't exist, nor it is planned.

I don't know how you aggregate and view spans, but maybe you can use spans' `transaction.id` field to extract the corresponding labels.

---

<div class="post-metadata">

**Author:** ![Jaybee](https://avatars.discourse-cdn.com/v4/letter/j/6de8d8/32.png) [@Jaybee](https://discuss.elastic.co/u/Jaybee)\
**Post date:** [December 9, 2020, 1:39pm UTC](https://discuss.elastic.co/t/applying-apm-transaction-labels-to-child-spans/258054/3 "2020-12-09T13:39:26Z")

</div>

Unfortunately Kibana doesn't really support joins for visualisations, which is why I'm trying to amend the spans before they get sent off to the APM Server.

I'm also looking at ByteBuddy as a way to intercept calls to the current span when it's activated. I don't know if there are any recommended ways to do this.

---

<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:** [December 30, 2020, 9:39am UTC](https://discuss.elastic.co/t/applying-apm-transaction-labels-to-child-spans/258054/4 "2020-12-30T09:39:48Z")

</div>

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