Custom Context vs Tags


(Doug Byrne) #1

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
and
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?


(Benjamin Wohlwend @ APM) #2

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 :slight_smile:


(Doug Byrne) #3

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.


(system) #4

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