# Custom field (tag, label, whatever...) available in transaction and subsequent spans (without defining them)

**URL:** https://discuss.elastic.co/t/custom-field-tag-label-whatever-available-in-transaction-and-subsequent-spans-without-defining-them/185775
**Category:** APM
**Tags:** rum
**Created:** [June 14, 2019, 6:52am UTC](https://discuss.elastic.co/t/custom-field-tag-label-whatever-available-in-transaction-and-subsequent-spans-without-defining-them/185775 "2019-06-14T06:52:09Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![J\_Weeda](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/j_weeda/32/45092_2.png) [@J\_Weeda](https://discuss.elastic.co/u/J_Weeda)
#### Post date: [June 14, 2019, 6:52am UTC](https://discuss.elastic.co/t/custom-field-tag-label-whatever-available-in-transaction-and-subsequent-spans-without-defining-them/185775/1 "2019-06-14T06:52:10Z")

</div>

**Kibana version** : 7.0.0

**Elasticsearch version** : 7.0.0

**APM Server version** : 7.0.0

**APM Agent language and version** :  
agent.name js-base  
agent.version 4.0.2

Elasticstack hosted on Elastic Cloud.

We are trying to add a custom field which is available in both the transaction and all subsequent spans without having to specify the spans. Would you have a way to accomodate that?

Below calls only populate the transaction docs.

```
  transaction.addTags({'team': 'Tag'});
  elasticApm.setCustomContext({'team': 'Context'});
```

---

<div class="post-metadata">

### Author: ![Hamidreza](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hamidreza/32/21369_2.png) [@Hamidreza](https://discuss.elastic.co/u/Hamidreza)
#### Post date: [June 14, 2019, 11:25am UTC](https://discuss.elastic.co/t/custom-field-tag-label-whatever-available-in-transaction-and-subsequent-spans-without-defining-them/185775/2 "2019-06-14T11:25:54Z")

</div>

Hi @J_Weeda,

Thanks for reaching out.  
At the moment, this is not possible. We try to mindful of the extra information we put on spans since they can increase the payload and storage costs.

Would you please explain a little bit more about your use-case?

Cheers,  
Hamid

---

<div class="post-metadata">

### Author: ![J\_Weeda](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/j_weeda/32/45092_2.png) [@J\_Weeda](https://discuss.elastic.co/u/J_Weeda)
#### Post date: [June 14, 2019, 1:50pm UTC](https://discuss.elastic.co/t/custom-field-tag-label-whatever-available-in-transaction-and-subsequent-spans-without-defining-them/185775/3 "2019-06-14T13:50:31Z")

</div>

Hi @Hamidreza , ty for your reply. As per your question; we are trying to maintain multitenancy on doc level. This implies roles which have access to specific documents limited by following statement in the _Granted documents query_ field in the Role definition:

{"term":{"team":"team\_A"}}

This worked fine on any docs we ingested from Beats but now APM comes into play which doesn't give us the document level control we require. Makes sense? Any recommendations?

---

<div class="post-metadata">

### Author: ![Hamidreza](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hamidreza/32/21369_2.png) [@Hamidreza](https://discuss.elastic.co/u/Hamidreza)
#### Post date: [June 18, 2019, 8:41am UTC](https://discuss.elastic.co/t/custom-field-tag-label-whatever-available-in-transaction-and-subsequent-spans-without-defining-them/185775/4 "2019-06-18T08:41:29Z")

</div>

Thank you for the explanation. That makes a lot of sense. I have created [this issue](https://github.com/elastic/apm/issues/99) to address this request.

---

<div class="post-metadata">

### Author: ![roncohen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/roncohen/32/22881_2.png) [@roncohen](https://discuss.elastic.co/u/roncohen)
#### Post date: [June 18, 2019, 11:12am UTC](https://discuss.elastic.co/t/custom-field-tag-label-whatever-available-in-transaction-and-subsequent-spans-without-defining-them/185775/5 "2019-06-18T11:12:56Z")

</div>

Hi @J_Weeda

If you run an APM Server per tenant/customer, you can set each one up to write to a specific pipeline that would add the fields you need to do index level security. You could also add a processor in APM Server to get the field added, but it's not currently documented.

Would this be an option for you?

best,  
Ron

---

<div class="post-metadata">

### Author: ![J\_Weeda](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/j_weeda/32/45092_2.png) [@J\_Weeda](https://discuss.elastic.co/u/J_Weeda)
#### Post date: [June 27, 2019, 1:02pm UTC](https://discuss.elastic.co/t/custom-field-tag-label-whatever-available-in-transaction-and-subsequent-spans-without-defining-them/185775/6 "2019-06-27T13:02:00Z")

</div>

hi @roncohen, thanks. Yes, it would be an option for a later stage where we need to scale up. For now we need to stick to a single instance.

We found a way to get the desired in place. We abuse the service field using a delimited value `team#service` and strip and write the `team` value to a dedicated field through logstash.

Thank you for your thoughts and views.

---

<div class="post-metadata">

### Author: ![roncohen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/roncohen/32/22881_2.png) [@roncohen](https://discuss.elastic.co/u/roncohen)
#### Post date: [June 27, 2019, 1:30pm UTC](https://discuss.elastic.co/t/custom-field-tag-label-whatever-available-in-transaction-and-subsequent-spans-without-defining-them/185775/7 "2019-06-27T13:30:17Z")

</div>

Cool @J_Weeda. Another potential option is to use Attribute Based Access Control to limit certain roles to documents that have certain `services.name`: [https://www.elastic.co/blog/attribute-based-access-control-with-xpack](https://www.elastic.co/blog/attribute-based-access-control-with-xpack)

---

<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: [July 18, 2019, 9:30am UTC](https://discuss.elastic.co/t/custom-field-tag-label-whatever-available-in-transaction-and-subsequent-spans-without-defining-them/185775/8 "2019-07-18T09:30:18Z")

</div>

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