Skip to content

Commit 8bcd435

Browse files
committed
Merge branch 'avara1986/fix_circular_imports' into avara1986/APPSEC-56946_cmdi_secure_mark_check
2 parents 86b22a8 + f1c95df commit 8bcd435

File tree

5 files changed

+30
-41
lines changed

5 files changed

+30
-41
lines changed

ddtrace/appsec/__init__.py

-11
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55

66
_APPSEC_TO_BE_LOADED = True
7-
_IAST_TO_BE_LOADED = True
87

98

109
def load_appsec():
@@ -17,16 +16,6 @@ def load_appsec():
1716
_APPSEC_TO_BE_LOADED = False
1817

1918

20-
def load_iast():
21-
"""Lazily load the iast module listeners."""
22-
from ddtrace.appsec._iast._listener import iast_listen
23-
24-
global _IAST_TO_BE_LOADED
25-
if _IAST_TO_BE_LOADED:
26-
iast_listen()
27-
_IAST_TO_BE_LOADED = False
28-
29-
3019
def load_common_appsec_modules():
3120
"""Lazily load the common module patches."""
3221
from ddtrace.settings.asm import config as asm_config

ddtrace/appsec/_iast/__init__.py

+12-3
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,15 @@ def wrapped_function(wrapped, instance, args, kwargs):
3737
from ddtrace.internal.module import ModuleWatchdog
3838
from ddtrace.settings.asm import config as asm_config
3939

40+
from ._listener import iast_listen
4041
from ._overhead_control_engine import OverheadControl
4142

4243

4344
log = get_logger(__name__)
4445

46+
_IAST_TO_BE_LOADED = True
47+
_iast_propagation_enabled = False
48+
4549
oce = OverheadControl()
4650

4751

@@ -79,9 +83,6 @@ def ddtrace_iast_flask_patch():
7983
exec(compiled_code, module.__dict__) # nosec B102
8084

8185

82-
_iast_propagation_enabled = False
83-
84-
8586
def enable_iast_propagation():
8687
"""Add IAST AST patching in the ModuleWatchdog"""
8788
# DEV: These imports are here to avoid _ast.ast_patching import in the top level
@@ -141,3 +142,11 @@ def disable_iast_propagation():
141142
"enable_iast_propagation",
142143
"disable_iast_propagation",
143144
]
145+
146+
147+
def load_iast():
148+
"""Lazily load the iast module listeners."""
149+
global _IAST_TO_BE_LOADED
150+
if _IAST_TO_BE_LOADED:
151+
iast_listen()
152+
_IAST_TO_BE_LOADED = False

ddtrace/appsec/_iast/processor.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
@dataclass(eq=False)
1616
class AppSecIastSpanProcessor(SpanProcessor):
1717
def __post_init__(self) -> None:
18-
from ddtrace.appsec import load_iast
18+
from . import load_iast
1919

2020
load_iast()
2121

docs/configuration.rst

+3-2
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ Traces
269269

270270
DD_TRACE_PROPAGATION_STYLE:
271271
default: |
272-
``datadog,tracecontext``
272+
``datadog,tracecontext,baggage``
273273

274274
description: |
275275
Comma separated list of propagation styles used for extracting trace context from inbound request headers and injecting trace context into outbound request headers.
@@ -278,7 +278,7 @@ Traces
278278

279279
Overridden by ``DD_TRACE_PROPAGATION_STYLE_INJECT`` for injection.
280280

281-
The supported values are ``datadog``, ``b3multi``, ``tracecontext``, and ``none``.
281+
The supported values are ``datadog``, ``b3multi``, ``tracecontext``, ``baggage``, and ``none``.
282282

283283
When checking inbound request headers we will take the first valid trace context in the order provided.
284284
When ``none`` is the only propagator listed, propagation is disabled.
@@ -293,6 +293,7 @@ Traces
293293
v1.7.0: The ``b3multi`` propagation style was added and ``b3`` was deprecated in favor it.
294294
v1.7.0: Added support for ``tracecontext`` W3C headers. Changed the default value to ``DD_TRACE_PROPAGATION_STYLE="tracecontext,datadog"``.
295295
v2.6.0: Updated default value to ``datadog,tracecontext``.
296+
v2.16.0: Updated default value to ``datadog,tracecontex,baggage``.
296297

297298
DD_TRACE_SPAN_TRACEBACK_MAX_SIZE:
298299
type: Integer

tests/contrib/aws_lambda/test_aws_lambda.py

+14-24
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import contextlib
2+
13
import pytest
24

35
from ddtrace.contrib.internal.aws_lambda.patch import patch
@@ -11,7 +13,6 @@
1113
from tests.contrib.aws_lambda.handlers import manually_wrapped_handler
1214
from tests.contrib.aws_lambda.handlers import static_handler
1315
from tests.contrib.aws_lambda.handlers import timeout_handler
14-
from tests.utils import flaky
1516
from tests.utils import override_env
1617

1718

@@ -46,13 +47,15 @@ def get_env(env=None):
4647
return {**common_env, **env}
4748

4849

49-
@pytest.fixture(autouse=True)
50-
def setup():
51-
yield
52-
unpatch()
50+
@contextlib.contextmanager
51+
def override_env_and_patch(env):
52+
# patching and unpatching must be done while the environment is set
53+
with override_env(env):
54+
patch()
55+
yield
56+
unpatch()
5357

5458

55-
@flaky(1744053478)
5659
@pytest.mark.parametrize("customApmFlushDeadline", [("-100"), ("10"), ("100"), ("200")])
5760
@pytest.mark.snapshot
5861
def test_timeout_traces(context, customApmFlushDeadline):
@@ -64,9 +67,7 @@ def test_timeout_traces(context, customApmFlushDeadline):
6467
}
6568
)
6669

67-
with override_env(env):
68-
patch()
69-
70+
with override_env_and_patch(env):
7071
datadog(timeout_handler)({}, context())
7172

7273

@@ -83,9 +84,7 @@ def test_continue_on_early_trace_ending(context):
8384
}
8485
)
8586

86-
with override_env(env):
87-
patch()
88-
87+
with override_env_and_patch(env):
8988
datadog(finishing_spans_early_handler)({}, context())
9089

9190

@@ -98,11 +97,8 @@ async def test_file_patching(context):
9897
}
9998
)
10099

101-
with override_env(env):
102-
patch()
103-
100+
with override_env_and_patch(env):
104101
result = datadog(handler)({}, context())
105-
106102
assert result == {"success": True}
107103

108104

@@ -117,11 +113,8 @@ async def test_module_patching(mocker, context):
117113
}
118114
)
119115

120-
with override_env(env):
121-
patch()
122-
116+
with override_env_and_patch(env):
123117
result = manually_wrapped_handler({}, context())
124-
125118
assert result == {"success": True}
126119

127120

@@ -135,7 +128,6 @@ async def test_module_patching(mocker, context):
135128
],
136129
)
137130
@pytest.mark.snapshot
138-
@flaky(1744053478, reason="Did not receive expected traces: 'aws.lambda' for [handler3-instance_handler_with_code]")
139131
def test_class_based_handlers(context, handler, function_name):
140132
env = get_env(
141133
{
@@ -144,8 +136,6 @@ def test_class_based_handlers(context, handler, function_name):
144136
}
145137
)
146138

147-
with override_env(env):
148-
patch()
149-
139+
with override_env_and_patch(env):
150140
result = datadog(handler)({}, context())
151141
assert result == {"success": True}

0 commit comments

Comments
 (0)