From fb54e2e8dc7bfb0d06bbd04192ee178b49e3327e Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Wed, 2 Sep 2020 14:38:05 -0600 Subject: [PATCH] Cast to string all carrier values --- lightstep/b3_propagator.py | 11 ++++++----- tests/b3_propagator_test.py | 10 ++++------ 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/lightstep/b3_propagator.py b/lightstep/b3_propagator.py index 940a86b..1d4568c 100644 --- a/lightstep/b3_propagator.py +++ b/lightstep/b3_propagator.py @@ -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( @@ -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") diff --git a/tests/b3_propagator_test.py b/tests/b3_propagator_test.py index 4728711..17ca55e 100644 --- a/tests/b3_propagator_test.py +++ b/tests/b3_propagator_test.py @@ -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" } ) @@ -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", } ) @@ -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) @@ -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)