Get request correlation id on custom plugin

Hi,

Is it possible to get the request correlation id that is displayed in the logs (field "i") on a plugin?

info sourceRequest m=GET, u=/echo, h=localhost:8090,
i=b177c580-854e-11e8-8824-d96d3e13eaec 
Or this id is for EMG internal use only?

I know this id is generated here: https://github.com/apigee/microgateway-core/blob/master/lib/plugins-middleware.js#L30 and i was wondering if it's possible to get this value on a custom plugin.

Thanks,

0 3 1,023
3 REPLIES 3

Former Community Member
Not applicable

You should be able to see it in the "x-request-id" header. In the config.yaml file, if you have enabled request-id, then you should see

headers:
...
  x-request-id: true
...

Hey @srinandans, thanks for your answer..

I have the x-request-id header enabled in the configuration, but according to the source code, the x-request-id will be set as a header only in the request between EMG and the target, during the targetRequest event..

https://github.com/apigee/microgateway-core/blob/master/lib/plugins-middleware.js#L123-L127

During the plugin chain execution between the sourceRequest (EMG receiving the request) and the targetRequest (request sent from EMG to the target) this id is not set as the x-request-id yet.

I want to use this value in my plugin chain during the whole request / response flows.


on response, just set the response header to the value of request header:

res.setHeader('x-correlation-id', req.correlationId);