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

Add Datadog specific error tags #1228

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import kamon.{ ClassLoading, Kamon }
import kamon.datadog.DatadogSpanReporter.Configuration
import kamon.module.{ ModuleFactory, SpanReporter }
import kamon.tag.{ Lookups, Tag, TagSet }
import kamon.trace.Span.TagKeys
import kamon.util.{ EnvironmentTags, Filter }
import org.slf4j.LoggerFactory

Expand Down Expand Up @@ -52,7 +53,14 @@ object KamonDataDogTranslatorDefault extends KamonDataDogTranslator {
val start = from.getEpochNano
val duration = Duration.between(from, span.to)
val marks = span.marks.map { m => m.key -> m.instant.getEpochNano.toString }.toMap
val tags = (span.tags.all() ++ span.metricTags.all() ++ additionalTags.all()).map { t =>
val errorTags = if (span.hasError) {
val builder = TagSet.builder()
span.tags.get(Lookups.option(TagKeys.ErrorMessage)).foreach(msg => builder.add("error.msg", msg))
span.tags.get(Lookups.option(TagKeys.ErrorStacktrace)).foreach(st => builder.add("error.stack", st))
builder.build()
} else TagSet.Empty

val tags = (span.tags.all() ++ span.metricTags.all() ++ errorTags.all() ++ additionalTags.all()).map { t =>
t.key -> Tag.unwrapValue(t).toString
}
val meta = (marks ++ tags).filterKeys(tagFilter.accept(_)).toMap
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,26 @@ trait TestData {
"error" -> 1
)

val spanWithErrorTags = span.copy(tags = TagSet.from(Map(
"error" -> true,
"error.type" -> "RuntimeException",
"error.message" -> "Error message",
"error.stacktrace" -> "Error stacktrace"
)), hasError = true)

val jsonWithErrorTags = json ++ Json.obj(
"meta" -> Json.obj(
"error" -> "true",
"env" -> "staging",
"error.type" -> "RuntimeException",
"error.message" -> "Error message",
"error.msg" -> "Error message",
"error.stacktrace" -> "Error stacktrace",
"error.stack" -> "Error stacktrace"
),
"error" -> 1
)

val spanWithTags = span.copy(metricTags =
TagSet.from(
Map(
Expand Down Expand Up @@ -152,6 +172,7 @@ trait TestData {
"span with marks" -> (Seq(spanWithMarks), Json.arr(Json.arr(jsonWithMarks))),
"span with meta and marks" -> (Seq(spanWithTagsAndMarks), Json.arr(Json.arr(jsonWithTagsAndMarks))),
"span with error" -> (Seq(spanWithError), Json.arr(Json.arr(jsonWithError))),
"span with error tags" -> (Seq(spanWithErrorTags), Json.arr(Json.arr(jsonWithErrorTags))),

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