Skip to content
This repository has been archived by the owner on Mar 29, 2020. It is now read-only.

Commit

Permalink
Merge pull request #28 from ptrlaszlo/http-status-code-as-metric-tag
Browse files Browse the repository at this point in the history
Adding an config option to include http status code as metric tag
  • Loading branch information
ivantopo authored Feb 9, 2018
2 parents 8267e50 + 546ef14 commit dd869f3
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
3 changes: 3 additions & 0 deletions kamon-akka-http/src/main/resources/reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ kamon.akka-http {
# cardinality explosion caused by variable sections in the Path.
name-generator = default

# Add http status codes as metric tags. The default value is false
add-http-status-code-as-metric-tag = false

modules {
kamon-akka-http {
requires-aspectj = yes
Expand Down
6 changes: 6 additions & 0 deletions kamon-akka-http/src/main/scala/kamon/akka/http/AkkaHttp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,15 @@ object AkkaHttp {
}
}

@volatile var addHttpStatusCodeAsMetricTag: Boolean = addHttpStatusCodeAsMetricTagFromConfig(Kamon.config())

private def addHttpStatusCodeAsMetricTagFromConfig(config: Config): Boolean =
Kamon.config.getBoolean("kamon.akka-http.add-http-status-code-as-metric-tag")

Kamon.onReconfigure(new OnReconfigureHook {
override def onReconfigure(newConfig: Config): Unit = {
nameGenerator = nameGeneratorFromConfig(newConfig)
addHttpStatusCodeAsMetricTag = addHttpStatusCodeAsMetricTagFromConfig(newConfig)
}
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,13 @@ class ClientRequestInstrumentation {
if(status.isFailure())
span.addError(status.reason())

span
.tag("http.status_code", response.status.intValue())
.finish()
val spanWithStatusTag = if (AkkaHttp.addHttpStatusCodeAsMetricTag) {
span.tagMetric("http.status_code", status.intValue.toString())
} else {
span.tag("http.status_code", status.intValue())
}

spanWithStatusTag.finish()
}
case Failure(t) {
span.addError(t.getMessage, t).finish()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,11 @@ object ServerFlowWrapper {
val response = grab(responseIn)
val status = response.status.intValue()

val span = Kamon.currentSpan()
.tag("http.status_code", status)
val span = if (addHttpStatusCodeAsMetricTag) {
Kamon.currentSpan().tagMetric("http.status_code", status.toString())
} else {
Kamon.currentSpan().tag("http.status_code", status)
}

if(status == 404)
span.setOperationName("unhandled")
Expand Down

0 comments on commit dd869f3

Please sign in to comment.