# Python agent are not filling context.user.ip field?

**URL:** <https://discuss.elastic.co/t/python-agent-are-not-filling-context-user-ip-field/170092>\
**Category:** APM\
**Created:** [February 27, 2019, 3:35am UTC](https://discuss.elastic.co/t/python-agent-are-not-filling-context-user-ip-field/170092 "2019-02-27T03:35:13Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![fr0der1c](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/fr0der1c/32/34125_2.png) [@fr0der1c](https://discuss.elastic.co/u/fr0der1c)\
**Post date:** [February 27, 2019, 3:35am UTC](https://discuss.elastic.co/t/python-agent-are-not-filling-context-user-ip-field/170092/1 "2019-02-27T03:35:13Z")

</div>

**Kibana version** : 6.6.0

**Elasticsearch version** :6.6.0

**APM Server version** :6.6.0

**APM Agent language and version** : Python 4.1.0

I notice there is a `context.user.ip` field according to APM-Server doc. Is there any reason the Python agent not automatically fill in this field? I want to do a user IP pie chart visualization and I found the Python agent didn't collect this information.

`elasticapm.set_user_context()` don't have a IP field either.

---

<div class="post-metadata">

**Author:** ![axw](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/axw/32/28197_2.png) [@axw](https://discuss.elastic.co/u/axw)\
**Post date:** [February 27, 2019, 4:03am UTC](https://discuss.elastic.co/t/python-agent-are-not-filling-context-user-ip-field/170092/2 "2019-02-27T04:03:59Z")

</div>

`context.user.ip` is set by the APM Server, but only for RUM (browser) transactions. For other transactions, `context.system.ip` is recorded, but that's the IP of the system on which the agent is running.

For the end-user IP, you can use `context.request.socket.remote_address`. See [https://www.elastic.co/guide/en/apm/server/current/transaction-indices.html](https://www.elastic.co/guide/en/apm/server/current/transaction-indices.html) for an example.

---

<div class="post-metadata">

**Author:** ![fr0der1c](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/fr0der1c/32/34125_2.png) [@fr0der1c](https://discuss.elastic.co/u/fr0der1c)\
**Post date:** [February 27, 2019, 4:21am UTC](https://discuss.elastic.co/t/python-agent-are-not-filling-context-user-ip-field/170092/3 "2019-02-27T04:21:56Z")

</div>

Thank you.  
I see `context.request.socket.remote_address` is not in Kibana index patterns by default. Do I have to use Elasticsearch Mapping API to make this field aggregatable in order to make a user IP pie chart?

---

<div class="post-metadata">

**Author:** ![axw](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/axw/32/28197_2.png) [@axw](https://discuss.elastic.co/u/axw)\
**Post date:** [March 1, 2019, 2:02am UTC](https://discuss.elastic.co/t/python-agent-are-not-filling-context-user-ip-field/170092/4 "2019-03-01T02:02:28Z")

</div>

Sorry for the late reply. Yes, you'll need to modify the mapping to index it, giving it an `ip` type. There is an experimental configuration in the server to simplify doing this, but we found a bug that prevents it from being used in this case: [https://github.com/elastic/apm-server/issues/1959](https://github.com/elastic/apm-server/issues/1959).

If you update the `apm-6.6` template, then new daily indices will be created with this mapping. If you want to be able to chart existing data, you will need to reindex.

---

<div class="post-metadata">

**Author:** ![fr0der1c](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/fr0der1c/32/34125_2.png) [@fr0der1c](https://discuss.elastic.co/u/fr0der1c)\
**Post date:** [March 3, 2019, 1:49am UTC](https://discuss.elastic.co/t/python-agent-are-not-filling-context-user-ip-field/170092/5 "2019-03-03T01:49:34Z")

</div>

Thank you for your suggestion. I end up in using Filebeat Nginx log to build my visitor IP pie chart.

---

<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:** [March 23, 2019, 9:49pm UTC](https://discuss.elastic.co/t/python-agent-are-not-filling-context-user-ip-field/170092/6 "2019-03-23T21:49:42Z")

</div>

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