-
Notifications
You must be signed in to change notification settings - Fork 327
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1026 from ivantopo/delay-span-reporting
introduce Span Reporting delay
- Loading branch information
Showing
4 changed files
with
131 additions
and
15 deletions.
There are no files selected for viewing
86 changes: 86 additions & 0 deletions
86
core/kamon-core-tests/src/test/scala/kamon/trace/SpanReportingDelaySpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* ========================================================================================= | ||
* Copyright © 2013-2017 the kamon project <http://kamon.io/> | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file | ||
* except in compliance with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the | ||
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | ||
* either express or implied. See the License for the specific language governing permissions | ||
* and limitations under the License. | ||
* ========================================================================================= | ||
*/ | ||
|
||
package kamon.trace | ||
|
||
import kamon.Kamon | ||
import kamon.testkit.{Reconfigure, SpanInspection, TestSpanReporter} | ||
import org.scalactic.TimesOnInt.convertIntToRepeater | ||
import org.scalatest.concurrent.Eventually | ||
import org.scalatest.time.SpanSugar | ||
import org.scalatest.{Matchers, OptionValues, WordSpec} | ||
|
||
|
||
class SpanReportingDelaySpec extends WordSpec with Matchers with OptionValues with SpanInspection.Syntax with Eventually | ||
with SpanSugar with TestSpanReporter with Reconfigure { | ||
|
||
"the Kamon tracer" when { | ||
"has span reporting delay disabled" should { | ||
"keep spans with a positive sampling decision" in { | ||
val span = Kamon.spanBuilder("positive-span-without-delay").start() | ||
span.trace.keep() | ||
span.finish() | ||
|
||
eventually(timeout(5 seconds)) { | ||
val reportedSpan = testSpanReporter().nextSpan().value | ||
reportedSpan.operationName shouldBe span.operationName() | ||
} | ||
} | ||
|
||
"not report spans with a negative sampling decision" in { | ||
val span = Kamon.spanBuilder("negative-span-without-delay").start() | ||
span.trace.drop() | ||
span.finish() | ||
span.trace.keep() // Should not have any effect | ||
|
||
5 times { | ||
val allSpans = testSpanReporter().spans() | ||
allSpans.find(_.operationName == span.operationName()) shouldBe empty | ||
|
||
Thread.sleep(100) // Should be enough because Spans are reported every millisecond in tests | ||
} | ||
} | ||
} | ||
|
||
"has span reporting delay enabled" should { | ||
"keep spans with a positive sampling decision" in { | ||
applyConfig("kamon.trace.span-reporting-delay = 2 seconds") | ||
val span = Kamon.spanBuilder("overwrite-to-positive-with-delay").start() | ||
span.trace.drop() | ||
span.finish() | ||
span.trace.keep() // Should force the Span to be reported, even though it was dropped before finising | ||
|
||
eventually(timeout(5 seconds)) { | ||
val reportedSpan = testSpanReporter().nextSpan().value | ||
reportedSpan.operationName shouldBe span.operationName() | ||
} | ||
} | ||
|
||
"not report spans with a negative sampling decision" in { | ||
val span = Kamon.spanBuilder("negative-span-without-delay").start() | ||
span.trace.keep() | ||
span.finish() | ||
span.trace.drop() // Should force the Span to be dropped, even though it was sampled before finishing | ||
|
||
5 times { | ||
val allSpans = testSpanReporter().spans() | ||
allSpans.find(_.operationName == span.operationName()) shouldBe empty | ||
|
||
Thread.sleep(100) // Should be enough because Spans are reported every millisecond in tests | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters