# Custom Context vs Tags

**URL:** https://discuss.elastic.co/t/custom-context-vs-tags/151126
**Category:** APM
**Created:** [October 4, 2018, 9:53pm UTC](https://discuss.elastic.co/t/custom-context-vs-tags/151126 "2018-10-04T21:53:54Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![doug\_shareablee](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/doug_shareablee/32/35436_2.png) [@doug\_shareablee](https://discuss.elastic.co/u/doug_shareablee)
#### Post date: [October 4, 2018, 9:53pm UTC](https://discuss.elastic.co/t/custom-context-vs-tags/151126/1 "2018-10-04T21:53:54Z")

</div>

I'm instrumenting my code, and trying to add some context to the traces. I see there are two methods:  
[https://www.elastic.co/guide/en/apm/agent/python/current/api.html#api-set-custom-context](https://www.elastic.co/guide/en/apm/agent/python/current/api.html#api-set-custom-context)  
and  
[https://www.elastic.co/guide/en/apm/agent/python/current/api.html#api-tag](https://www.elastic.co/guide/en/apm/agent/python/current/api.html#api-tag)

Right now I'm setting both, and for example one goes into context.custom.my\_cool\_context\_key while the other is in context.tag.my\_cool\_context\_key. Otherwise they appear the same.

When should I use one over the other? Are there things that one can do that the other can not?

---

<div class="post-metadata">

### Author: ![beniwohli](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/beniwohli/32/21256_2.png) [@beniwohli](https://discuss.elastic.co/u/beniwohli)
#### Post date: [October 5, 2018, 11:16am UTC](https://discuss.elastic.co/t/custom-context-vs-tags/151126/2 "2018-10-05T11:16:34Z")

</div>

Hi Doug

great question! The main difference is that tags are indexed in Elasticsearch, while custom context is only stored, but not indexed. This means that you can filter and aggregate based on tags, but not on fields in your custom context.

However, custom context allows you to store more complex objects, while tags are only for key/value pairs of strings.

Hope this helps 🙂

---

<div class="post-metadata">

### Author: ![doug\_shareablee](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/doug_shareablee/32/35436_2.png) [@doug\_shareablee](https://discuss.elastic.co/u/doug_shareablee)
#### Post date: [October 5, 2018, 3:11pm UTC](https://discuss.elastic.co/t/custom-context-vs-tags/151126/3 "2018-10-05T15:11:30Z")

</div>

OK, I think that I may have taken

> This should be a flat key/value `dict` object.

too literally for the Custom Context. I see the use cases for each now.

---

<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 26, 2018, 11:11am UTC](https://discuss.elastic.co/t/custom-context-vs-tags/151126/4 "2018-10-26T11:11:36Z")

</div>

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