# How can i log http response body in apm

**URL:** <https://discuss.elastic.co/t/how-can-i-log-http-response-body-in-apm/138114>\
**Category:** APM\
**Created:** [July 2, 2018, 3:51am UTC](https://discuss.elastic.co/t/how-can-i-log-http-response-body-in-apm/138114 "2018-07-02T03:51:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![umapati](https://avatars.discourse-cdn.com/v4/letter/u/9d8465/32.png) [@umapati](https://discuss.elastic.co/u/umapati)\
**Post date:** [July 2, 2018, 3:51am UTC](https://discuss.elastic.co/t/how-can-i-log-http-response-body-in-apm/138114/1 "2018-07-02T03:51:17Z")

</div>

my current apm configuration is as follows:

config.apm = {  
serviceName: 'MyService',  
secretToken: '',  
serverUrl: 'localhost:5601',  
captureBody: 'all',  
instrument: 'true',  
errorOnAbortedRequests: 'true'  
};

var apm = require('elastic-apm-node').start({  
serviceName: config.apm.serviceName,  
secretToken: config.apm.secretToken,  
serverUrl: config.apm.serverUrl,  
captureBody: config.apm.captureBody,  
});

the http request body is captured correctly. I would like to know if there is an existing way to capture the response too.

---

<div class="post-metadata">

**Author:** ![wa7son](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wa7son/32/21259_2.png) [@wa7son](https://discuss.elastic.co/u/wa7son)\
**Post date:** [July 2, 2018, 7:32am UTC](https://discuss.elastic.co/t/how-can-i-log-http-response-body-in-apm/138114/2 "2018-07-02T07:32:37Z")

</div>

Not automatically, but if you have the body in a variable, you can attach it to the transaction manually by calling [`apm.setCustomContext()`](https://www.elastic.co/guide/en/apm/agent/nodejs/current/agent-api.html#apm-set-custom-context), eg:

```
apm.setCustomContext({
  responseBody: body
})

```

Just remember to call this function before the request have ended.

---

<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 23, 2018, 3:32am UTC](https://discuss.elastic.co/t/how-can-i-log-http-response-body-in-apm/138114/3 "2018-07-23T03:32:37Z")

</div>

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