aboutsummaryrefslogtreecommitdiff
path: root/kamon-core/src/test/scala/kamon/trace
diff options
context:
space:
mode:
Diffstat (limited to 'kamon-core/src/test/scala/kamon/trace')
-rw-r--r--kamon-core/src/test/scala/kamon/trace/ActiveSpanManagementSpec.scala40
-rw-r--r--kamon-core/src/test/scala/kamon/trace/RealSpanSpec.scala10
-rw-r--r--kamon-core/src/test/scala/kamon/trace/TracerSpec.scala48
3 files changed, 47 insertions, 51 deletions
diff --git a/kamon-core/src/test/scala/kamon/trace/ActiveSpanManagementSpec.scala b/kamon-core/src/test/scala/kamon/trace/ActiveSpanManagementSpec.scala
index ebee9f66..a6a7bc3a 100644
--- a/kamon-core/src/test/scala/kamon/trace/ActiveSpanManagementSpec.scala
+++ b/kamon-core/src/test/scala/kamon/trace/ActiveSpanManagementSpec.scala
@@ -9,16 +9,16 @@ import org.scalatest.{Matchers, WordSpec}
class ActiveSpanManagementSpec extends WordSpec with Matchers {
"Kamon acting as a ActiveSpanSource" should {
- "return a ActiveSpan wrapping a empty span when there is no currently active Span" in {
+ "return a empty span when there is no currently active Span" in {
inspect(Kamon.activeSpan()) shouldBe empty
}
- "safely operate on a ActiveSpan that wraps a empty Span" in {
- val activeSpan = Kamon.activeSpan()
+ "safely operate on a empty Span" in {
+ val emptySpan = Kamon.activeSpan()
val activeSpanData = inspect(Kamon.activeSpan())
activeSpanData shouldBe empty
- activeSpan
+ emptySpan
.setOperationName("test")
.addBaggage("key", "value")
.addMetricTag("key", "value")
@@ -28,39 +28,33 @@ class ActiveSpanManagementSpec extends WordSpec with Matchers {
.addSpanTag("boolean-false", false)
.annotate(Annotation(Clock.microTimestamp(), "event", Map("k" -> "v")))
- val baggage = activeSpan.context().baggage
+ val baggage = emptySpan.context().baggage
baggage.add("key", "value")
baggage.get("key") shouldBe empty
baggage.getAll() shouldBe empty
- val continuation = activeSpan.capture()
- val activatedSpan = continuation.activate()
- inspect(Kamon.activeSpan()) shouldBe empty
- activatedSpan.deactivate()
+ Kamon.withActiveSpan(emptySpan) {
+ inspect(Kamon.activeSpan()) shouldBe empty
+ }
inspect(Kamon.activeSpan()) shouldBe empty
}
- "set a Span as active when using makeActive" in {
+ "set a Span as active when using activate" in {
val span = Kamon.buildSpan("mySpan").start()
- val activeSpan = Kamon.makeActive(span)
- Kamon.activeSpan() shouldBe theSameInstanceAs(activeSpan)
- activeSpan.deactivate()
- }
-
- "set a Span as active when using startActive" in {
- val activeSpan = Kamon.buildSpan("mySpan").startActive()
- Kamon.activeSpan() shouldBe theSameInstanceAs(activeSpan)
- activeSpan.deactivate()
+ val scope = Kamon.activate(span)
+ Kamon.activeSpan() shouldBe theSameInstanceAs(span)
+ scope.close()
}
- "restore the previously active Span when a ActiveSpan gets deactivated" in {
+ "restore the previously active Span when a scope is closed" in {
val previouslyActiveSpan = Kamon.activeSpan()
inspect(Kamon.activeSpan()) shouldBe empty
- val activeSpan = Kamon.buildSpan("mySpan").startActive()
- Kamon.activeSpan() shouldBe theSameInstanceAs(activeSpan)
- activeSpan.deactivate()
+ val span = Kamon.buildSpan("mySpan").start()
+ Kamon.withActiveSpan(span) {
+ Kamon.activeSpan() shouldBe theSameInstanceAs(span)
+ }
Kamon.activeSpan() shouldBe theSameInstanceAs(previouslyActiveSpan)
}
diff --git a/kamon-core/src/test/scala/kamon/trace/RealSpanSpec.scala b/kamon-core/src/test/scala/kamon/trace/RealSpanSpec.scala
index 150bf4c7..e019e15a 100644
--- a/kamon-core/src/test/scala/kamon/trace/RealSpanSpec.scala
+++ b/kamon-core/src/test/scala/kamon/trace/RealSpanSpec.scala
@@ -88,16 +88,16 @@ class RealSpanSpec extends WordSpec with Matchers with BeforeAndAfterAll with Ev
}
}
- "pass all the tags, annotations and baggage to the FinishedSpan instance when started active and finished" in {
- val activeSpan = Kamon.buildSpan("full-span")
+ "pass all the tags, annotations and baggage to the FinishedSpan instance when started, activated and finished" in {
+ val scope = Kamon.activate(Kamon.buildSpan("full-span")
.withSpanTag("builder-string-tag", "value")
.withSpanTag("builder-boolean-tag-true", true)
.withSpanTag("builder-boolean-tag-false", false)
.withSpanTag("builder-number-tag", 42)
.withStartTimestamp(100)
- .startActive()
+ .start())
- activeSpan
+ Kamon.activeSpan()
.addBaggage("baggage", "value")
.addSpanTag("span-string-tag", "value")
.addSpanTag("span-boolean-tag-true", true)
@@ -110,7 +110,7 @@ class RealSpanSpec extends WordSpec with Matchers with BeforeAndAfterAll with Ev
.setOperationName("fully-populated-active-span")
.finish(200)
- activeSpan.deactivate()
+ scope.close()
eventually(timeout(2 seconds)) {
val finishedSpan = reporter.nextSpan().value
diff --git a/kamon-core/src/test/scala/kamon/trace/TracerSpec.scala b/kamon-core/src/test/scala/kamon/trace/TracerSpec.scala
index 3e05adb5..5abfe723 100644
--- a/kamon-core/src/test/scala/kamon/trace/TracerSpec.scala
+++ b/kamon-core/src/test/scala/kamon/trace/TracerSpec.scala
@@ -42,23 +42,23 @@ class TracerSpec extends WordSpec with Matchers with SpanBuilding with OptionVal
("boolean" -> TagValue.True))
}
- "do not interfere with the currently active Span if not requested when starting a Span" in {
- val previouslyActiveSpan = tracer.activeSpan()
- tracer.buildSpan("myOperation").start()
- tracer.activeSpan() should be theSameInstanceAs(previouslyActiveSpan)
- }
-
- "make a span active with started with the .startActive() function and restore the previous Span when deactivated" in {
- val previouslyActiveSpan = tracer.activeSpan()
- val activeSpan = tracer.buildSpan("myOperation").startActive()
-
- tracer.activeSpan() shouldNot be theSameInstanceAs(previouslyActiveSpan)
- val activeSpanData = inspect(activeSpan)
- activeSpanData.operationName() shouldBe "myOperation"
-
- activeSpan.deactivate()
- tracer.activeSpan() should be theSameInstanceAs(previouslyActiveSpan)
- }
+// "do not interfere with the currently active Span if not requested when starting a Span" in {
+// val previouslyActiveSpan = tracer.activeSpan()
+// tracer.buildSpan("myOperation").start()
+// tracer.activeSpan() should be theSameInstanceAs(previouslyActiveSpan)
+// }
+//
+// "make a span active with started with the .startActive() function and restore the previous Span when deactivated" in {
+// val previouslyActiveSpan = tracer.activeSpan()
+// val activeSpan = tracer.buildSpan("myOperation").startActive()
+//
+// tracer.activeSpan() shouldNot be theSameInstanceAs(previouslyActiveSpan)
+// val activeSpanData = inspect(activeSpan)
+// activeSpanData.operationName() shouldBe "myOperation"
+//
+// activeSpan.deactivate()
+// tracer.activeSpan() should be theSameInstanceAs(previouslyActiveSpan)
+// }
"not have any parent Span if there is ActiveSpan and no parent was explicitly given" in {
val span = tracer.buildSpan("myOperation").start()
@@ -67,9 +67,10 @@ class TracerSpec extends WordSpec with Matchers with SpanBuilding with OptionVal
}
"use the currently active span as parent" in {
- val parent = tracer.buildSpan("myOperation").startActive()
- val child = tracer.buildSpan("childOperation").asChildOf(parent).start()
- parent.deactivate()
+ val parent = tracer.buildSpan("myOperation").start()
+ val child = Kamon.withActiveSpan(parent) {
+ tracer.buildSpan("childOperation").asChildOf(parent).start()
+ }
val parentData = inspect(parent)
val childData = inspect(child)
@@ -77,9 +78,10 @@ class TracerSpec extends WordSpec with Matchers with SpanBuilding with OptionVal
}
"ignore the currently active span as parent if explicitly requested" in {
- val parent = tracer.buildSpan("myOperation").startActive()
- val child = tracer.buildSpan("childOperation").ignoreActiveSpan().start()
- parent.deactivate()
+ val parent = tracer.buildSpan("myOperation").start()
+ val child = Kamon.withActiveSpan(parent) {
+ tracer.buildSpan("childOperation").ignoreActiveSpan().start()
+ }
val childData = inspect(child)
childData.context().parentID shouldBe IdentityProvider.NoIdentifier