# How can I log response body in APM in python

**URL:** <https://discuss.elastic.co/t/how-can-i-log-response-body-in-apm-in-python/219733>\
**Category:** APM\
**Tags:** python\
**Created:** [February 18, 2020, 8:33am UTC](https://discuss.elastic.co/t/how-can-i-log-response-body-in-apm-in-python/219733 "2020-02-18T08:33:38Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![alza](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alza/32/50143_2.png) [@alza](https://discuss.elastic.co/u/alza)\
**Post date:** [February 19, 2020, 7:22am UTC](https://discuss.elastic.co/t/how-can-i-log-response-body-in-apm-in-python/219733/6 "2020-02-19T07:22:05Z")

</div>

I found the solution [here](https://discuss.elastic.co/t/how-to-add-contextual-information-with-flask-plugin/143066/5)! and accordingly changed my example as follow:

```auto
import elasticapm
from flask import Flask
from elasticapm.contrib.flask import ElasticAPM

app = Flask( __name__ )
app.config['ELASTIC_APM'] = {
    'DEBUG': True,
    'SERVER_URL': 'http://localhost:7200',
    'SERVICE_NAME': 'test-service',
}
apm = ElasticAPM(app)

@app.route('/')
def hello_world():
    resp = {"msg": "Hello world!"}
    elasticapm.set_custom_context({'body': resp})
    return 'OK'

if __name__ == ' __main__':
    app.run()

```

---

_[View the full topic](https://discuss.elastic.co/t/how-can-i-log-response-body-in-apm-in-python/219733)._
