Skip to content

Commit 788c4f0

Browse files
authored
Merge branch 'main' into chris.agocs/patch_botocore_stepfunctions
2 parents facabb7 + 2bd8e73 commit 788c4f0

40 files changed

+822
-418
lines changed

.gitlab/benchmarks.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ benchmark-set-http-meta:
6969
variables:
7070
SCENARIO: "set_http_meta"
7171

72+
benchmark-django-simple:
73+
extends: .benchmarks
74+
timeout: 1h 30m
75+
variables:
76+
SCENARIO: "django_simple"
77+
7278
benchmark-flask-simple:
7379
extends: .benchmarks
7480
timeout: 1h 30m
@@ -94,3 +100,18 @@ appsec-iast-propagation:
94100
extends: .benchmarks
95101
variables:
96102
SCENARIO: "appsec_iast_propagation"
103+
104+
benchmark-encoder:
105+
extends: .benchmarks
106+
variables:
107+
SCENARIO: "encoder"
108+
109+
benchmark-http-propagation-extract:
110+
extends: .benchmarks
111+
variables:
112+
SCENARIO: "http_propagation_extract"
113+
114+
benchmark-http-propagation-inject:
115+
extends: .benchmarks
116+
variables:
117+
SCENARIO: "http_propagation_inject"

benchmarks/base/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ pyperf
44
pyyaml
55
attrs
66
httpretty==1.1.4
7+
tenacity==8.0.0

benchmarks/core_api/config.yaml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,75 @@
11
core_dispatch_no_listeners:
22
listeners: 0
3+
all_listeners: 0
34
set_item_count: 0
45
get_item_exists: false
56
core_dispatch_listeners:
67
listeners: 10
8+
all_listeners: 0
9+
set_item_count: 0
10+
get_item_exists: false
11+
core_dispatch_listeners_and_all_listeners:
12+
listeners: 10
13+
all_listeners: 10
14+
set_item_count: 0
15+
get_item_exists: false
16+
core_dispatch_only_all_listeners:
17+
listeners: 0
18+
all_listeners: 10
19+
set_item_count: 0
20+
get_item_exists: false
21+
core_dispatch_with_results_no_listeners:
22+
listeners: 0
23+
all_listeners: 0
24+
set_item_count: 0
25+
get_item_exists: false
26+
core_dispatch_with_results_listeners:
27+
listeners: 10
28+
all_listeners: 0
29+
set_item_count: 0
30+
get_item_exists: false
31+
core_dispatch_with_results_listeners_and_all_listeners:
32+
listeners: 10
33+
all_listeners: 10
34+
set_item_count: 0
35+
get_item_exists: false
36+
core_dispatch_with_results_only_all_listeners:
37+
listeners: 0
38+
all_listeners: 10
739
set_item_count: 0
840
get_item_exists: false
941
context_with_data_no_listeners:
1042
listeners: 0
43+
all_listeners: 0
1144
set_item_count: 0
1245
get_item_exists: false
1346
context_with_data_listeners:
1447
listeners: 10
48+
all_listeners: 0
49+
set_item_count: 0
50+
get_item_exists: false
51+
context_with_data_listeners_and_all_listeners:
52+
listeners: 10
53+
all_listeners: 10
54+
set_item_count: 0
55+
get_item_exists: false
56+
context_with_data_only_all_listeners:
57+
listeners: 10
58+
all_listeners: 0
1559
set_item_count: 0
1660
get_item_exists: false
1761
set_item:
1862
listeners: 0
63+
all_listeners: 0
1964
set_item_count: 100
2065
get_item_exists: false
2166
get_item_missing:
2267
listeners: 0
68+
all_listeners: 0
2369
set_item_count: 0
2470
get_item_exists: false
2571
get_item_exists:
2672
listeners: 0
73+
all_listeners: 0
2774
set_item_count: 0
2875
get_item_exists: true

benchmarks/core_api/scenario.py

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,47 @@
33
from ddtrace.internal import core
44

55

6+
if not hasattr(core, "dispatch_with_results"):
7+
core.dispatch_with_results = core.dispatch
8+
9+
610
class CoreAPIScenario(bm.Scenario):
711
CUSTOM_EVENT_NAME = "CoreAPIScenario.event"
812

913
listeners = bm.var(type=int, default=0)
14+
all_listeners = bm.var(type=int, default=0)
1015
set_item_count = bm.var(type=int, default=100)
1116
get_item_exists = bm.var_bool(default=False)
1217

1318
def run(self):
1419
# Activate a number of no-op listeners for known events
1520
for _ in range(self.listeners):
1621

17-
def listener(_):
22+
def listener(*_):
1823
pass
1924

2025
core.on(self.CUSTOM_EVENT_NAME, listener)
2126
core.on("context.started.with_data", listener)
2227
core.on("context.ended.with_data", listener)
2328

29+
for _ in range(self.all_listeners):
30+
if hasattr(core, "on_all"):
31+
32+
def all_listener(event_id, args):
33+
pass
34+
35+
core.on_all(all_listener)
36+
else:
37+
38+
def listener(*_):
39+
pass
40+
41+
# If we don't support "core.on_all", just double up the registered listeners to try
42+
# and make the comparison semi-equal
43+
core.on(self.CUSTOM_EVENT_NAME, listener)
44+
core.on("context.started.with_data", listener)
45+
core.on("context.ended.with_data", listener)
46+
2447
if self.get_item_exists:
2548
core.set_item("key", "value")
2649

@@ -29,6 +52,11 @@ def core_dispatch(loops):
2952
for _ in range(loops):
3053
core.dispatch(self.CUSTOM_EVENT_NAME, (5, 6, 7, 8))
3154

55+
def core_dispatch_with_results(loops):
56+
"""Measure the cost to dispatch an event on the hub"""
57+
for _ in range(loops):
58+
core.dispatch_with_results(self.CUSTOM_EVENT_NAME, (5, 6, 7, 8))
59+
3260
def context_with_data(loops):
3361
"""Measure the cost of creating and ending a new context"""
3462
for _ in range(loops):
@@ -48,7 +76,9 @@ def get_item(loops):
4876
for _ in range(loops):
4977
core.get_item("key")
5078

51-
if "core_dispatch" in self.scenario_name:
79+
if "core_dispatch_with_results" in self.scenario_name:
80+
yield core_dispatch_with_results
81+
elif "core_dispatch" in self.scenario_name:
5282
yield core_dispatch
5383
elif "context_with_data" in self.scenario_name:
5484
yield context_with_data
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
flask==3.0.0
22
gunicorn==20.1.0
33
requests==2.31.0
4-
tenacity==8.0.0
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
flask==3.0.0
22
gunicorn==20.1.0
33
requests==2.31.0
4-
tenacity==8.0.0

benchmarks/sampling_rule_matches/scenario.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,11 @@ def run(self):
3838
tag_names = [rands() for _ in range(self.num_tags)]
3939

4040
# Generate all possible permutations of service and operation names
41-
spans = [
42-
Span(service=service, name=name, resource=resource, tags={tag: tag})
43-
for service, name, resource, tag in itertools.product(services, operation_names, resource_names, tag_names)
44-
]
41+
spans = []
42+
for service, name, resource, tag in itertools.product(services, operation_names, resource_names, tag_names):
43+
span = Span(service=service, name=name, resource=resource)
44+
span.set_tag(tag, tag)
45+
spans.append(span)
4546

4647
# Create a single rule to use for all matches
4748
# Pick a random service/operation name

ddtrace/__init__.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import sys
22

3-
43
LOADED_MODULES = frozenset(sys.modules.keys())
54

65
from ddtrace.internal.module import ModuleWatchdog
76

8-
97
ModuleWatchdog.install()
108

119
# Acquire a reference to the threading module. Some parts of the library (e.g.
@@ -21,15 +19,17 @@
2119
# configure ddtrace logger before other modules log
2220
configure_ddtrace_logger() # noqa: E402
2321

24-
from ddtrace.internal import telemetry
22+
from .settings import _config as config
2523

24+
if config._telemetry_enabled:
25+
from ddtrace.internal import telemetry
2626

27-
telemetry.install_excepthook()
28-
# In order to support 3.12, we start the writer upon initialization.
29-
# See https://github.com/python/cpython/pull/104826.
30-
# Telemetry events will only be sent after the `app-started` is queued.
31-
# This will occur when the agent writer starts.
32-
telemetry.telemetry_writer.enable()
27+
telemetry.install_excepthook()
28+
# In order to support 3.12, we start the writer upon initialization.
29+
# See https://github.com/python/cpython/pull/104826.
30+
# Telemetry events will only be sent after the `app-started` is queued.
31+
# This will occur when the agent writer starts.
32+
telemetry.telemetry_writer.enable()
3333

3434
from ._monkey import patch # noqa: E402
3535
from ._monkey import patch_all # noqa: E402

ddtrace/contrib/asgi/middleware.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ async def __call__(self, scope, receive, send):
194194
if not self.integration_config.trace_query_string:
195195
query_string = None
196196
body = None
197-
parse_body_result = core.dispatch("asgi.request.parse.body", receive, headers)[0]
197+
parse_body_result = core.dispatch_with_results("asgi.request.parse.body", (receive, headers))[0]
198198
if len(parse_body_result) == 1:
199199
receive, body = await parse_body_result[0]
200200

@@ -232,7 +232,7 @@ async def wrapped_send(message):
232232
trace_utils.set_http_meta(
233233
span, self.integration_config, status_code=status_code, response_headers=response_headers
234234
)
235-
core.dispatch("asgi.start_response", "asgi")
235+
core.dispatch("asgi.start_response", ("asgi",))
236236

237237
if core.get_item(HTTP_REQUEST_BLOCKED):
238238
raise trace_utils.InterruptException("wrapped_send")
@@ -252,7 +252,7 @@ async def wrapped_send(message):
252252
span.finish()
253253

254254
async def wrapped_blocked_send(message):
255-
status, headers, content = core.dispatch("asgi.block.started", ctx, url)[0][0]
255+
status, headers, content = core.dispatch_with_results("asgi.block.started", (ctx, url))[0][0]
256256
if span and message.get("type") == "http.response.start":
257257
message["headers"] = headers
258258
message["status"] = int(status)
@@ -269,7 +269,7 @@ async def wrapped_blocked_send(message):
269269
span.finish()
270270

271271
try:
272-
core.dispatch("asgi.start_request", "asgi")
272+
core.dispatch("asgi.start_request", ("asgi",))
273273
if core.get_item(HTTP_REQUEST_BLOCKED):
274274
return await _blocked_asgi_app(scope, receive, wrapped_blocked_send)
275275
return await self.app(scope, receive, wrapped_send)

0 commit comments

Comments
 (0)