Skip to content

Commit

Permalink
Support both boolean and binary expressions of Sampled value (Finagle…
Browse files Browse the repository at this point in the history
… impl and openzipkin spec are contraditory)
  • Loading branch information
drpacman committed Apr 8, 2016
1 parent d6e5b61 commit d9b0dc6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ trait TracingSettings extends GlobalSettings with PlayControllerTracing {
lazy val excludedHeaders = Set.empty[String]

protected def sample(request: RequestHeader): Unit = {
val upstreamSampling = request.headers.get(TracingHeaders.Sampled).map(_.toBoolean)
val upstreamSampling = request.headers.get(TracingHeaders.Sampled).map(_.toLowerCase)
upstreamSampling match {
case Some(true) =>
case Some("true") | Some("1") =>
trace.sample(request, serviceName, true)
case None =>
trace.sample(request, serviceName)
case Some(false) =>
case Some(x) =>
// don't sample
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ class PlayTracingSpec extends PlaySpecification with TracingTestCommons with Moc
expectSpans(0)
}

"ensure upstream 'do sample' decision is honoured" in new WithApplication(disabledLocalSamplingApplication) {
"ensure upstream 'do sample' decision is honoured" in new WithApplication(fakeApplication) {
val spanId = Random.nextLong
val result = route(FakeRequest("GET", TestPath + "?key=value",
FakeHeaders(Seq(
Expand All @@ -180,6 +180,16 @@ class PlayTracingSpec extends PlaySpecification with TracingTestCommons with Moc
)), AnyContentAsEmpty)).map(Await.result(_, defaultAwaitTimeout.duration))
expectSpans(1)
}

"ensure upstream 'do sample' decision is honoured (binary value)" in new WithApplication(fakeApplication) {
val spanId = Random.nextLong
val result = route(FakeRequest("GET", TestPath + "?key=value",
FakeHeaders(Seq(
TracingHeaders.TraceId -> Seq(SpanMetadata.idToString(spanId)),
TracingHeaders.Sampled -> Seq("1")
)), AnyContentAsEmpty)).map(Await.result(_, defaultAwaitTimeout.duration))
expectSpans(1)
}
}

step {
Expand Down

0 comments on commit d9b0dc6

Please sign in to comment.