Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Span error.message from throwable #625

Merged
merged 2 commits into from
Dec 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
6 changes: 3 additions & 3 deletions kamon-core/src/main/scala/kamon/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ package object kamon {
}

def pairs: Map[String, String] = {
topLevelKeys
.map(key => (key, config.getString(key)))
.toMap
config.root().entrySet().asScala.map { entry =>
(entry.getKey, entry.getValue.unwrapped().asInstanceOf[String])
}.toMap
}
}
}
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)
ivantopo marked this conversation as resolved.
Show resolved Hide resolved

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