coderberry / airbrake-grails

Airbrake Client for Grails
4 stars 7 forks source link

make environment configuration more flexible #41

Open ghost opened 9 years ago

ghost commented 9 years ago

I would like to set Notice.env to the hostname (I realise that the host is already available in Notice.hostname, but this field is not displayed on Errbit's error list screen, whereas the environment is).

AFAIK, the only reliable way to get the hostname is from the request object, e.g.

RequestContextHolder.requestAttributes?.currentRequest?.getHeader('X-Forwarded-Host')

However, if I configure

grails.plugins.airbrake.env = RequestContextHolder.requestAttributes?.currentRequest?.getHeader('X-Forwarded-Host')

this won't work, because there is no request object when this configuration is read. Instead, I would like to be able to do this

grails.plugins.airbrake.env = { RequestAttributes webRequest ->
    webRequest?.currentRequest?.getHeader('X-Forwarded-Host')
}

@cavneb if you've no objection to this (and are willing to release a new version that includes this change), could you let me know, and I'll send a pull-request with the relevant code changes?

I'll make this change such that it's backwards compatible, i.e. the environment will be resolved by passing the current request into the closure above only if a closure is assigned to grails.plugins.airbrake.env.

jonspalmer commented 9 years ago

I'm not sure I understand the need to make this driven from the webRequest. Why can't you set grails.plugins.airbrake.env in each environment that you deploy to and map it to whatever you want?