Skip to content

Commit d2db875

Browse files
Add Datadog specific error tags (#1228)
1 parent 12983f9 commit d2db875

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

reporters/kamon-datadog/src/main/scala/kamon/datadog/DatadogSpanReporter.scala

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import kamon.{ ClassLoading, Kamon }
2525
import kamon.datadog.DatadogSpanReporter.Configuration
2626
import kamon.module.{ ModuleFactory, SpanReporter }
2727
import kamon.tag.{ Lookups, Tag, TagSet }
28+
import kamon.trace.Span.TagKeys
2829
import kamon.util.{ EnvironmentTags, Filter }
2930
import org.slf4j.LoggerFactory
3031

@@ -52,7 +53,14 @@ object KamonDataDogTranslatorDefault extends KamonDataDogTranslator {
5253
val start = from.getEpochNano
5354
val duration = Duration.between(from, span.to)
5455
val marks = span.marks.map { m => m.key -> m.instant.getEpochNano.toString }.toMap
55-
val tags = (span.tags.all() ++ span.metricTags.all() ++ additionalTags.all()).map { t =>
56+
val errorTags = if (span.hasError) {
57+
val builder = TagSet.builder()
58+
span.tags.get(Lookups.option(TagKeys.ErrorMessage)).foreach(msg => builder.add("error.msg", msg))
59+
span.tags.get(Lookups.option(TagKeys.ErrorStacktrace)).foreach(st => builder.add("error.stack", st))
60+
builder.build()
61+
} else TagSet.Empty
62+
63+
val tags = (span.tags.all() ++ span.metricTags.all() ++ errorTags.all() ++ additionalTags.all()).map { t =>
5664
t.key -> Tag.unwrapValue(t).toString
5765
}
5866
val meta = (marks ++ tags).filterKeys(tagFilter.accept(_)).toMap

reporters/kamon-datadog/src/test/scala/kamon/datadog/DatadogSpanReporterSpec.scala

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,26 @@ trait TestData {
9090
"error" -> 1
9191
)
9292

93+
val spanWithErrorTags = span.copy(tags = TagSet.from(Map(
94+
"error" -> true,
95+
"error.type" -> "RuntimeException",
96+
"error.message" -> "Error message",
97+
"error.stacktrace" -> "Error stacktrace"
98+
)), hasError = true)
99+
100+
val jsonWithErrorTags = json ++ Json.obj(
101+
"meta" -> Json.obj(
102+
"error" -> "true",
103+
"env" -> "staging",
104+
"error.type" -> "RuntimeException",
105+
"error.message" -> "Error message",
106+
"error.msg" -> "Error message",
107+
"error.stacktrace" -> "Error stacktrace",
108+
"error.stack" -> "Error stacktrace"
109+
),
110+
"error" -> 1
111+
)
112+
93113
val spanWithTags = span.copy(metricTags =
94114
TagSet.from(
95115
Map(
@@ -152,6 +172,7 @@ trait TestData {
152172
"span with marks" -> (Seq(spanWithMarks), Json.arr(Json.arr(jsonWithMarks))),
153173
"span with meta and marks" -> (Seq(spanWithTagsAndMarks), Json.arr(Json.arr(jsonWithTagsAndMarks))),
154174
"span with error" -> (Seq(spanWithError), Json.arr(Json.arr(jsonWithError))),
175+
"span with error tags" -> (Seq(spanWithErrorTags), Json.arr(Json.arr(jsonWithErrorTags))),
155176

156177
"multiple spans with same trace" -> (Seq(span, spanWithTags), Json.arr(Json.arr(json, jsonWithTags)))
157178
// "multiple spans with two traces" -> (Seq(span, spanWithTags, otherTraceSpan, span), Json.arr(Json.arr(json, jsonWithTags, json), Json.arr(otherTraceJson)))

0 commit comments

Comments
 (0)