Skip to content

Instantly share code, notes, and snippets.

@kell18
Last active May 2, 2019 15:43
Show Gist options
  • Save kell18/060c8f0296c94620c54132b75d59b0df to your computer and use it in GitHub Desktop.
Save kell18/060c8f0296c94620c54132b75d59b0df to your computer and use it in GitHub Desktop.
class T extends WordSpec with FridaDefaultJsonProtocol with Directives with SprayJsonSupport with Matchers with ScalatestRouteTest {
import scala.concurrent.ExecutionContext.Implicits.global
Kamon.addReporter(new InfluxDBReporter(Kamon.config()))
private val log = LoggerFactory.getLogger(getClass.getName)
val futureFunc: Future[Int] = Future(123)
val eHandler = ExceptionHandler {
case NonFatal(_) =>
log.error("789")
complete(GenericResponse(ok = false))
}
def r: Route =
get {
path("abc") {
withTxKContext {
log.info("123")
handleExceptions(eHandler) {
complete {
futureFunc.map(_ * 2).map {
_ =>
log.info("456")
throw new Exception("Test exception")
GenericResponse(ok = true)
}
}
}
}
}
}
"R test" should {
"propagate context" in {
Get("/abc") ~> r ~> check {
StatusCodes.OK shouldEqual StatusCodes.OK
}
}
}
private def withTxKContext[T](f: => T): T = {
Kamon.withContext(Kamon.currentContext().withKey(Key.broadcast[String](name = "A", emptyValue = ""), "abc"))(f)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment