Build Status Gitter Maven Central

Getting Started

The kamon-servlet module brings traces and metrics to your servlet based applications.

Kamon Servlet is currently available for Scala 2.10, 2.11 and 2.12.

Supported releases and dependencies are shown below.

kamon-servlet-2.5 status jdk scala
1.0.0 stable 1.8+ 2.10, 2.11, 2.12
2.0.0 stable 1.8+ 2.11, 2.12, 2.13
kamon-servlet-3.x.x status jdk scala
1.0.0 stable 1.8+ 2.10, 2.11, 2.12
2.0.0 stable 1.8+ 2.11, 2.12, 2.13

To get kamon-servlet in your project:

  • Maven:
  • Gradle:
dependencies {
  compile 'io.kamon:kamon-servlet-3_2.12:2.0.0'
  • SBT:
libraryDependencies += "io.kamon" %% "kamon-servlet-3" % "2.0.0"

Setting up

All you need to do is to add the Kamon Filter on your Web App:

You should register it in the specific way your framework required. Otherwise, you need to configure it manually. Below there are some example.

Servlet v3+

You could programmatically register it using a ServletContextListener:

package kamon.servlet.v3.example;

import java.util.EnumSet;
import javax.servlet.DispatcherType;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import kamon.Kamon;
import kamon.servlet.v3.KamonFilterV3;

public class KamonContextListener implements ServletContextListener {

  public void contextInitialized(ServletContextEvent servletContextEvent) {
    // here you might subscribe all reporters you want. e.g. `Kamon.addReporter(new PrometheusReporter())`
        .addFilter("KamonFilter", new KamonFilterV3())
        .addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, "/*");

  public void contextDestroyed(ServletContextEvent arg0) {
    // in case you have subscribed some reporters: `Kamon.stopAllReporters();`
    System.out.println("KamonContextListener destroyed");

Servlet v2.5

For Servlet 2.5 there isn't a programmatic way to achieve it, so you have to define it in web.xml:



kamon-servlet uses TypeSafe Config. Default configuration is in resources/reference.conf for each subproject:

You can customize/override any property adding an application.conf in the /resources/ of your app or by providing System properties (e.g. -Dpath.of.your.key=value). This is the standard behavior of TypeSafe Config, for more info see its doc.

Micro Benchmarks

Execute from your terminal:

project benchmarks-3 # or benchmarks-25
jmh:run -i 50 -wi 20 -f1 -t1 .*Benchmark.*