Skip to content

Commit 56bdb95

Browse files
revert(tracing/internal): disable Datadog internal tag propagation (#3326) (#3329)
(cherry picked from commit 99b9fac) Co-authored-by: Brett Langdon <[email protected]>
1 parent 41503d5 commit 56bdb95

File tree

7 files changed

+11
-267
lines changed

7 files changed

+11
-267
lines changed

benchmarks/http_propagation_extract/config.yaml

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ valid_headers_basic: &valid_headers_basic
2626
valid_headers_all: &valid_headers_all
2727
<<: *default_values
2828
headers: |
29-
{"x-datadog-trace-id": "1234", "x-datadog-span-id": "5678", "x-datadog-sampling-priority": "1", "x-datadog-origin": "synthetics", "x-datadog-tags": "_dd.p.tag=value,_dd.p.some_long_key=some_long_value"}
29+
{"x-datadog-trace-id": "1234", "x-datadog-span-id": "5678", "x-datadog-sampling-priority": "1", "x-datadog-origin": "synthetics"}
3030
3131
# All valid/possible headers but 20 additional unrelated headers
3232
medium_valid_headers_all: &medium_valid_headers_all
@@ -42,25 +42,19 @@ large_valid_headers_all: &large_valid_headers_all
4242
invalid_trace_id_header: &invalid_trace_id_header
4343
<<: *default_values
4444
headers: |
45-
{"x-datadog-trace-id": "trace_id", "x-datadog-span-id": "5678", "x-datadog-sampling-priority": "1", "x-datadog-origin": "synthetics", "x-datadog-tags": "_dd.p.tag=value,_dd.p.some_long_key=some_long_value"}
45+
{"x-datadog-trace-id": "trace_id", "x-datadog-span-id": "5678", "x-datadog-sampling-priority": "1", "x-datadog-origin": "synthetics"}
4646
4747
# x-datadog-span-id is invalid
4848
invalid_span_id_header: &invalid_span_id_header
4949
<<: *default_values
5050
headers: |
51-
{"x-datadog-trace-id": "1234", "x-datadog-span-id": "span_id", "x-datadog-sampling-priority": "1", "x-datadog-origin": "synthetics", "x-datadog-tags": "_dd.p.tag=value,_dd.p.some_long_key=some_long_value"}
51+
{"x-datadog-trace-id": "1234", "x-datadog-span-id": "span_id", "x-datadog-sampling-priority": "1", "x-datadog-origin": "synthetics"}
5252
5353
# x-datadog-sampling-priority is invalid
5454
invalid_priority_header: &invalid_priority_header
5555
<<: *default_values
5656
headers: |
57-
{"x-datadog-trace-id": "1234", "x-datadog-span-id": "5678", "x-datadog-sampling-priority": "priority", "x-datadog-origin": "synthetics", "x-datadog-tags": "_dd.p.tag=value,_dd.p.some_long_key=some_long_value"}
58-
59-
# x-datadog-tags is invalid
60-
invalid_tags_header: &invalid_tags_header
61-
<<: *default_values
62-
headers: |
63-
{"x-datadog-trace-id": "1234", "x-datadog-span-id": "5678", "x-datadog-sampling-priority": "1", "x-datadog-origin": "synthetics", "x-datadog-tags": "_dd.p.tag=value,_dd.p.some_long_key=some_long_value,key=,=value,"}
57+
{"x-datadog-trace-id": "1234", "x-datadog-span-id": "5678", "x-datadog-sampling-priority": "priority", "x-datadog-origin": "synthetics"}
6458
6559
6660
# Same scenarios as above but with HTTP_WSGI_STYLE_HEADERS
@@ -103,7 +97,3 @@ wsgi_invalid_span_id_header:
10397
wsgi_invalid_priority_header:
10498
<<: *invalid_priority_header
10599
wsgi_style: True
106-
107-
wsgi_invalid_tags_header:
108-
<<: *invalid_tags_header
109-
wsgi_style: True

benchmarks/http_propagation_extract/scenario.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import bm
44

5+
from ddtrace.propagation import _utils as utils
56
from ddtrace.propagation import http
6-
from ddtrace.propagation import utils
77

88

99
class HTTPPropagationExtract(bm.Scenario):
Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
ids_only: &defaults
22
sampling_priority: ""
33
dd_origin: ""
4-
meta: ""
54

65
with_sampling_priority:
76
<<: *defaults
@@ -16,25 +15,3 @@ with_priority_and_origin:
1615
sampling_priority: "1"
1716
dd_origin: "synthetics"
1817

19-
with_tags:
20-
<<: *defaults
21-
meta: |
22-
{"_dd.p.test": "value", "_dd.p.sample": "value", "will.be": "skipped"}
23-
24-
with_all:
25-
<<: *defaults
26-
sampling_priority: "1"
27-
dd_origin: "synthetics"
28-
meta: |
29-
{"_dd.p.test": "value", "_dd.p.sample": "value", "will.be": "skipped"}
30-
31-
with_tags_invalid:
32-
<<: *defaults
33-
meta: |
34-
{"_dd.p.test": "value", "_dd.p.test=": "=value,"}
35-
36-
with_tags_max_size:
37-
<<: *defaults
38-
# The limit is 512, so one of these will can be encoded, but not both
39-
meta: |
40-
{"_dd.p.test": "______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________", "_dd.p.sample": "______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________"}

benchmarks/http_propagation_inject/scenario.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import json
2-
31
import bm
42

53
from ddtrace.context import Context
@@ -9,24 +7,18 @@
97
class HTTPPropagationInject(bm.Scenario):
108
sampling_priority = bm.var(type=str)
119
dd_origin = bm.var(type=str)
12-
meta = bm.var(type=str)
1310

1411
def run(self):
1512
sampling_priority = None
1613
if self.sampling_priority != "":
1714
sampling_priority = int(self.sampling_priority)
1815
dd_origin = self.dd_origin or None
1916

20-
meta = None
21-
if self.meta:
22-
meta = json.loads(self.meta)
23-
2417
ctx = Context(
2518
trace_id=8336172473188639332,
2619
span_id=6804240797025004118,
2720
sampling_priority=sampling_priority,
2821
dd_origin=dd_origin,
29-
meta=meta,
3022
)
3123

3224
def _(loops):

ddtrace/propagation/http.py

Lines changed: 1 addition & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,8 @@
11
from typing import Dict
22
from typing import FrozenSet
33
from typing import Optional
4-
from typing import Union
5-
from typing import cast
64

75
from ..context import Context
8-
from ..internal._tagset import TagsetDecodeError
9-
from ..internal._tagset import TagsetEncodeError
10-
from ..internal._tagset import TagsetMaxSizeError
11-
from ..internal._tagset import decode_tagset_string
12-
from ..internal._tagset import encode_tagset_values
13-
from ..internal.compat import ensure_str
146
from ..internal.logger import get_logger
157
from ._utils import get_wsgi_header
168

@@ -23,7 +15,6 @@
2315
HTTP_HEADER_PARENT_ID = "x-datadog-parent-id"
2416
HTTP_HEADER_SAMPLING_PRIORITY = "x-datadog-sampling-priority"
2517
HTTP_HEADER_ORIGIN = "x-datadog-origin"
26-
HTTP_HEADER_TAGS = "x-datadog-tags"
2718

2819

2920
# Note that due to WSGI spec we have to also check for uppercased and prefixed
@@ -34,7 +25,6 @@
3425
[HTTP_HEADER_SAMPLING_PRIORITY, get_wsgi_header(HTTP_HEADER_SAMPLING_PRIORITY).lower()]
3526
)
3627
POSSIBLE_HTTP_HEADER_ORIGIN = frozenset([HTTP_HEADER_ORIGIN, get_wsgi_header(HTTP_HEADER_ORIGIN).lower()])
37-
POSSIBLE_HTTP_HEADER_TAGS = frozenset([HTTP_HEADER_TAGS, get_wsgi_header(HTTP_HEADER_TAGS).lower()])
3828

3929

4030
class HTTPPropagator(object):
@@ -74,30 +64,6 @@ def parent_call():
7464
if "_dd.propagation_error" in span_context._meta:
7565
return
7666

77-
# Only propagate tags that start with `_dd.p.`
78-
tags_to_encode = {} # type: Dict[str, str]
79-
for key, value in span_context._meta.items():
80-
# DEV: encoding will fail if the key or value are not `str`
81-
key = ensure_str(key)
82-
if key.startswith("_dd.p."):
83-
tags_to_encode[key] = ensure_str(value)
84-
85-
if tags_to_encode:
86-
encoded_tags = None
87-
88-
try:
89-
encoded_tags = encode_tagset_values(tags_to_encode)
90-
except TagsetMaxSizeError:
91-
# We hit the max size allowed, add a tag to the context to indicate this happened
92-
span_context._meta["_dd.propagation_error"] = "max_size"
93-
log.warning("failed to encode x-datadog-tags", exc_info=True)
94-
except TagsetEncodeError:
95-
# We hit an encoding error, add a tag to the context to indicate this happened
96-
span_context._meta["_dd.propagation_error"] = "encoding_error"
97-
log.warning("failed to encode x-datadog-tags", exc_info=True)
98-
if encoded_tags:
99-
headers[HTTP_HEADER_TAGS] = encoded_tags
100-
10167
@staticmethod
10268
def _extract_header_value(possible_header_names, headers, default=None):
10369
# type: (FrozenSet[str], Dict[str, str], Optional[str]) -> Optional[str]
@@ -155,19 +121,6 @@ def my_controller(url, headers):
155121
POSSIBLE_HTTP_HEADER_ORIGIN,
156122
normalized_headers,
157123
)
158-
meta = None
159-
tags_value = HTTPPropagator._extract_header_value(
160-
POSSIBLE_HTTP_HEADER_TAGS,
161-
normalized_headers,
162-
default="",
163-
)
164-
if tags_value:
165-
# Do not fail if the tags are malformed
166-
try:
167-
# We get a Dict[str, str], but need it to be Dict[Union[str, bytes], str] (e.g. _MetaDictType)
168-
meta = cast(Dict[Union[str, bytes], str], decode_tagset_string(tags_value))
169-
except TagsetDecodeError:
170-
log.debug("failed to decode x-datadog-tags: %r", tags_value, exc_info=True)
171124

172125
# Try to parse values into their expected types
173126
try:
@@ -182,20 +135,15 @@ def my_controller(url, headers):
182135
span_id=int(parent_span_id) or None, # type: ignore[arg-type]
183136
sampling_priority=sampling_priority, # type: ignore[arg-type]
184137
dd_origin=origin,
185-
meta=meta,
186138
)
187139
# If headers are invalid and cannot be parsed, return a new context and log the issue.
188140
except (TypeError, ValueError):
189141
log.debug(
190-
(
191-
"received invalid x-datadog-* headers, "
192-
"trace-id: %r, parent-id: %r, priority: %r, origin: %r, tags: %r"
193-
),
142+
"received invalid x-datadog-* headers, " "trace-id: %r, parent-id: %r, priority: %r, origin: %r",
194143
trace_id,
195144
parent_span_id,
196145
sampling_priority,
197146
origin,
198-
tags_value,
199147
)
200148
return Context()
201149
except Exception:
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
other:
3+
- |
4+
tracing/internal: disable Datadog internal tag propagation

0 commit comments

Comments
 (0)