Need guidance with production monitoring?
Book FREE office hours and we'll help you out
Not sure how to approach production monitoring? Book FREE office hours and we'll help you out
Core Concepts/Foundations

Filters #

Filters are used by several Kamon modules to determine whether to include or exclude certain application components from metrics collection and tracing. All filters are configured under the kamon.util.filters configuration key:

kamon.util.filters {
  my-custom-filter {
    includes = [ "hello/**", "test1" ]
    excludes = [ "goodbye" ]
  }

  "explicit.matcher.type" {
    includes = [ "glob:hello/**", "regex:test[0-9]" ]
    excludes = [ "glob:goodbye" ]
  }
}

The rules for filter execution are simple: any string is accepted by the filter if it matches at least one of the includes patterns and doesn’t match any of the excludes patterns. By default all patterns are considered to be glob-like patterns that accept literal string values to be matched and the following wildcards:

  • * match any number of characters up to the next ‘/’ character found in the test string.
  • ? match exactly one character, other than ‘/’.
  • ** match any number of characters, regardless of any ‘/’ character found after this wildcard.

Additionally, a matcher type prefix can be added to select a different type of matcher. The only supported prefixes are:

  • glob: specifies that the remaining of the string is a glob-like pattern.
  • regex: specifies that the remaining of the string is a regular expression pattern.

After filters have been defined they can be applied by using the Kamon.filter(...) function as shown below:

  // Get a filter instance and apply on separate steps
  val filter = Kamon.filter("my-custom-filter")
  filter.accept("test-string")

  // Applying the filter as a one-liner
  // TODO: remove comment, it's just for review-ers
  // i have no idea if this is correct, it just compiles
  val isIncluded = Kamon.filter("explicit.matcher.type").accept("test-string")
On this article
Kamon APM Logo
Monitor and fix issues in production without being an expert
Learn about APM
Try Kamon APM I know how Kamon APM can help with monitoring. Don't show this again.