Repository: open-telemetry/opentelemetry-python-contrib

Issue:
OpenTracing propagator does not use a TraceFlags object
I set up a client and server that propagated spans using the OpenTracing propagator. The server side reported this error:

```
[2021-04-26 16:41:13,377] ERROR in app: Exception on /ping [GET]
Traceback (most recent call last):
  File "/home/ocelotl/virtual_environments/LS-22507/lib/python3.8/site-packages/flask/app.py", line 2447, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/ocelotl/virtual_environments/LS-22507/lib/python3.8/site-packages/flask/app.py", line 1952, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/ocelotl/virtual_environments/LS-22507/lib/python3.8/site-packages/flask/app.py", line 1821, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/home/ocelotl/virtual_environments/LS-22507/lib/python3.8/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/home/ocelotl/virtual_environments/LS-22507/lib/python3.8/site-packages/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/ocelotl/virtual_environments/LS-22507/lib/python3.8/site-packages/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "server.py", line 53, in ping
    with tracer.start_as_current_span(
  File "/home/ocelotl/.pyenv/versions/3.8.3/lib/python3.8/contextlib.py", line 113, in __enter__
    return next(self.gen)
  File "/home/ocelotl/github/ocelotl/opentelemetry-python/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py", line 863, in start_as_current_span
    span = self.start_span(
  File "/home/ocelotl/github/ocelotl/opentelemetry-python/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py", line 917, in start_span
    sampling_result = self.sampler.should_sample(
  File "/home/ocelotl/github/ocelotl/opentelemetry-python/opentelemetry-sdk/src/opentelemetry/sdk/trace/sampling.py", line 326, in should_sample
    if parent_span_context.trace_flags.sampled:
AttributeError: 'int' object has no attribute 'sampled'
```

This happens because when instantiating a context during propagation with the OpenTracing propagator, a `TracFlags` object is not used for the trace flags.


Discussion:

Resolving patch:
diff --git a/propagator/opentelemetry-propagator-ot-trace/src/opentelemetry/propagators/ot_trace/__init__.py b/propagator/opentelemetry-propagator-ot-trace/src/opentelemetry/propagators/ot_trace/__init__.py
--- a/propagator/opentelemetry-propagator-ot-trace/src/opentelemetry/propagators/ot_trace/__init__.py
+++ b/propagator/opentelemetry-propagator-ot-trace/src/opentelemetry/propagators/ot_trace/__init__.py
@@ -85,7 +85,7 @@ def extract(
                         trace_id=int(traceid, 16),
                         span_id=int(spanid, 16),
                         is_remote=True,
-                        trace_flags=traceflags,
+                        trace_flags=TraceFlags(traceflags),
                     )
                 ),
                 context,


Test patch:
diff --git a/propagator/opentelemetry-propagator-ot-trace/tests/test_ot_trace_propagator.py b/propagator/opentelemetry-propagator-ot-trace/tests/test_ot_trace_propagator.py
--- a/propagator/opentelemetry-propagator-ot-trace/tests/test_ot_trace_propagator.py
+++ b/propagator/opentelemetry-propagator-ot-trace/tests/test_ot_trace_propagator.py
@@ -248,6 +248,9 @@ def test_extract_trace_id_span_id_sampled_true(self):
         self.assertEqual(hex(span_context.span_id)[2:], "e457b5a2e4d86bd1")
         self.assertTrue(span_context.is_remote)
         self.assertEqual(span_context.trace_flags, TraceFlags.SAMPLED)
+        self.assertIsInstance(
+            get_current_span().get_span_context().trace_flags, TraceFlags
+        )
 
     def test_extract_trace_id_span_id_sampled_false(self):
         """Test valid trace_id, span_id and sampled false"""
@@ -268,6 +271,9 @@ def test_extract_trace_id_span_id_sampled_false(self):
         self.assertEqual(hex(span_context.span_id)[2:], "e457b5a2e4d86bd1")
         self.assertTrue(span_context.is_remote)
         self.assertEqual(span_context.trace_flags, TraceFlags.DEFAULT)
+        self.assertIsInstance(
+            get_current_span().get_span_context().trace_flags, TraceFlags
+        )
 
     def test_extract_malformed_trace_id(self):
         """Test extraction with malformed trace_id"""