Skip to content

Commit d02133a

Browse files
Deprecate ddtrace.propagation.utils (#3068)
In preparation for the 1.0 release where we'll remove the utils module. Co-authored-by: Kyle Verhoog <kyle@verhoog.ca>
1 parent fc8eb28 commit d02133a

File tree

8 files changed

+48
-34
lines changed

8 files changed

+48
-34
lines changed

ddtrace/contrib/django/utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from ddtrace.constants import SPAN_MEASURED_KEY
77
from ddtrace.contrib import func_name
88
from ddtrace.ext import SpanTypes
9-
from ddtrace.propagation.utils import from_wsgi_header
9+
from ddtrace.propagation._utils import from_wsgi_header
1010

1111
from .. import trace_utils
1212
from ...internal.logger import get_logger

ddtrace/contrib/wsgi/wsgi.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
from ddtrace import config
2121
from ddtrace.ext import SpanTypes
2222
from ddtrace.internal.logger import get_logger
23+
from ddtrace.propagation._utils import from_wsgi_header
2324
from ddtrace.propagation.http import HTTPPropagator
24-
from ddtrace.propagation.utils import from_wsgi_header
2525

2626
from .. import trace_utils
2727

ddtrace/propagation/_utils.py

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from typing import Optional
2+
3+
from ddtrace.internal.utils.cache import cached
4+
5+
6+
@cached()
7+
def get_wsgi_header(header):
8+
# type: (str) -> str
9+
"""Returns a WSGI compliant HTTP header.
10+
See https://www.python.org/dev/peps/pep-3333/#environ-variables for
11+
information from the spec.
12+
"""
13+
return "HTTP_{}".format(header.upper().replace("-", "_"))
14+
15+
16+
@cached()
17+
def from_wsgi_header(header):
18+
# type: (str) -> Optional[str]
19+
"""Convert a WSGI compliant HTTP header into the original header.
20+
See https://www.python.org/dev/peps/pep-3333/#environ-variables for
21+
information from the spec.
22+
"""
23+
HTTP_PREFIX = "HTTP_"
24+
# PEP 333 gives two headers which aren't prepended with HTTP_.
25+
UNPREFIXED_HEADERS = {"CONTENT_TYPE", "CONTENT_LENGTH"}
26+
27+
if header.startswith(HTTP_PREFIX):
28+
header = header[len(HTTP_PREFIX) :]
29+
elif header not in UNPREFIXED_HEADERS:
30+
return None
31+
return header.replace("_", "-").title()

ddtrace/propagation/http.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from ..internal._tagset import encode_tagset_values
1313
from ..internal.compat import ensure_str
1414
from ..internal.logger import get_logger
15-
from .utils import get_wsgi_header
15+
from ._utils import get_wsgi_header
1616

1717

1818
log = get_logger(__name__)

ddtrace/propagation/utils.py

+8-29
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,10 @@
1-
from typing import Optional
1+
from ..internal.utils.deprecation import deprecation
2+
from ._utils import from_wsgi_header # noqa
3+
from ._utils import get_wsgi_header # noqa
24

3-
from ddtrace.internal.utils.cache import cached
45

5-
6-
@cached()
7-
def get_wsgi_header(header):
8-
# type: (str) -> str
9-
"""Returns a WSGI compliant HTTP header.
10-
See https://www.python.org/dev/peps/pep-3333/#environ-variables for
11-
information from the spec.
12-
"""
13-
return "HTTP_{}".format(header.upper().replace("-", "_"))
14-
15-
16-
@cached()
17-
def from_wsgi_header(header):
18-
# type: (str) -> Optional[str]
19-
"""Convert a WSGI compliant HTTP header into the original header.
20-
See https://www.python.org/dev/peps/pep-3333/#environ-variables for
21-
information from the spec.
22-
"""
23-
HTTP_PREFIX = "HTTP_"
24-
# PEP 333 gives two headers which aren't prepended with HTTP_.
25-
UNPREFIXED_HEADERS = {"CONTENT_TYPE", "CONTENT_LENGTH"}
26-
27-
if header.startswith(HTTP_PREFIX):
28-
header = header[len(HTTP_PREFIX) :]
29-
elif header not in UNPREFIXED_HEADERS:
30-
return None
31-
return header.replace("_", "-").title()
6+
deprecation(
7+
name="ddtrace.propagation.utils",
8+
message="This module will be removed in v1.0.",
9+
version="1.0.0",
10+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
deprecations:
3+
- |
4+
``ddtrace.propagation.utils`` has been deprecated and will be removed in version 1.0.``

tests/contrib/django/test_django.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@
2828
from ddtrace.internal.compat import PY2
2929
from ddtrace.internal.compat import binary_type
3030
from ddtrace.internal.compat import string_type
31+
from ddtrace.propagation._utils import get_wsgi_header
3132
from ddtrace.propagation.http import HTTP_HEADER_PARENT_ID
3233
from ddtrace.propagation.http import HTTP_HEADER_SAMPLING_PRIORITY
3334
from ddtrace.propagation.http import HTTP_HEADER_TRACE_ID
34-
from ddtrace.propagation.utils import get_wsgi_header
3535
from ddtrace.vendor import wrapt
3636
from tests.opentracer.utils import init_tracer
3737
from tests.utils import assert_dict_issuperset

tests/tracer/test_propagation.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
import pytest
55

66
from ddtrace.context import Context
7+
from ddtrace.propagation._utils import get_wsgi_header
78
from ddtrace.propagation.http import HTTPPropagator
89
from ddtrace.propagation.http import HTTP_HEADER_ORIGIN
910
from ddtrace.propagation.http import HTTP_HEADER_PARENT_ID
1011
from ddtrace.propagation.http import HTTP_HEADER_SAMPLING_PRIORITY
1112
from ddtrace.propagation.http import HTTP_HEADER_TAGS
1213
from ddtrace.propagation.http import HTTP_HEADER_TRACE_ID
13-
from ddtrace.propagation.utils import get_wsgi_header
1414
from tests.utils import DummyTracer
1515

1616

0 commit comments

Comments
 (0)