Skip to content

Deprecate ddtrace.propagation.utils #3068

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Dec 17, 2021
2 changes: 1 addition & 1 deletion ddtrace/contrib/django/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from ddtrace.constants import SPAN_MEASURED_KEY
from ddtrace.contrib import func_name
from ddtrace.ext import SpanTypes
from ddtrace.propagation.utils import from_wsgi_header
from ddtrace.propagation._utils import from_wsgi_header

from .. import trace_utils
from ...internal.logger import get_logger
Expand Down
2 changes: 1 addition & 1 deletion ddtrace/contrib/wsgi/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
from ddtrace import config
from ddtrace.ext import SpanTypes
from ddtrace.internal.logger import get_logger
from ddtrace.propagation._utils import from_wsgi_header
from ddtrace.propagation.http import HTTPPropagator
from ddtrace.propagation.utils import from_wsgi_header

from .. import trace_utils

Expand Down
31 changes: 31 additions & 0 deletions ddtrace/propagation/_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from typing import Optional

from ddtrace.internal.utils.cache import cached


@cached()
def get_wsgi_header(header):
# type: (str) -> str
"""Returns a WSGI compliant HTTP header.
See https://www.python.org/dev/peps/pep-3333/#environ-variables for
information from the spec.
"""
return "HTTP_{}".format(header.upper().replace("-", "_"))


@cached()
def from_wsgi_header(header):
# type: (str) -> Optional[str]
"""Convert a WSGI compliant HTTP header into the original header.
See https://www.python.org/dev/peps/pep-3333/#environ-variables for
information from the spec.
"""
HTTP_PREFIX = "HTTP_"
# PEP 333 gives two headers which aren't prepended with HTTP_.
UNPREFIXED_HEADERS = {"CONTENT_TYPE", "CONTENT_LENGTH"}

if header.startswith(HTTP_PREFIX):
header = header[len(HTTP_PREFIX) :]
elif header not in UNPREFIXED_HEADERS:
return None
return header.replace("_", "-").title()
2 changes: 1 addition & 1 deletion ddtrace/propagation/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from ..internal._tagset import encode_tagset_values
from ..internal.compat import ensure_str
from ..internal.logger import get_logger
from .utils import get_wsgi_header
from ._utils import get_wsgi_header


log = get_logger(__name__)
Expand Down
37 changes: 8 additions & 29 deletions ddtrace/propagation/utils.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,10 @@
from typing import Optional
from ..internal.utils.deprecation import deprecation
from ._utils import from_wsgi_header # noqa
from ._utils import get_wsgi_header # noqa

from ddtrace.internal.utils.cache import cached


@cached()
def get_wsgi_header(header):
# type: (str) -> str
"""Returns a WSGI compliant HTTP header.
See https://www.python.org/dev/peps/pep-3333/#environ-variables for
information from the spec.
"""
return "HTTP_{}".format(header.upper().replace("-", "_"))


@cached()
def from_wsgi_header(header):
# type: (str) -> Optional[str]
"""Convert a WSGI compliant HTTP header into the original header.
See https://www.python.org/dev/peps/pep-3333/#environ-variables for
information from the spec.
"""
HTTP_PREFIX = "HTTP_"
# PEP 333 gives two headers which aren't prepended with HTTP_.
UNPREFIXED_HEADERS = {"CONTENT_TYPE", "CONTENT_LENGTH"}

if header.startswith(HTTP_PREFIX):
header = header[len(HTTP_PREFIX) :]
elif header not in UNPREFIXED_HEADERS:
return None
return header.replace("_", "-").title()
deprecation(
name="ddtrace.propagation.utils",
message="This module will be removed in v1.0.",
version="1.0.0",
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
deprecations:
- |
``ddtrace.propagation.utils`` has been deprecated and will be removed in version 1.0.``
2 changes: 1 addition & 1 deletion tests/contrib/django/test_django.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
from ddtrace.internal.compat import PY2
from ddtrace.internal.compat import binary_type
from ddtrace.internal.compat import string_type
from ddtrace.propagation._utils import get_wsgi_header
from ddtrace.propagation.http import HTTP_HEADER_PARENT_ID
from ddtrace.propagation.http import HTTP_HEADER_SAMPLING_PRIORITY
from ddtrace.propagation.http import HTTP_HEADER_TRACE_ID
from ddtrace.propagation.utils import get_wsgi_header
from ddtrace.vendor import wrapt
from tests.opentracer.utils import init_tracer
from tests.utils import assert_dict_issuperset
Expand Down
2 changes: 1 addition & 1 deletion tests/tracer/test_propagation.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
import pytest

from ddtrace.context import Context
from ddtrace.propagation._utils import get_wsgi_header
from ddtrace.propagation.http import HTTPPropagator
from ddtrace.propagation.http import HTTP_HEADER_ORIGIN
from ddtrace.propagation.http import HTTP_HEADER_PARENT_ID
from ddtrace.propagation.http import HTTP_HEADER_SAMPLING_PRIORITY
from ddtrace.propagation.http import HTTP_HEADER_TAGS
from ddtrace.propagation.http import HTTP_HEADER_TRACE_ID
from ddtrace.propagation.utils import get_wsgi_header
from tests.utils import DummyTracer


Expand Down