kamon-io / kamon-play

Kamon Play Framework Integration
https://kamon.io/docs/latest/instrumentation/play-framework/
Other
28 stars 20 forks source link

Doubling count of requests #12

Closed ilya-nurullin closed 4 years ago

ilya-nurullin commented 7 years ago

Hello! I have a problem with doubling count of requests:

img

plugins.sbt:

// The Play plugin
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.5.15")

resolvers += Resolver.bintrayIvyRepo("kamon-io", "sbt-plugins")
addSbtPlugin("io.kamon" % "sbt-aspectj-play-runner" % "1.0.1")

build.sbt:

name := """monitoring"""
organization := "none"

version := "1.0-SNAPSHOT"

lazy val root = (project in file(".")).enablePlugins(PlayScala)

scalaVersion := "2.11.8"

libraryDependencies += "io.kamon" %% "kamon-core" % "0.6.7"
libraryDependencies += "io.kamon" % "kamon-play-2.5_2.11" % "0.6.7"
libraryDependencies += "io.kamon" % "kamon-influxdb_2.11" % "0.6.7"
libraryDependencies += "org.aspectj" % "aspectjweaver" % "1.8.10"
libraryDependencies += "io.kamon" % "sigar-loader" % "1.6.6-rev002"
libraryDependencies += "io.kamon" %% "kamon-system-metrics" % "0.6.7"

// Adds additional packages into Twirl
//TwirlKeys.templateImports += "none.controllers._"

// Adds additional packages into conf/routes
// play.sbt.routes.RoutesKeys.routesImport += "none.binders._"

application.conf:

kamon {

  metric {
    tick-interval = 5 second
  }

  influxdb {
    application-name = appName
    database = monitoring
    subscriptions {
      histogram       = [ "**" ]
      min-max-counter = [ "**" ]
      gauge           = [ "**" ]
      counter         = [ "**" ]
      trace           = [ "**" ]
      trace-segment   = [ "**" ]
      akka-actor      = [ "**" ]
      akka-dispatcher = [ "**" ]
      akka-router     = [ "**" ]
      system-metric   = [ "**" ]
      http-server     = [ "**" ]
    }
  }

  system-metrics {
    #sigar is enabled by default
    sigar-enabled = true

    #jmx related metrics are enabled by default
    jmx-enabled = true
  }

  play {
    include-trace-token-header = false
    trace-token-header-name = "X-Trace-Token"
  }

  modules {
  }
}

Filters.scala:

import javax.inject.Inject

import play.api.http.DefaultHttpFilters
import kamon.play.KamonFilter

class Filters @Inject() (kamonFilter: KamonFilter) extends DefaultHttpFilters(kamonFilter)

routes:

# Routes
# This file defines all application routes (Higher priority routes first)
# https://www.playframework.com/documentation/latest/ScalaRouting
# ~~~~

# An example controller showing a sample home page
GET        /                    controllers.HomeController.index
GET        /error               controllers.HomeController.errorReq

# Map static resources from the /public folder to the /assets URL path
GET        /assets/*file        controllers.Assets.versioned(path="/public", file: Asset)

HomeController.scala:

package controllers

import javax.inject._

import kamon.Kamon
import play.api.mvc._

@Singleton
class HomeController @Inject()() extends Controller {
  val counter = Kamon.metrics.counter("explicit_counter")

  def index() = Action {
    counter.increment()
    Ok("it works")
  }

  def errorReq() = Action {
    InternalServerError("Error")
  }

}
ivantopo commented 7 years ago

hey @ilya-nurullin, may I ask why are you adding the KamonFilter explicitly? The instrumentation will make sure that it is added without you needing to do anything explicitly so maybe in your example the filter is being added twice.. can you try again without adding the KamonFilter explicitly?

ilya-nurullin commented 7 years ago

@ivantopo Yes, everything works fine after removing the explicit addition of the KamonFilter. I didn't know that the filter was added automatically. Thank you!