Kamon Akka + Statsd collecting traces even if not turned on
Hi. Unfortunately I won't be able to provide much more info on this bug since I soon won't have access to the code anymore, but:
This is the gradle section for Kamon and Akka:
compile(group: 'com.typesafe.akka', name: 'akka-http_2.11', version: '10.0.6') {
exclude module: 'config'
exclude module: 'scala-library'
}
compile(group: 'com.typesafe.akka', name: 'akka-cluster-sharding_2.11', version: '2.4.17') {
exclude module: 'akka-stream_2.11'
}
compile(group: 'com.typesafe.akka', name: 'akka-slf4j_2.11', version: '2.4.17') {
exclude module: 'scala-java8-compat_2.11'
}
compile(group: 'de.heikoseeberger', name: 'akka-log4j_2.11', version: '1.3.0') {
exclude module: 'akka-actor_2.11'
exclude module: 'log4j-api'
}
compile(group: 'io.kamon', name: 'kamon-core_2.11', version: '0.6.6') {
exclude module: 'akka-actor_2.11'
exclude module: 'slf4j-api'
}
compile(group: 'io.kamon', name: 'kamon-statsd_2.11', version: '0.6.6') {
exclude module: 'akka-actor_2.11'
}
compile(group: 'io.kamon', name: 'kamon-autoweave_2.11', version: '0.6.5') {
exclude module: 'kamon-core_2.11'
}
compile(group: 'io.kamon', name: 'kamon-akka-2.4_2.11', version: '0.6.6') {
exclude module: 'kamon-core_2.11'
exclude module: 'akka-actor_2.11'
}
This is my Kamon section for the config file:
kamon {
trace {
level-of-detail = "metrics-only"
# Sampling strategy to apply when the tracing level is set to `simple-trace`. The options are: all, random, ordered,
# threshold and clock. The details of each sampler are below.
sampling = random
# Use a ThreadLocalRandom to generate numbers between 1 and 100, if the random number is less or equal to .chance
# then tracing information will be gathered and reported for the current trace.
random-sampler {
chance = 20
}
}
metric {
tick-interval = 10 seconds
disable-aspectj-weaver-missing-error = false
track-unmatched-entities = yes
show-aspectj-missing-warning = yes
filters {
akka-actor {
includes = [
"**couchbase**",
"**REGION*_Coordinator*"
]
excludes = [ ]
}
akka-router {
includes = []
excludes = ["**"]
}
akka-dispatcher {
includes = ["**"]
excludes = []
}
trace {
includes = [ "**" ]
excludes = []
}
}
}
statsd {
# Hostname and port in which your StatsD is running. Remember that StatsD packets are sent using UDP and
# setting unreachable hosts and/or not open ports wont be warned by the Kamon, your data wont go anywhere.
hostname = "XXX"
port = 8125
time-units = "ms"
# Interval between metrics data flushes to StatsD. It's value must be equal or greater than the
# kamon.metric.tick-interval setting.
flush-interval = 10 seconds
# Max packet size for UDP metrics data sent to StatsD.
max-packet-size = 1024 bytes
# Subscription patterns used to select which metrics will be pushed to StatsD. Note that first, metrics
# collection for your desired entities must be activated under the kamon.metrics.filters settings.
subscriptions {
histogram = [ "**" ]
min-max-counter = [ "**" ]
gauge = [ "**" ]
counter = [ "**" ]
trace = [ "**" ]
trace-segment = [ "**" ]
akka-actor = [ "**" ]
akka-dispatcher = [ "**" ]
akka-router = [ "**" ]
system-metric = [ "**" ]
http-server = [ "**" ]
}
# FQCN of the implementation of `kamon.statsd.MetricKeyGenerator` to be instantiated and used for assigning
# metric names. The implementation must have a single parameter constructor accepting a `com.typesafe.config.Config`.
metric-entityId-generator = kamon.statsd.SimpleMetricKeyGenerator
simple-metric-entityId-generator {
# Application prefix for all metrics pushed to StatsD. The default namespacing scheme for metrics follows
# this pattern:
# application.host.entity.entity-name.metric-name
application = "XXX"
# Includes the name of the hostname in the generated metric. When set to false, the scheme for the metrics
# will look as follows:
# application.entity.entity-name.metric-name
include-hostname = true
# Allow users to override the name of the hostname reported by kamon. When changed, the scheme for the metrics
# will have the following pattern:
# application.hostname-override-value.entity.entity-name.metric-name
hostname-override = none
# When the sections that make up the metric names have special characters like dots (very common in dispatcher
# names) or forward slashes (all actor metrics) we need to sanitize those values before sending them to StatsD
# with one of the following strategies:
# - normalize: changes ': ' to '-' and ' ', '/' and '.' to '_'.
# - percent-encode: percent encode the section on the metric name. Please note that StatsD doesn't support
# percent encoded metric names, this option is only useful if using our docker image which has a patched
# version of StatsD or if you are running your own, customized version of StatsD that supports this.
metric-name-normalization-strategy = normalize
}
}
}
What we do is Kamon.start on startup and Kamon.shutdown on end. In the code, there are a number of traces being generated with Kamon.tracer().newContext(contextName); and add a few segments etc.
Now, we thought that in order to not use kamon, it would have been enough to wrap the Kamon.start() and Kamon.shutdown() bits inside conditional blocks. The idea being: if Kamon isn't started up, the various trace and segment commands would just do nothing.
Turns out, that's not the case: what actually happens is that the traces get collected over time, but never flushed, eventually leading to the heap being out of memory.
While this is an acceptable behavior (the fix was simply to put all Kamon constructs into a conditional wrapper), I don't think this is sufficiently documented or intuitive, and perhaps should be either changed or better highlighted.
See attached screenshot from heap dump analysis of a long test session Google Drive image
I'm closing this issue because it is either too old to be relevant or stale. Stop by our Github Discussions section and drop a message if you need any additional help with the topic.
Have a nice day!