Do not rely on a play app running to gather metrics

Fixes #44 
It is not a strong guarantee, but chances are Everest-high that code that
triggers initialization of this lazy val happens *after* an hypothetical
Play app is started; as opposed to loading the class, which may happen
earlier at any time.

A sure-fire solution would be to make this a def, but it looks a little bit
wasteful...

On Thu, Oct 9, 2014 at 12:56 PM, Lloyd <notifications@github.com> wrote:

> In app/com/m3/octoparts/OctopartsMetricsRegistry.scala:
>
> > @@ -0,0 +1,11 @@
> > +package com.m3.octoparts
> > +
> > +import com.codahale.metrics.SharedMetricRegistries
> > +import play.api.Play
> > +
> > +object OctopartsMetricsRegistry {
> > +  /**
> > +   * Same as [[com.kenshoo.play.metrics.MetricsRegistry.default]] when a Play app is running; uses the default name ("default") otherwise
> > +   */
> > +  lazy val default = SharedMetricRegistries.getOrCreate(Play.maybeApplication.flatMap(_.configuration.getString("metrics.name")).getOrElse("default"))
>
> You have no guarantees either way.
>
> —
> Reply to this email directly or view it on GitHub
> <https://github.com/m3dev/octoparts/pull/45/files#r18625798>.
>