https://github.com/kamon-io/kamon-servlet
https://github.com/kamon-io/kamon-servlet
Last synced: 11 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/kamon-io/kamon-servlet
- Owner: kamon-io
- License: apache-2.0
- Created: 2018-03-21T14:29:21.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2020-03-24T19:59:27.000Z (almost 6 years ago)
- Last Synced: 2025-02-26T15:31:15.606Z (11 months ago)
- Language: Scala
- Size: 131 KB
- Stars: 0
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# Kamon-Servlet
[](https://travis-ci.org/kamon-io/kamon-servlet)
[](https://gitter.im/kamon-io/Kamon?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[](https://maven-badges.herokuapp.com/maven-central/io.kamon/kamon-servlet_2.12)
### Getting Started
The `kamon-servlet` module brings traces and metrics to your [servlet][1] 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:
```xml
io.kamon
kamon-servlet-3_2.12
2.0.0
```
* Gradle:
```groovy
dependencies {
compile 'io.kamon:kamon-servlet-3_2.12:2.0.0'
}
```
* SBT:
```sbtshell
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:
* For Servlet 2.5: [`kamon.servlet.v25.KamonFilterV25`][2]
* For Servlet 3.x.x: [`kamon.servlet.v3.KamonFilterV3`][3]
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`:
```java
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 {
@Override
public void contextInitialized(ServletContextEvent servletContextEvent) {
// here you might subscribe all reporters you want. e.g. `Kamon.addReporter(new PrometheusReporter())`
servletContextEvent
.getServletContext()
.addFilter("KamonFilter", new KamonFilterV3())
.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, "/*");
}
@Override
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`:
```xml
kamonFilter
kamon.servlet.v25.KamonFilterV25
kamonFilter
/*
```
### Config
`kamon-servlet` uses [TypeSafe Config][4]. Default configuration is
in `resources/reference.conf` for each subproject:
* [kamon-servlet-25 config][5]
* [kamon-servlet-3 config][6]
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][7].
### Micro Benchmarks
Execute from your terminal:
```bash
sbt
project benchmarks-3 # or benchmarks-25
jmh:run -i 50 -wi 20 -f1 -t1 .*Benchmark.*
```
[1]: http://www.oracle.com/technetwork/java/index-jsp-135475.html
[2]: kamon-servlet-2.5/src/main/scala/kamon/servlet/v25/KamonFilterV25.scala
[3]: kamon-servlet-3.x.x/src/main/scala/kamon/servlet/v3/KamonFilterV3.scala
[4]: https://github.com/lightbend/config
[5]: kamon-servlet-2.5/src/main/resources/reference.conf
[6]: kamon-servlet-3.x.x/src/main/resources/reference.conf
[7]: https://github.com/lightbend/config#standard-behavior