Skip to content

Commit 9f62e2a

Browse files
authored
Cast to string all carrier values (#106)
1 parent d11a943 commit 9f62e2a

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

lightstep/b3_propagator.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ def inject(self, span_context, carrier):
3636

3737
flags = baggage.pop(_FLAGS, None)
3838
if flags is not None:
39-
carrier[_FLAGS] = flags
39+
carrier[_FLAGS] = str(flags)
4040

4141
sampled = baggage.pop(_SAMPLED, None)
4242

4343
if sampled is None:
44-
carrier[_SAMPLED] = 1
44+
carrier[_SAMPLED] = "1"
4545
else:
4646
if flags == 1:
4747
_LOG.warning(
@@ -56,16 +56,17 @@ def inject(self, span_context, carrier):
5656
int(sampled), sampled
5757
)
5858
)
59-
carrier[_SAMPLED] = sampled
59+
carrier[_SAMPLED] = str(sampled)
6060

6161
if sampled is flags is (traceid and spanid) is None:
6262
warn(
6363
"If not propagating only the sampling state, traceid and "
6464
"spanid must be defined, setting sampling state to 1."
6565
)
66-
carrier[_SAMPLED] = 1
66+
carrier[_SAMPLED] = "1"
6767

68-
carrier.update(baggage)
68+
for key, value in baggage.items():
69+
carrier[key] = str(value)
6970

7071
if traceid is not None:
7172
carrier[_TRACEID] = format(traceid, "x")

tests/b3_propagator_test.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def test_inject(self):
3232
{
3333
"x-b3-traceid": format(span.context.trace_id, "x"),
3434
"x-b3-spanid": format(span.context.span_id, "x"),
35-
"x-b3-sampled": 1,
35+
"x-b3-sampled": "1",
3636
"checked": "baggage"
3737
}
3838
)
@@ -47,7 +47,7 @@ def test_inject(self):
4747
{
4848
"x-b3-traceid": format(span.context.trace_id, "x"),
4949
"x-b3-spanid": format(span.context.span_id, "x"),
50-
"x-b3-flags": 1,
50+
"x-b3-flags": "1",
5151
}
5252
)
5353

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

177-
self.assertTrue(
178-
isinstance(carrier["x-b3-sampled"], type(sampled_value))
179-
)
177+
self.assertTrue(isinstance(carrier["x-b3-sampled"], str))
180178

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

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

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

203-
self.assertEqual(carrier["x-b3-sampled"], 1)
201+
self.assertEqual(carrier["x-b3-sampled"], "1")
204202

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

0 commit comments

Comments
 (0)