Skip to content

Commit

Permalink
Span error.message from throwable (#625)
Browse files Browse the repository at this point in the history
* Config utils pairs fix

Extract key-value pairs directly from config set. Extracting topLevelKeys
and then fetching values by key will explode in cases where key is not
a valid `com.typesafe.config.impl.Path` (globs)
Fixes kamon-io/kamon-akka-http#72

* use throwable message for error.message for spans failed with a throwable
  • Loading branch information
mladens authored and ivantopo committed Dec 12, 2019
1 parent 85cc682 commit 7a4c6c0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
29 changes: 29 additions & 0 deletions kamon-core-tests/src/test/scala/kamon/trace/TracerSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,35 @@ class TracerSpec extends WordSpec with Matchers with SpanInspection.Syntax with

span.operationName() shouldBe "customName"
}

"collect exception information for failed Spans" in {
val byMessage = Kamon.spanBuilder("o1").start()
.fail("byMessage")
val byException = Kamon.spanBuilder("o2").start()
.fail(new RuntimeException("byException"))
val byMessageAndException = Kamon.spanBuilder("o3").start()
.fail("byMessageAndException", new RuntimeException("byException"))

Reconfigure.applyConfig("kamon.trace.include-error-stacktrace=false")
val byExceptionDisabled = Kamon.spanBuilder("o2").start()
.fail(new RuntimeException("byExceptionDisabled"))

byMessage.metricTags().get(plainBoolean("error")) shouldBe true
byMessage.spanTags().get(plain("error.message")) shouldBe "byMessage"
byMessage.spanTags().get(option("error.stacktrace")) shouldBe None

byException.metricTags().get(plainBoolean("error")) shouldBe true
byException.spanTags().get(plain("error.message")) shouldBe "byException"
byException.spanTags().get(option("error.stacktrace")) shouldBe defined

byMessageAndException.metricTags().get(plainBoolean("error")) shouldBe true
byMessageAndException.spanTags().get(plain("error.message")) shouldBe "byMessageAndException"
byException.spanTags().get(option("error.stacktrace")) shouldBe defined

byExceptionDisabled.metricTags().get(plainBoolean("error")) shouldBe true
byExceptionDisabled.spanTags().get(plain("error.message")) shouldBe "byExceptionDisabled"
byExceptionDisabled.spanTags().get(option("error.stacktrace")) shouldBe None
}
}

private def remoteSpan(samplingDecision: SamplingDecision = SamplingDecision.Sample): Span.Remote =
Expand Down
8 changes: 6 additions & 2 deletions kamon-core/src/main/scala/kamon/trace/Span.scala
Original file line number Diff line number Diff line change
Expand Up @@ -517,8 +517,12 @@ object Span {
if(_isOpen) {
_hasError = true

if(isSampled && includeErrorStacktrace)
_spanTags.add(TagKeys.ErrorStacktrace, toStackTraceString(throwable))
if(isSampled) {
_spanTags.add(TagKeys.ErrorMessage, throwable.getMessage)

if(includeErrorStacktrace)
_spanTags.add(TagKeys.ErrorStacktrace, toStackTraceString(throwable))
}
}
this
}
Expand Down

0 comments on commit 7a4c6c0

Please sign in to comment.