opencensus-python
opencensus-python copied to clipboard
[TextFormatPropagator] fix parent trace_option data type to string
DEFAULT_TRACE_OPTIONS is string, so mixing bool here has broken situation as following:
>>> from opencensus.trace.propagation.text_format import TextFormatPropagator
>>> propagator = TextFormatPropagator()
>>> data = {}
>>> span_context = propagator.from_carrier(data)
>>> span_context.trace_options.set_enabled(True)
>>> print(propagator.to_carrier(span_context, data))
{'opencensus-trace-traceid': 'ad39a21155167cc115a13e5f4cfb6cd4', 'opencensus-trace-traceoptions': '1'}
>>> span_context = propagator.from_carrier(data)
>>> span_context.trace_options.set_enabled(True)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/mnt/c/Users/kawai/Documents/kwi-opencensus/opencensus/trace/trace_options.py", line 78, in set_enabled
self.enabled = self.get_enabled()
File "/mnt/c/Users/kawai/Documents/kwi-opencensus/opencensus/trace/trace_options.py", line 65, in get_enabled
enabled = bool(int(self.trace_options_byte) & _ENABLED_BITMASK)
ValueError: invalid literal for int() with base 10: 'Tru1'
>>> print(propagator.to_carrier(span_context, data))
{'opencensus-trace-traceid': 'ad39a21155167cc115a13e5f4cfb6cd4', 'opencensus-trace-traceoptions': 'Tru1'}
@hkwi thanks for the fix. It would be great to add a test case.
LGTM with a test case that fails on master, passes with this change.
@hkwi would you add a test case and also rebase to the latest master? Thanks!