THIS IS NOT USED
This library aims to provide a supporting framework to ease consistent implementation of non-functional platform concerns, including metrics, audit, alerting, and logging, within concrete Play 2.5 microservice applications. It is primarily a wrapper around play-events. However, the latter has been modified, extended, and implemented where necessary for the purposes of the TxM team.
TxM Events provides a Play 2.5 module which extends and replaces the Kenshoo Metrics module
com.kenshoo.play.metrics.PlayModule
. Out-of-the-box, this module makes available the following components:
LoggerEventHandler
: via implementationGuiceLoggerEventHandler
, a simple implementation which delegates to theDefaultLoggerEventHandler
from play-events.AlertEventHandler
: via implementationGuiceAlertEventHandler
, a simple implementation which delegates to theDefaultAlertEventHandler
from play-events.MetricsEventHandler
: via implementationKenshooMetricsEventHandler
AuditEventHandler
: via implementationGuiceAuditEventHandler
, a simple implementation which delegates to theAuditEventHandler
from from play-events.EventRecorder
: via implementationTxmEventRecorder
which defines the above components as the set of event handlers.TxmMonitor
: via implementationTxmThirdPartWebServiceCallMonitor
, a monitor designed to produce appropriate metrics and audits when wrapped around a call to a 3rd party web service.
@Singleton
class MyController @Inject()(txmMonitor: TxmMonitor) extends BaseController with WSGet {
private implicit val auditStrategy = MyAuditStrategy
def doSomething = Action.async { implicit req =>
val hc = HeaderCarrier.fromHeadersAndSession(req.headers)
txmMonitor.monitor[TheirResponse]("MyComponentName", "the-transaction-name") {
GET[TheirResponse]("http://foo.bar/baz")
} recover {
// exceptions thrown during monitoring bubble up so we can handle them here if necessary
case e: Exception => throw Upstream5xxResponse("Uh oh!", 500, 500)
}
}
}
// Default implementation does no auditing. We can override to modify details and tags on success and failure
object MyAuditStrategy extends AuditStrategy[TheirResponse] {
override def auditDataOnSuccess(resp: TheirResponse): Map[String, String] = Map("SomeKey" -> resp.someValue)
}
As a result of wrapping the GET
above with monitoring, we get count and timer metrics for the operation
(using the component and transaction name) and an audit message containing resp.someValue
if the call is successful.
The main play-events APIs are used. TxM events just provides event recorders and handlers as DI-able components via the Guice module. Refer to the play-events documentation.
This code is open source software licensed under the Apache 2.0 License.