aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvan Topolnjak <ivantopo@gmail.com>2018-02-10 01:32:53 +0100
committerIvan Topolnjak <ivantopo@gmail.com>2018-02-10 01:33:19 +0100
commit5f748c1c74bb71ba4125644b2afec7d4e58bcb9f (patch)
tree1d516e55ce35d81762e761f2b7d5e299e64019b2
parentfa342db5ec6e80227d559ee5ac9d0b11b9f0b453 (diff)
downloadKamon-5f748c1c74bb71ba4125644b2afec7d4e58bcb9f.tar.gz
Kamon-5f748c1c74bb71ba4125644b2afec7d4e58bcb9f.tar.bz2
Kamon-5f748c1c74bb71ba4125644b2afec7d4e58bcb9f.zip
apply metric tags on spans, even if the span is not sampled, fixes #513
-rw-r--r--kamon-core-tests/src/test/scala/kamon/trace/SpanMetricsSpec.scala (renamed from kamon-core-tests/src/test/scala/kamon/trace/SpanMetrics.scala)18
-rw-r--r--kamon-core/src/main/scala/kamon/trace/Span.scala33
2 files changed, 35 insertions, 16 deletions
diff --git a/kamon-core-tests/src/test/scala/kamon/trace/SpanMetrics.scala b/kamon-core-tests/src/test/scala/kamon/trace/SpanMetricsSpec.scala
index 2a04024c..1dfe24a3 100644
--- a/kamon-core-tests/src/test/scala/kamon/trace/SpanMetrics.scala
+++ b/kamon-core-tests/src/test/scala/kamon/trace/SpanMetricsSpec.scala
@@ -21,9 +21,9 @@ import org.scalatest.{Matchers, WordSpecLike}
import scala.util.control.NoStackTrace
-class SpanMetrics extends WordSpecLike with Matchers with MetricInspection with Reconfigure {
+class SpanMetricsSpec extends WordSpecLike with Matchers with MetricInspection with Reconfigure {
- sampleAlways()
+ sampleNever()
"Span Metrics" should {
"be recorded for successful execution" in {
@@ -57,6 +57,18 @@ class SpanMetrics extends WordSpecLike with Matchers with MetricInspection with
Span.Metrics.ProcessingTime.valuesForTag("operation") shouldNot contain(operation)
}
+ "allow specifying custom Span metric tags" in {
+ val operation = "span-with-custom-metric-tags"
+ buildSpan(operation)
+ .withMetricTag("custom-metric-tag-on-builder", "value")
+ .start()
+ .tagMetric("custom-metric-tag-on-span", "value")
+ .finish()
+
+ Span.Metrics.ProcessingTime.valuesForTag("custom-metric-tag-on-builder") should contain("value")
+ Span.Metrics.ProcessingTime.valuesForTag("custom-metric-tag-on-span") should contain("value")
+ }
+
"be recorded if metrics are enabled by calling enableMetrics() on the Span" in {
val operation = "span-with-re-enabled-metrics"
buildSpan(operation)
@@ -68,7 +80,7 @@ class SpanMetrics extends WordSpecLike with Matchers with MetricInspection with
Span.Metrics.ProcessingTime.valuesForTag("operation") should contain(operation)
}
- "record correctly error latency and count" in {
+ "record error latency and count" in {
val operation = "span-failure"
val operationTag = "operation" -> operation
diff --git a/kamon-core/src/main/scala/kamon/trace/Span.scala b/kamon-core/src/main/scala/kamon/trace/Span.scala
index 690efeb4..9778373a 100644
--- a/kamon-core/src/main/scala/kamon/trace/Span.scala
+++ b/kamon-core/src/main/scala/kamon/trace/Span.scala
@@ -123,11 +123,12 @@ object Span {
}
override def tagMetric(key: String, value: String): Span = synchronized {
- if(sampled && open) {
- spanTags = spanTags + (key -> TagValue.String(value))
-
+ if(open) {
if(collectMetrics)
customMetricTags = customMetricTags + (key -> value)
+
+ if(sampled)
+ spanTags = spanTags + (key -> TagValue.String(value))
}
this
}
@@ -142,23 +143,29 @@ object Span {
}
override def addError(error: String): Span = synchronized {
- if(sampled && open) {
+ if(open) {
hasError = true
- spanTags = spanTags ++ Map(
- "error" -> TagValue.True,
- "error.object" -> TagValue.String(error)
- )
+
+ if(sampled) {
+ spanTags = spanTags ++ Map(
+ "error" -> TagValue.True,
+ "error.object" -> TagValue.String(error)
+ )
+ }
}
this
}
override def addError(error: String, throwable: Throwable): Span = synchronized {
- if(sampled && open) {
+ if(open) {
hasError = true
- spanTags = spanTags ++ Map(
- "error" -> TagValue.True,
- "error.object" -> TagValue.String(throwable.getMessage())
- )
+
+ if(sampled) {
+ spanTags = spanTags ++ Map(
+ "error" -> TagValue.True,
+ "error.object" -> TagValue.String(throwable.getMessage())
+ )
+ }
}
this
}