opencensus-python icon indicating copy to clipboard operation
opencensus-python copied to clipboard

[TextFormatPropagator] fix parent trace_option data type to string

Open hkwi opened this issue 6 years ago • 3 comments

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 avatar Jul 04 '19 01:07 hkwi

@hkwi thanks for the fix. It would be great to add a test case.

reyang avatar Jul 04 '19 01:07 reyang

LGTM with a test case that fails on master, passes with this change.

c24t avatar Jul 12 '19 19:07 c24t

@hkwi would you add a test case and also rebase to the latest master? Thanks!

reyang avatar Jul 16 '19 17:07 reyang