We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN 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.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `propagator/opentelemetry-propagator-ot-trace/src/opentelemetry/propagators/ot_trace/__init__.py`
Content:
```
1 # Copyright The OpenTelemetry Authors
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #     http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 
15 from re import compile as re_compile
16 from typing import Any, Iterable, Optional
17 
18 from opentelemetry.baggage import get_all, set_baggage
19 from opentelemetry.context import Context
20 from opentelemetry.propagators.textmap import (
21     CarrierT,
22     Getter,
23     Setter,
24     TextMapPropagator,
25     default_getter,
26     default_setter,
27 )
28 from opentelemetry.trace import (
29     INVALID_SPAN_ID,
30     INVALID_TRACE_ID,
31     NonRecordingSpan,
32     SpanContext,
33     TraceFlags,
34     get_current_span,
35     set_span_in_context,
36 )
37 
38 OT_TRACE_ID_HEADER = "ot-tracer-traceid"
39 OT_SPAN_ID_HEADER = "ot-tracer-spanid"
40 OT_SAMPLED_HEADER = "ot-tracer-sampled"
41 OT_BAGGAGE_PREFIX = "ot-baggage-"
42 
43 _valid_header_name = re_compile(r"[\w_^`!#$%&'*+.|~]+")
44 _valid_header_value = re_compile(r"[\t\x20-\x7e\x80-\xff]+")
45 _valid_extract_traceid = re_compile(r"[0-9a-f]{1,32}")
46 _valid_extract_spanid = re_compile(r"[0-9a-f]{1,16}")
47 
48 
49 class OTTracePropagator(TextMapPropagator):
50     """Propagator for the OTTrace HTTP header format"""
51 
52     def extract(
53         self,
54         carrier: CarrierT,
55         context: Optional[Context] = None,
56         getter: Getter = default_getter,
57     ) -> Context:
58 
59         traceid = _extract_first_element(
60             getter.get(carrier, OT_TRACE_ID_HEADER), INVALID_TRACE_ID
61         )
62 
63         spanid = _extract_first_element(
64             getter.get(carrier, OT_SPAN_ID_HEADER), INVALID_SPAN_ID
65         )
66 
67         sampled = _extract_first_element(
68             getter.get(carrier, OT_SAMPLED_HEADER)
69         )
70 
71         if sampled == "true":
72             traceflags = TraceFlags.SAMPLED
73         else:
74             traceflags = TraceFlags.DEFAULT
75 
76         if (
77             traceid != INVALID_TRACE_ID
78             and _valid_extract_traceid.fullmatch(traceid) is not None
79             and spanid != INVALID_SPAN_ID
80             and _valid_extract_spanid.fullmatch(spanid) is not None
81         ):
82             context = set_span_in_context(
83                 NonRecordingSpan(
84                     SpanContext(
85                         trace_id=int(traceid, 16),
86                         span_id=int(spanid, 16),
87                         is_remote=True,
88                         trace_flags=traceflags,
89                     )
90                 ),
91                 context,
92             )
93 
94             baggage = get_all(context) or {}
95 
96             for key in getter.keys(carrier):
97 
98                 if not key.startswith(OT_BAGGAGE_PREFIX):
99                     continue
100 
101                 baggage[
102                     key[len(OT_BAGGAGE_PREFIX) :]
103                 ] = _extract_first_element(getter.get(carrier, key))
104 
105             for key, value in baggage.items():
106                 context = set_baggage(key, value, context)
107 
108         return context
109 
110     def inject(
111         self,
112         carrier: CarrierT,
113         context: Optional[Context] = None,
114         setter: Setter = default_setter,
115     ) -> None:
116 
117         span_context = get_current_span(context).get_span_context()
118 
119         if span_context.trace_id == INVALID_TRACE_ID:
120             return
121 
122         setter.set(
123             carrier, OT_TRACE_ID_HEADER, hex(span_context.trace_id)[2:][-16:]
124         )
125         setter.set(
126             carrier, OT_SPAN_ID_HEADER, hex(span_context.span_id)[2:][-16:],
127         )
128 
129         if span_context.trace_flags == TraceFlags.SAMPLED:
130             traceflags = "true"
131         else:
132             traceflags = "false"
133 
134         setter.set(carrier, OT_SAMPLED_HEADER, traceflags)
135 
136         baggage = get_all(context)
137 
138         if not baggage:
139             return
140 
141         for header_name, header_value in baggage.items():
142 
143             if (
144                 _valid_header_name.fullmatch(header_name) is None
145                 or _valid_header_value.fullmatch(header_value) is None
146             ):
147                 continue
148 
149             setter.set(
150                 carrier,
151                 "".join([OT_BAGGAGE_PREFIX, header_name]),
152                 header_value,
153             )
154 
155     @property
156     def fields(self):
157         """Returns a set with the fields set in `inject`.
158 
159         See
160         `opentelemetry.propagators.textmap.TextMapPropagator.fields`
161         """
162         return {
163             OT_TRACE_ID_HEADER,
164             OT_SPAN_ID_HEADER,
165             OT_SAMPLED_HEADER,
166         }
167 
168 
169 def _extract_first_element(
170     items: Iterable[CarrierT], default: Any = None,
171 ) -> Optional[CarrierT]:
172     if items is None:
173         return default
174     return next(iter(items), None)
175
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

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 @@
                         trace_id=int(traceid, 16),
                         span_id=int(spanid, 16),
                         is_remote=True,
-                        trace_flags=traceflags,
+                        trace_flags=TraceFlags(traceflags),
                     )
                 ),
                 context,

{"golden_diff": "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\n--- a/propagator/opentelemetry-propagator-ot-trace/src/opentelemetry/propagators/ot_trace/__init__.py\n+++ b/propagator/opentelemetry-propagator-ot-trace/src/opentelemetry/propagators/ot_trace/__init__.py\n@@ -85,7 +85,7 @@\n                         trace_id=int(traceid, 16),\n                         span_id=int(spanid, 16),\n                         is_remote=True,\n-                        trace_flags=traceflags,\n+                        trace_flags=TraceFlags(traceflags),\n                     )\n                 ),\n                 context,\n", "issue": "OpenTracing propagator does not use a TraceFlags object\nI set up a client and server that propagated spans using the OpenTracing propagator. The server side reported this error:\r\n\r\n```\r\n[2021-04-26 16:41:13,377] ERROR in app: Exception on /ping [GET]\r\nTraceback (most recent call last):\r\n  File \"/home/ocelotl/virtual_environments/LS-22507/lib/python3.8/site-packages/flask/app.py\", line 2447, in wsgi_app\r\n    response = self.full_dispatch_request()\r\n  File \"/home/ocelotl/virtual_environments/LS-22507/lib/python3.8/site-packages/flask/app.py\", line 1952, in full_dispatch_request\r\n    rv = self.handle_user_exception(e)\r\n  File \"/home/ocelotl/virtual_environments/LS-22507/lib/python3.8/site-packages/flask/app.py\", line 1821, in handle_user_exception\r\n    reraise(exc_type, exc_value, tb)\r\n  File \"/home/ocelotl/virtual_environments/LS-22507/lib/python3.8/site-packages/flask/_compat.py\", line 39, in reraise\r\n    raise value\r\n  File \"/home/ocelotl/virtual_environments/LS-22507/lib/python3.8/site-packages/flask/app.py\", line 1950, in full_dispatch_request\r\n    rv = self.dispatch_request()\r\n  File \"/home/ocelotl/virtual_environments/LS-22507/lib/python3.8/site-packages/flask/app.py\", line 1936, in dispatch_request\r\n    return self.view_functions[rule.endpoint](**req.view_args)\r\n  File \"server.py\", line 53, in ping\r\n    with tracer.start_as_current_span(\r\n  File \"/home/ocelotl/.pyenv/versions/3.8.3/lib/python3.8/contextlib.py\", line 113, in __enter__\r\n    return next(self.gen)\r\n  File \"/home/ocelotl/github/ocelotl/opentelemetry-python/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py\", line 863, in start_as_current_span\r\n    span = self.start_span(\r\n  File \"/home/ocelotl/github/ocelotl/opentelemetry-python/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py\", line 917, in start_span\r\n    sampling_result = self.sampler.should_sample(\r\n  File \"/home/ocelotl/github/ocelotl/opentelemetry-python/opentelemetry-sdk/src/opentelemetry/sdk/trace/sampling.py\", line 326, in should_sample\r\n    if parent_span_context.trace_flags.sampled:\r\nAttributeError: 'int' object has no attribute 'sampled'\r\n```\r\n\r\nThis happens because when instantiating a context during propagation with the OpenTracing propagator, a `TracFlags` object is not used for the trace flags.\n", "before_files": [{"content": "# Copyright The OpenTelemetry Authors\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nfrom re import compile as re_compile\nfrom typing import Any, Iterable, Optional\n\nfrom opentelemetry.baggage import get_all, set_baggage\nfrom opentelemetry.context import Context\nfrom opentelemetry.propagators.textmap import (\n    CarrierT,\n    Getter,\n    Setter,\n    TextMapPropagator,\n    default_getter,\n    default_setter,\n)\nfrom opentelemetry.trace import (\n    INVALID_SPAN_ID,\n    INVALID_TRACE_ID,\n    NonRecordingSpan,\n    SpanContext,\n    TraceFlags,\n    get_current_span,\n    set_span_in_context,\n)\n\nOT_TRACE_ID_HEADER = \"ot-tracer-traceid\"\nOT_SPAN_ID_HEADER = \"ot-tracer-spanid\"\nOT_SAMPLED_HEADER = \"ot-tracer-sampled\"\nOT_BAGGAGE_PREFIX = \"ot-baggage-\"\n\n_valid_header_name = re_compile(r\"[\\w_^`!#$%&'*+.|~]+\")\n_valid_header_value = re_compile(r\"[\\t\\x20-\\x7e\\x80-\\xff]+\")\n_valid_extract_traceid = re_compile(r\"[0-9a-f]{1,32}\")\n_valid_extract_spanid = re_compile(r\"[0-9a-f]{1,16}\")\n\n\nclass OTTracePropagator(TextMapPropagator):\n    \"\"\"Propagator for the OTTrace HTTP header format\"\"\"\n\n    def extract(\n        self,\n        carrier: CarrierT,\n        context: Optional[Context] = None,\n        getter: Getter = default_getter,\n    ) -> Context:\n\n        traceid = _extract_first_element(\n            getter.get(carrier, OT_TRACE_ID_HEADER), INVALID_TRACE_ID\n        )\n\n        spanid = _extract_first_element(\n            getter.get(carrier, OT_SPAN_ID_HEADER), INVALID_SPAN_ID\n        )\n\n        sampled = _extract_first_element(\n            getter.get(carrier, OT_SAMPLED_HEADER)\n        )\n\n        if sampled == \"true\":\n            traceflags = TraceFlags.SAMPLED\n        else:\n            traceflags = TraceFlags.DEFAULT\n\n        if (\n            traceid != INVALID_TRACE_ID\n            and _valid_extract_traceid.fullmatch(traceid) is not None\n            and spanid != INVALID_SPAN_ID\n            and _valid_extract_spanid.fullmatch(spanid) is not None\n        ):\n            context = set_span_in_context(\n                NonRecordingSpan(\n                    SpanContext(\n                        trace_id=int(traceid, 16),\n                        span_id=int(spanid, 16),\n                        is_remote=True,\n                        trace_flags=traceflags,\n                    )\n                ),\n                context,\n            )\n\n            baggage = get_all(context) or {}\n\n            for key in getter.keys(carrier):\n\n                if not key.startswith(OT_BAGGAGE_PREFIX):\n                    continue\n\n                baggage[\n                    key[len(OT_BAGGAGE_PREFIX) :]\n                ] = _extract_first_element(getter.get(carrier, key))\n\n            for key, value in baggage.items():\n                context = set_baggage(key, value, context)\n\n        return context\n\n    def inject(\n        self,\n        carrier: CarrierT,\n        context: Optional[Context] = None,\n        setter: Setter = default_setter,\n    ) -> None:\n\n        span_context = get_current_span(context).get_span_context()\n\n        if span_context.trace_id == INVALID_TRACE_ID:\n            return\n\n        setter.set(\n            carrier, OT_TRACE_ID_HEADER, hex(span_context.trace_id)[2:][-16:]\n        )\n        setter.set(\n            carrier, OT_SPAN_ID_HEADER, hex(span_context.span_id)[2:][-16:],\n        )\n\n        if span_context.trace_flags == TraceFlags.SAMPLED:\n            traceflags = \"true\"\n        else:\n            traceflags = \"false\"\n\n        setter.set(carrier, OT_SAMPLED_HEADER, traceflags)\n\n        baggage = get_all(context)\n\n        if not baggage:\n            return\n\n        for header_name, header_value in baggage.items():\n\n            if (\n                _valid_header_name.fullmatch(header_name) is None\n                or _valid_header_value.fullmatch(header_value) is None\n            ):\n                continue\n\n            setter.set(\n                carrier,\n                \"\".join([OT_BAGGAGE_PREFIX, header_name]),\n                header_value,\n            )\n\n    @property\n    def fields(self):\n        \"\"\"Returns a set with the fields set in `inject`.\n\n        See\n        `opentelemetry.propagators.textmap.TextMapPropagator.fields`\n        \"\"\"\n        return {\n            OT_TRACE_ID_HEADER,\n            OT_SPAN_ID_HEADER,\n            OT_SAMPLED_HEADER,\n        }\n\n\ndef _extract_first_element(\n    items: Iterable[CarrierT], default: Any = None,\n) -> Optional[CarrierT]:\n    if items is None:\n        return default\n    return next(iter(items), None)\n", "path": "propagator/opentelemetry-propagator-ot-trace/src/opentelemetry/propagators/ot_trace/__init__.py"}], "after_files": [{"content": "# Copyright The OpenTelemetry Authors\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nfrom re import compile as re_compile\nfrom typing import Any, Iterable, Optional\n\nfrom opentelemetry.baggage import get_all, set_baggage\nfrom opentelemetry.context import Context\nfrom opentelemetry.propagators.textmap import (\n    CarrierT,\n    Getter,\n    Setter,\n    TextMapPropagator,\n    default_getter,\n    default_setter,\n)\nfrom opentelemetry.trace import (\n    INVALID_SPAN_ID,\n    INVALID_TRACE_ID,\n    NonRecordingSpan,\n    SpanContext,\n    TraceFlags,\n    get_current_span,\n    set_span_in_context,\n)\n\nOT_TRACE_ID_HEADER = \"ot-tracer-traceid\"\nOT_SPAN_ID_HEADER = \"ot-tracer-spanid\"\nOT_SAMPLED_HEADER = \"ot-tracer-sampled\"\nOT_BAGGAGE_PREFIX = \"ot-baggage-\"\n\n_valid_header_name = re_compile(r\"[\\w_^`!#$%&'*+.|~]+\")\n_valid_header_value = re_compile(r\"[\\t\\x20-\\x7e\\x80-\\xff]+\")\n_valid_extract_traceid = re_compile(r\"[0-9a-f]{1,32}\")\n_valid_extract_spanid = re_compile(r\"[0-9a-f]{1,16}\")\n\n\nclass OTTracePropagator(TextMapPropagator):\n    \"\"\"Propagator for the OTTrace HTTP header format\"\"\"\n\n    def extract(\n        self,\n        carrier: CarrierT,\n        context: Optional[Context] = None,\n        getter: Getter = default_getter,\n    ) -> Context:\n\n        traceid = _extract_first_element(\n            getter.get(carrier, OT_TRACE_ID_HEADER), INVALID_TRACE_ID\n        )\n\n        spanid = _extract_first_element(\n            getter.get(carrier, OT_SPAN_ID_HEADER), INVALID_SPAN_ID\n        )\n\n        sampled = _extract_first_element(\n            getter.get(carrier, OT_SAMPLED_HEADER)\n        )\n\n        if sampled == \"true\":\n            traceflags = TraceFlags.SAMPLED\n        else:\n            traceflags = TraceFlags.DEFAULT\n\n        if (\n            traceid != INVALID_TRACE_ID\n            and _valid_extract_traceid.fullmatch(traceid) is not None\n            and spanid != INVALID_SPAN_ID\n            and _valid_extract_spanid.fullmatch(spanid) is not None\n        ):\n            context = set_span_in_context(\n                NonRecordingSpan(\n                    SpanContext(\n                        trace_id=int(traceid, 16),\n                        span_id=int(spanid, 16),\n                        is_remote=True,\n                        trace_flags=TraceFlags(traceflags),\n                    )\n                ),\n                context,\n            )\n\n            baggage = get_all(context) or {}\n\n            for key in getter.keys(carrier):\n\n                if not key.startswith(OT_BAGGAGE_PREFIX):\n                    continue\n\n                baggage[\n                    key[len(OT_BAGGAGE_PREFIX) :]\n                ] = _extract_first_element(getter.get(carrier, key))\n\n            for key, value in baggage.items():\n                context = set_baggage(key, value, context)\n\n        return context\n\n    def inject(\n        self,\n        carrier: CarrierT,\n        context: Optional[Context] = None,\n        setter: Setter = default_setter,\n    ) -> None:\n\n        span_context = get_current_span(context).get_span_context()\n\n        if span_context.trace_id == INVALID_TRACE_ID:\n            return\n\n        setter.set(\n            carrier, OT_TRACE_ID_HEADER, hex(span_context.trace_id)[2:][-16:]\n        )\n        setter.set(\n            carrier, OT_SPAN_ID_HEADER, hex(span_context.span_id)[2:][-16:],\n        )\n\n        if span_context.trace_flags == TraceFlags.SAMPLED:\n            traceflags = \"true\"\n        else:\n            traceflags = \"false\"\n\n        setter.set(carrier, OT_SAMPLED_HEADER, traceflags)\n\n        baggage = get_all(context)\n\n        if not baggage:\n            return\n\n        for header_name, header_value in baggage.items():\n\n            if (\n                _valid_header_name.fullmatch(header_name) is None\n                or _valid_header_value.fullmatch(header_value) is None\n            ):\n                continue\n\n            setter.set(\n                carrier,\n                \"\".join([OT_BAGGAGE_PREFIX, header_name]),\n                header_value,\n            )\n\n    @property\n    def fields(self):\n        \"\"\"Returns a set with the fields set in `inject`.\n\n        See\n        `opentelemetry.propagators.textmap.TextMapPropagator.fields`\n        \"\"\"\n        return {\n            OT_TRACE_ID_HEADER,\n            OT_SPAN_ID_HEADER,\n            OT_SAMPLED_HEADER,\n        }\n\n\ndef _extract_first_element(\n    items: Iterable[CarrierT], default: Any = None,\n) -> Optional[CarrierT]:\n    if items is None:\n        return default\n    return next(iter(items), None)\n", "path": "propagator/opentelemetry-propagator-ot-trace/src/opentelemetry/propagators/ot_trace/__init__.py"}]}