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

Cast to string all carrier values #106

Merged
merged 1 commit into from
Sep 8, 2020
Merged
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
11 changes: 6 additions & 5 deletions lightstep/b3_propagator.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ def inject(self, span_context, carrier):

flags = baggage.pop(_FLAGS, None)
if flags is not None:
carrier[_FLAGS] = flags
carrier[_FLAGS] = str(flags)

sampled = baggage.pop(_SAMPLED, None)

if sampled is None:
carrier[_SAMPLED] = 1
carrier[_SAMPLED] = "1"
else:
if flags == 1:
_LOG.warning(
Expand All @@ -56,16 +56,17 @@ def inject(self, span_context, carrier):
int(sampled), sampled
)
)
carrier[_SAMPLED] = sampled
carrier[_SAMPLED] = str(sampled)

if sampled is flags is (traceid and spanid) is None:
warn(
"If not propagating only the sampling state, traceid and "
"spanid must be defined, setting sampling state to 1."
)
carrier[_SAMPLED] = 1
carrier[_SAMPLED] = "1"

carrier.update(baggage)
for key, value in baggage.items():
carrier[key] = str(value)

if traceid is not None:
carrier[_TRACEID] = format(traceid, "x")
Expand Down
10 changes: 4 additions & 6 deletions tests/b3_propagator_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def test_inject(self):
{
"x-b3-traceid": format(span.context.trace_id, "x"),
"x-b3-spanid": format(span.context.span_id, "x"),
"x-b3-sampled": 1,
"x-b3-sampled": "1",
"checked": "baggage"
}
)
Expand All @@ -47,7 +47,7 @@ def test_inject(self):
{
"x-b3-traceid": format(span.context.trace_id, "x"),
"x-b3-spanid": format(span.context.span_id, "x"),
"x-b3-flags": 1,
"x-b3-flags": "1",
}
)

Expand Down Expand Up @@ -174,9 +174,7 @@ def test_sampled(sampled_value):
carrier = {}
tracer.inject(inject_span.context, Format.HTTP_HEADERS, carrier)

self.assertTrue(
isinstance(carrier["x-b3-sampled"], type(sampled_value))
)
self.assertTrue(isinstance(carrier["x-b3-sampled"], str))

extract_span_context = tracer.extract(Format.HTTP_HEADERS, carrier)

Expand All @@ -200,7 +198,7 @@ def test_sampled(sampled_value):

tracer.inject(inject_span.context, Format.HTTP_HEADERS, carrier)

self.assertEqual(carrier["x-b3-sampled"], 1)
self.assertEqual(carrier["x-b3-sampled"], "1")

extract_span_context = tracer.extract(Format.HTTP_HEADERS, carrier)

Expand Down