Skip to content

Commit 5bdc811

Browse files
authored
Merge branch '2.18' into backport-11759-to-2.18
2 parents 15a89f5 + c0bb6bd commit 5bdc811

26 files changed

+515
-118
lines changed

ddtrace/contrib/internal/asgi/middleware.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,18 @@ async def _blocked_asgi_app(scope, receive, send):
9191
await send({"type": "http.response.body", "body": b""})
9292

9393

94+
def _parse_response_cookies(response_headers):
95+
cookies = {}
96+
try:
97+
result = response_headers.get("set-cookie", "").split("=", maxsplit=1)
98+
if len(result) == 2:
99+
cookie_key, cookie_value = result
100+
cookies[cookie_key] = cookie_value
101+
except Exception:
102+
log.debug("failed to extract response cookies", exc_info=True)
103+
return cookies
104+
105+
94106
class TraceMiddleware:
95107
"""
96108
ASGI application middleware that traces the requests.
@@ -211,7 +223,6 @@ async def __call__(self, scope, receive, send):
211223
peer_ip = client[0]
212224
else:
213225
peer_ip = None
214-
215226
trace_utils.set_http_meta(
216227
span,
217228
self.integration_config,
@@ -234,15 +245,8 @@ async def wrapped_send(message):
234245
except Exception:
235246
log.warning("failed to extract response headers", exc_info=True)
236247
response_headers = None
237-
238248
if span and message.get("type") == "http.response.start" and "status" in message:
239-
cookies = {}
240-
try:
241-
cookie_key, cookie_value = response_headers.get("set-cookie", "").split("=", maxsplit=1)
242-
cookies[cookie_key] = cookie_value
243-
except Exception:
244-
log.debug("failed to extract response cookies", exc_info=True)
245-
249+
cookies = _parse_response_cookies(response_headers)
246250
status_code = message["status"]
247251
trace_utils.set_http_meta(
248252
span,

ddtrace/contrib/internal/celery/app.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,6 @@ def _traced_apply_async_inner(func, instance, args, kwargs):
133133
if task_span:
134134
task_span.set_exc_info(*sys.exc_info())
135135

136-
prerun_span = core.get_item("prerun_span")
137-
if prerun_span:
138-
prerun_span.set_exc_info(*sys.exc_info())
139-
140136
raise
141137
finally:
142138
task_span = core.get_item("task_span")
@@ -147,11 +143,4 @@ def _traced_apply_async_inner(func, instance, args, kwargs):
147143
)
148144
task_span.finish()
149145

150-
prerun_span = core.get_item("prerun_span")
151-
if prerun_span:
152-
log.debug(
153-
"The task_postrun signal was not called, so manually closing span: %s", prerun_span._pprint()
154-
)
155-
prerun_span.finish()
156-
157146
return _traced_apply_async_inner

ddtrace/contrib/internal/celery/signals.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,6 @@ def trace_prerun(*args, **kwargs):
5454
service = config.celery["worker_service_name"]
5555
span = pin.tracer.trace(c.WORKER_ROOT_SPAN, service=service, resource=task.name, span_type=SpanTypes.WORKER)
5656

57-
# Store an item called "prerun span" in case task_postrun doesn't get called
58-
core.set_item("prerun_span", span)
59-
6057
# set span.kind to the type of request being performed
6158
span.set_tag_str(SPAN_KIND, SpanKind.CONSUMER)
6259

ddtrace/internal/datadog/profiling/dd_wrapper/include/uploader_builder.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ class UploaderBuilder
4343
static void set_output_filename(std::string_view _output_filename);
4444

4545
static std::variant<Uploader, std::string> build();
46+
47+
static void postfork_child();
4648
};
4749

4850
} // namespace Datadog

ddtrace/internal/datadog/profiling/dd_wrapper/src/code_provenance.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ namespace Datadog {
1414
void
1515
Datadog::CodeProvenance::postfork_child()
1616
{
17-
get_instance().mtx.~mutex(); // Destroy the mutex
17+
// NB placement-new to re-init and leak the mutex because doing anything else is UB
1818
new (&get_instance().mtx) std::mutex(); // Recreate the mutex
19-
get_instance().reset(); // Reset the state
2019
}
2120

2221
void

ddtrace/internal/datadog/profiling/dd_wrapper/src/ddup_interface.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ ddup_postfork_child()
2424
Datadog::Uploader::postfork_child();
2525
Datadog::SampleManager::postfork_child();
2626
Datadog::CodeProvenance::postfork_child();
27+
Datadog::UploaderBuilder::postfork_child();
2728
}
2829

2930
void

ddtrace/internal/datadog/profiling/dd_wrapper/src/profile.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,6 @@ Datadog::Profile::collect(const ddog_prof_Sample& sample, int64_t endtime_ns)
186186
void
187187
Datadog::Profile::postfork_child()
188188
{
189-
profile_mtx.unlock();
189+
new (&profile_mtx) std::mutex();
190190
cycle_buffers();
191191
}

ddtrace/internal/datadog/profiling/dd_wrapper/src/uploader.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,5 +175,6 @@ Datadog::Uploader::postfork_parent()
175175
void
176176
Datadog::Uploader::postfork_child()
177177
{
178-
unlock();
178+
// NB placement-new to re-init and leak the mutex because doing anything else is UB
179+
new (&upload_lock) std::mutex();
179180
}

ddtrace/internal/datadog/profiling/dd_wrapper/src/uploader_builder.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,3 +186,10 @@ Datadog::UploaderBuilder::build()
186186

187187
return Datadog::Uploader{ output_filename, ddog_exporter };
188188
}
189+
190+
void
191+
Datadog::UploaderBuilder::postfork_child()
192+
{
193+
// NB placement-new to re-init and leak the mutex because doing anything else is UB
194+
new (&tag_mutex) std::mutex();
195+
}

ddtrace/internal/datadog/profiling/stack_v2/src/sampler.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ _stack_v2_atfork_child()
6767
// so we don't even reveal this function to the user
6868
_set_pid(getpid());
6969
ThreadSpanLinks::postfork_child();
70+
71+
// `thread_info_map_lock` and `task_link_map_lock` are global locks held in echion
72+
// NB placement-new to re-init and leak the mutex because doing anything else is UB
73+
new (&thread_info_map_lock) std::mutex;
74+
new (&task_link_map_lock) std::mutex;
7075
}
7176

7277
__attribute__((constructor)) void

0 commit comments

Comments
 (0)