Skip to content

Commit f05ee70

Browse files
committed
Pad on the LS side
1 parent 4a51360 commit f05ee70

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

lightstep/b3_propagator.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,10 @@ def inject(self, span_context, carrier):
6565
carrier.update(baggage)
6666

6767
if traceid is not None:
68-
# FIXME This adds zeroes on the MS side until traceid is 128b long.
69-
# Confirm that this is the desired implementation.
70-
carrier[_TRACEID] = format(traceid, "032x")
68+
traceid = format(traceid, "x")
69+
carrier[_TRACEID] = "{}{}".format(
70+
traceid, "0" * (32 - len(traceid))
71+
)
7172
if spanid is not None:
7273
carrier[_SPANID] = format(spanid, "016x")
7374

@@ -138,8 +139,9 @@ def extract(self, carrier):
138139
baggage = None
139140

140141
# FIXME This truncates the MSb of traceid until only 64b are left.
141-
# Confirm that this implementation is correct.
142-
traceid = traceid[-16:]
142+
# This should only be done when reporting to LightStep. What exactly
143+
# needs to be coded?
144+
# traceid = traceid[-16:]
143145

144146
return SpanContext(
145147
# traceid and spanid are encoded in hex, so thet must be encoded

tests/b3_propagator_test.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ def test_inject(self):
2828
self.assertEqual(
2929
carrier,
3030
{
31-
"x-b3-traceid": format(span.context.trace_id, "032x"),
31+
"x-b3-traceid": (
32+
format(span.context.trace_id, "x").ljust(32, "0")
33+
),
3234
"x-b3-spanid": format(span.context.span_id, "016x"),
3335
"checked": "baggage"
3436
}
@@ -42,7 +44,9 @@ def test_inject(self):
4244
self.assertEqual(
4345
carrier,
4446
{
45-
"x-b3-traceid": format(span.context.trace_id, "032x"),
47+
"x-b3-traceid": (
48+
format(span.context.trace_id, "x").ljust(32, "0")
49+
),
4650
"x-b3-spanid": format(span.context.span_id, "016x"),
4751
"x-b3-flags": 1,
4852
}

0 commit comments

Comments
 (0)