prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  `ddtrace.opentracer` incorrectly raises `SpanContextCorruptedException` on `extract` of missing span context
  The documentation for `SpanContextCorruptedException` [says](https://opentracing-python.readthedocs.io/en/1.3.0/api.html#opentracing.SpanContextCorruptedException):
  
  > SpanContextCorruptedException should be used when the underlying span context state is seemingly present but not well-formed.
  
  `ddtrace.opentracer`'s `extract` is throwing an error whenever it fails to recover a span, whether or not it was malformed or simply missing.  This completely breaks the normal pattern of "I received an HTTP request, so I'll throw the headers at `extract` and pass the result to `child_of` for my new span, expecting to get `None` and therefore make a new root span if I was called without tracing info".
  
  ### Which version of dd-trace-py are you using?
  
  Python 3.7
  ddtrace 0.46.0
  
  ### How can we reproduce your problem?
  
  ```py
  In [1]: from opentracing import Format
  
  In [2]: from ddtrace.opentracer import Tracer
  
  In [3]: tracer = Tracer()
  
  In [4]: tracer.extract(Format.HTTP_HEADERS, {})
  ---------------------------------------------------------------------------
  SpanContextCorruptedException             Traceback (most recent call last)
  <ipython-input-4-f497fe0c23a2> in <module>
  ----> 1 tracer.extract(Format.HTTP_HEADERS, {})
  
  ~/projects/granular/analysis/analysis-api/.venv/lib/python3.7/site-packages/ddtrace/opentracer/tracer.py in extract(self, format, carrier)
      326         # we have to manually activate the returned context from a distributed
      327         # trace
  --> 328         ot_span_ctx = propagator.extract(carrier)
      329         dd_span_ctx = ot_span_ctx._dd_context
      330         self._dd_tracer.context_provider.activate(dd_span_ctx)
  
  ~/projects/granular/analysis/analysis-api/.venv/lib/python3.7/site-packages/ddtrace/opentracer/propagation/http.py in extract(self, carrier)
       70         # if this occurs.
       71         if not ddspan_ctx.trace_id:
  ---> 72             raise SpanContextCorruptedException("failed to extract span context")
       73 
       74         baggage = {}
  
  SpanContextCorruptedException: failed to extract span context
  ```
  
  ### What is the result that you expected?
  
  I expect to get a clean `None` with no error if no DataDog span context material was present.  See Jaeger:
  
  ```py
  In [1]: from opentracing import Format
  
  In [2]: import jaeger_client
  
  In [3]: tracer = jaeger_client.Config({"service_name": "foo"}).initialize_tracer()
  
  In [4]: tracer.extract(Format.HTTP_HEADERS, {})
  
  In [5]: print(tracer.extract(Format.HTTP_HEADERS, {}))
  None
  ```
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `ddtrace/opentracer/propagation/http.py`
  Content:
  ```
  1 from typing import Dict
  2 
  3 from opentracing import InvalidCarrierException
  4 from opentracing import SpanContextCorruptedException
  5 
  6 from ddtrace.propagation.http import HTTPPropagator as DDHTTPPropagator
  7 
  8 from ...internal.logger import get_logger
  9 from ..span_context import SpanContext
  10 from .propagator import Propagator
  11 
  12 
  13 log = get_logger(__name__)
  14 
  15 HTTP_BAGGAGE_PREFIX = "ot-baggage-"
  16 HTTP_BAGGAGE_PREFIX_LEN = len(HTTP_BAGGAGE_PREFIX)
  17 
  18 
  19 class HTTPPropagator(Propagator):
  20     """OpenTracing compatible HTTP_HEADER and TEXT_MAP format propagator.
  21 
  22     `HTTPPropagator` provides compatibility by using existing OpenTracing
  23     compatible methods from the ddtracer along with new logic supporting the
  24     outstanding OpenTracing-defined functionality.
  25     """
  26 
  27     @staticmethod
  28     def inject(span_context, carrier):
  29         # type: (SpanContext, Dict[str, str]) -> None
  30         """Inject a span context into a carrier.
  31 
  32         *span_context* is injected into the carrier by first using an
  33         :class:`ddtrace.propagation.http.HTTPPropagator` to inject the ddtracer
  34         specific fields.
  35 
  36         Then the baggage is injected into *carrier*.
  37 
  38         :param span_context: span context to inject.
  39 
  40         :param carrier: carrier to inject into.
  41         """
  42         if not isinstance(carrier, dict):
  43             raise InvalidCarrierException("propagator expects carrier to be a dict")
  44 
  45         DDHTTPPropagator.inject(span_context._dd_context, carrier)
  46 
  47         # Add the baggage
  48         if span_context.baggage is not None:
  49             for key in span_context.baggage:
  50                 carrier[HTTP_BAGGAGE_PREFIX + key] = span_context.baggage[key]
  51 
  52     @staticmethod
  53     def extract(carrier):
  54         # type: (Dict[str, str]) -> SpanContext
  55         """Extract a span context from a carrier.
  56 
  57         :class:`ddtrace.propagation.http.HTTPPropagator` is used to extract
  58         ddtracer supported fields into a `ddtrace.Context` context which is
  59         combined with new logic to extract the baggage which is returned in an
  60         OpenTracing compatible span context.
  61 
  62         :param carrier: carrier to extract from.
  63 
  64         :return: extracted span context.
  65         """
  66         if not isinstance(carrier, dict):
  67             raise InvalidCarrierException("propagator expects carrier to be a dict")
  68 
  69         ddspan_ctx = DDHTTPPropagator.extract(carrier)
  70 
  71         # if the dd propagator fails then it will return a new empty span
  72         # context (with trace_id=None), we however want to raise an exception
  73         # if this occurs.
  74         if not ddspan_ctx.trace_id:
  75             raise SpanContextCorruptedException("failed to extract span context")
  76 
  77         baggage = {}
  78         for key in carrier:
  79             if key.startswith(HTTP_BAGGAGE_PREFIX):
  80                 baggage[key[HTTP_BAGGAGE_PREFIX_LEN:]] = carrier[key]
  81 
  82         return SpanContext(ddcontext=ddspan_ctx, baggage=baggage)
  83
  ```
  --- 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()
  
  ```
  
golden_diff: diff --git a/ddtrace/opentracer/propagation/http.py b/ddtrace/opentracer/propagation/http.py
  --- a/ddtrace/opentracer/propagation/http.py
  +++ b/ddtrace/opentracer/propagation/http.py
  @@ -1,7 +1,6 @@
   from typing import Dict
   
   from opentracing import InvalidCarrierException
  -from opentracing import SpanContextCorruptedException
   
   from ddtrace.propagation.http import HTTPPropagator as DDHTTPPropagator
   
  @@ -67,13 +66,6 @@
               raise InvalidCarrierException("propagator expects carrier to be a dict")
   
           ddspan_ctx = DDHTTPPropagator.extract(carrier)
  -
  -        # if the dd propagator fails then it will return a new empty span
  -        # context (with trace_id=None), we however want to raise an exception
  -        # if this occurs.
  -        if not ddspan_ctx.trace_id:
  -            raise SpanContextCorruptedException("failed to extract span context")
  -
           baggage = {}
           for key in carrier:
               if key.startswith(HTTP_BAGGAGE_PREFIX):
  
verification_info: {"golden_diff": "diff --git a/ddtrace/opentracer/propagation/http.py b/ddtrace/opentracer/propagation/http.py\n--- a/ddtrace/opentracer/propagation/http.py\n+++ b/ddtrace/opentracer/propagation/http.py\n@@ -1,7 +1,6 @@\n from typing import Dict\n \n from opentracing import InvalidCarrierException\n-from opentracing import SpanContextCorruptedException\n \n from ddtrace.propagation.http import HTTPPropagator as DDHTTPPropagator\n \n@@ -67,13 +66,6 @@\n             raise InvalidCarrierException(\"propagator expects carrier to be a dict\")\n \n         ddspan_ctx = DDHTTPPropagator.extract(carrier)\n-\n-        # if the dd propagator fails then it will return a new empty span\n-        # context (with trace_id=None), we however want to raise an exception\n-        # if this occurs.\n-        if not ddspan_ctx.trace_id:\n-            raise SpanContextCorruptedException(\"failed to extract span context\")\n-\n         baggage = {}\n         for key in carrier:\n             if key.startswith(HTTP_BAGGAGE_PREFIX):\n", "issue": "`ddtrace.opentracer` incorrectly raises `SpanContextCorruptedException` on `extract` of missing span context\nThe documentation for `SpanContextCorruptedException` [says](https://opentracing-python.readthedocs.io/en/1.3.0/api.html#opentracing.SpanContextCorruptedException):\r\n\r\n> SpanContextCorruptedException should be used when the underlying span context state is seemingly present but not well-formed.\r\n\r\n`ddtrace.opentracer`'s `extract` is throwing an error whenever it fails to recover a span, whether or not it was malformed or simply missing.  This completely breaks the normal pattern of \"I received an HTTP request, so I'll throw the headers at `extract` and pass the result to `child_of` for my new span, expecting to get `None` and therefore make a new root span if I was called without tracing info\".\r\n\r\n### Which version of dd-trace-py are you using?\r\n\r\nPython 3.7\r\nddtrace 0.46.0\r\n\r\n### How can we reproduce your problem?\r\n\r\n```py\r\nIn [1]: from opentracing import Format\r\n\r\nIn [2]: from ddtrace.opentracer import Tracer\r\n\r\nIn [3]: tracer = Tracer()\r\n\r\nIn [4]: tracer.extract(Format.HTTP_HEADERS, {})\r\n---------------------------------------------------------------------------\r\nSpanContextCorruptedException             Traceback (most recent call last)\r\n<ipython-input-4-f497fe0c23a2> in <module>\r\n----> 1 tracer.extract(Format.HTTP_HEADERS, {})\r\n\r\n~/projects/granular/analysis/analysis-api/.venv/lib/python3.7/site-packages/ddtrace/opentracer/tracer.py in extract(self, format, carrier)\r\n    326         # we have to manually activate the returned context from a distributed\r\n    327         # trace\r\n--> 328         ot_span_ctx = propagator.extract(carrier)\r\n    329         dd_span_ctx = ot_span_ctx._dd_context\r\n    330         self._dd_tracer.context_provider.activate(dd_span_ctx)\r\n\r\n~/projects/granular/analysis/analysis-api/.venv/lib/python3.7/site-packages/ddtrace/opentracer/propagation/http.py in extract(self, carrier)\r\n     70         # if this occurs.\r\n     71         if not ddspan_ctx.trace_id:\r\n---> 72             raise SpanContextCorruptedException(\"failed to extract span context\")\r\n     73 \r\n     74         baggage = {}\r\n\r\nSpanContextCorruptedException: failed to extract span context\r\n```\r\n\r\n### What is the result that you expected?\r\n\r\nI expect to get a clean `None` with no error if no DataDog span context material was present.  See Jaeger:\r\n\r\n```py\r\nIn [1]: from opentracing import Format\r\n\r\nIn [2]: import jaeger_client\r\n\r\nIn [3]: tracer = jaeger_client.Config({\"service_name\": \"foo\"}).initialize_tracer()\r\n\r\nIn [4]: tracer.extract(Format.HTTP_HEADERS, {})\r\n\r\nIn [5]: print(tracer.extract(Format.HTTP_HEADERS, {}))\r\nNone\r\n```\r\n\n", "before_files": [{"content": "from typing import Dict\n\nfrom opentracing import InvalidCarrierException\nfrom opentracing import SpanContextCorruptedException\n\nfrom ddtrace.propagation.http import HTTPPropagator as DDHTTPPropagator\n\nfrom ...internal.logger import get_logger\nfrom ..span_context import SpanContext\nfrom .propagator import Propagator\n\n\nlog = get_logger(__name__)\n\nHTTP_BAGGAGE_PREFIX = \"ot-baggage-\"\nHTTP_BAGGAGE_PREFIX_LEN = len(HTTP_BAGGAGE_PREFIX)\n\n\nclass HTTPPropagator(Propagator):\n    \"\"\"OpenTracing compatible HTTP_HEADER and TEXT_MAP format propagator.\n\n    `HTTPPropagator` provides compatibility by using existing OpenTracing\n    compatible methods from the ddtracer along with new logic supporting the\n    outstanding OpenTracing-defined functionality.\n    \"\"\"\n\n    @staticmethod\n    def inject(span_context, carrier):\n        # type: (SpanContext, Dict[str, str]) -> None\n        \"\"\"Inject a span context into a carrier.\n\n        *span_context* is injected into the carrier by first using an\n        :class:`ddtrace.propagation.http.HTTPPropagator` to inject the ddtracer\n        specific fields.\n\n        Then the baggage is injected into *carrier*.\n\n        :param span_context: span context to inject.\n\n        :param carrier: carrier to inject into.\n        \"\"\"\n        if not isinstance(carrier, dict):\n            raise InvalidCarrierException(\"propagator expects carrier to be a dict\")\n\n        DDHTTPPropagator.inject(span_context._dd_context, carrier)\n\n        # Add the baggage\n        if span_context.baggage is not None:\n            for key in span_context.baggage:\n                carrier[HTTP_BAGGAGE_PREFIX + key] = span_context.baggage[key]\n\n    @staticmethod\n    def extract(carrier):\n        # type: (Dict[str, str]) -> SpanContext\n        \"\"\"Extract a span context from a carrier.\n\n        :class:`ddtrace.propagation.http.HTTPPropagator` is used to extract\n        ddtracer supported fields into a `ddtrace.Context` context which is\n        combined with new logic to extract the baggage which is returned in an\n        OpenTracing compatible span context.\n\n        :param carrier: carrier to extract from.\n\n        :return: extracted span context.\n        \"\"\"\n        if not isinstance(carrier, dict):\n            raise InvalidCarrierException(\"propagator expects carrier to be a dict\")\n\n        ddspan_ctx = DDHTTPPropagator.extract(carrier)\n\n        # if the dd propagator fails then it will return a new empty span\n        # context (with trace_id=None), we however want to raise an exception\n        # if this occurs.\n        if not ddspan_ctx.trace_id:\n            raise SpanContextCorruptedException(\"failed to extract span context\")\n\n        baggage = {}\n        for key in carrier:\n            if key.startswith(HTTP_BAGGAGE_PREFIX):\n                baggage[key[HTTP_BAGGAGE_PREFIX_LEN:]] = carrier[key]\n\n        return SpanContext(ddcontext=ddspan_ctx, baggage=baggage)\n", "path": "ddtrace/opentracer/propagation/http.py"}], "after_files": [{"content": "from typing import Dict\n\nfrom opentracing import InvalidCarrierException\n\nfrom ddtrace.propagation.http import HTTPPropagator as DDHTTPPropagator\n\nfrom ...internal.logger import get_logger\nfrom ..span_context import SpanContext\nfrom .propagator import Propagator\n\n\nlog = get_logger(__name__)\n\nHTTP_BAGGAGE_PREFIX = \"ot-baggage-\"\nHTTP_BAGGAGE_PREFIX_LEN = len(HTTP_BAGGAGE_PREFIX)\n\n\nclass HTTPPropagator(Propagator):\n    \"\"\"OpenTracing compatible HTTP_HEADER and TEXT_MAP format propagator.\n\n    `HTTPPropagator` provides compatibility by using existing OpenTracing\n    compatible methods from the ddtracer along with new logic supporting the\n    outstanding OpenTracing-defined functionality.\n    \"\"\"\n\n    @staticmethod\n    def inject(span_context, carrier):\n        # type: (SpanContext, Dict[str, str]) -> None\n        \"\"\"Inject a span context into a carrier.\n\n        *span_context* is injected into the carrier by first using an\n        :class:`ddtrace.propagation.http.HTTPPropagator` to inject the ddtracer\n        specific fields.\n\n        Then the baggage is injected into *carrier*.\n\n        :param span_context: span context to inject.\n\n        :param carrier: carrier to inject into.\n        \"\"\"\n        if not isinstance(carrier, dict):\n            raise InvalidCarrierException(\"propagator expects carrier to be a dict\")\n\n        DDHTTPPropagator.inject(span_context._dd_context, carrier)\n\n        # Add the baggage\n        if span_context.baggage is not None:\n            for key in span_context.baggage:\n                carrier[HTTP_BAGGAGE_PREFIX + key] = span_context.baggage[key]\n\n    @staticmethod\n    def extract(carrier):\n        # type: (Dict[str, str]) -> SpanContext\n        \"\"\"Extract a span context from a carrier.\n\n        :class:`ddtrace.propagation.http.HTTPPropagator` is used to extract\n        ddtracer supported fields into a `ddtrace.Context` context which is\n        combined with new logic to extract the baggage which is returned in an\n        OpenTracing compatible span context.\n\n        :param carrier: carrier to extract from.\n\n        :return: extracted span context.\n        \"\"\"\n        if not isinstance(carrier, dict):\n            raise InvalidCarrierException(\"propagator expects carrier to be a dict\")\n\n        ddspan_ctx = DDHTTPPropagator.extract(carrier)\n        baggage = {}\n        for key in carrier:\n            if key.startswith(HTTP_BAGGAGE_PREFIX):\n                baggage[key[HTTP_BAGGAGE_PREFIX_LEN:]] = carrier[key]\n\n        return SpanContext(ddcontext=ddspan_ctx, baggage=baggage)\n", "path": "ddtrace/opentracer/propagation/http.py"}]}