[2.1-scala] An example of Play 2.1 Filters

580 views
Skip to first unread message

Roberto Tyley

unread,
Jan 18, 2013, 5:16:26 AM1/18/13
to play-fr...@googlegroups.com
Play 2.1 Filters aren't heavily documented yet, so I thought some might like to see an example of their use - we've just updated our management-and-metrics library at the Guardian ("guardian-management") to use Play 2.1 Filters. The Filters framework makes it very easy for us to gather timing and http-status-code statistics on the responses we're passing back to the user. The filters are defined here:


They're extremely simple, perhaps the only thing worth watching out for is the use of onFinalPlainResult() against the Scala 2.10 Future used by AsyncResult, ensuring we only time & count the response once it's fully completed.

The library includes an example of it's use in a example Play project:

https://github.com/guardian/guardian-management/blob/v5.23/example-play/app/Global.scala#L4 - registers them as Play filters so they can start counting requests

The statistics are then available as a JSON endpoint on a separate port (eg localhost:18080/management/status, while your Play app might be running on port 9000). This makes it easy to keep the stats private, and also ensures that hitting the management & status urls won't increment the stats themselves. Finally, the stats are read by a monitoring service like Graphite/Ganglia.

best regards,
Roberto Tyley


Guillaume Bort

unread,
Jan 18, 2013, 6:47:06 AM1/18/13
to play-fr...@googlegroups.com
Cool thanks.



--
 
 



--
Guillaume Bort, http://guillaume.bort.fr

Nilanjan Raychaudhuri

unread,
Jan 18, 2013, 9:20:48 AM1/18/13
to play-fr...@googlegroups.com
Very cool.

Nilanjan, Developer & Consultant
Typesafe Inc.
Twitter: @nraychaudhuri
Reply all
Reply to author
Forward
0 new messages