Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use nextSpan instead of joinSpan #53

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions core/src/main/scala/brave/play/ZipkinTraceServiceLike.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2017-2020 The OpenZipkin Authors
* Copyright 2017-2021 The OpenZipkin Authors
*
* 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
Expand Down Expand Up @@ -183,7 +183,8 @@ trait ZipkinTraceServiceLike {
(carrier: A, key: String) => getHeader(carrier, key).orNull
).extract(headers)

tracer.joinSpan(contextOrFlags.context())
Option(contextOrFlags.context())
.map(tracer.joinSpan).getOrElse(tracer.nextSpan(contextOrFlags))
}

/**
Expand Down
10 changes: 9 additions & 1 deletion core/src/test/scala/brave/play/ZipkinTraceServiceLikeSpec.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2017-2020 The OpenZipkin Authors
* Copyright 2017-2021 The OpenZipkin Authors
*
* 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
Expand Down Expand Up @@ -114,6 +114,14 @@ class ZipkinTraceServiceLikeSpec extends FunSuite {
assert(reported.tags.get("tag") === "value")
}

test("when sampling is disabled, toSpan results in a new unsampled trace") {
val tracer = new TestZipkinTraceService()

val parent = tracer.toSpan(Map("X-B3-Sampled" -> "0"))(getValueFromMap)

assert(parent.context().parentId() == null)
assert(parent.context().sampled() == false)
}
}

class TestZipkinTraceService extends ZipkinTraceServiceLike {
Expand Down