From 1656e7d4f523e500370f358b00002e579ee1a951 Mon Sep 17 00:00:00 2001 From: Christophe Papazian <114495376+christophe-papazian@users.noreply.github.com> Date: Mon, 20 Nov 2023 22:22:27 +0100 Subject: [PATCH] fix(tracer): fix multiprocessing queue on aws lambda (#7612) https://github.com/DataDog/dd-trace-py/pull/6929 introduced a bug as multiprocessing.Queue is not supported on AWS lambda platform. This fix prevents the use of the Queue on aws lambda, as this is used for a RC only feature, and lambda does not use RC. ## Checklist - [x] Change(s) are motivated and described in the PR description. - [x] Testing strategy is described if automated tests are not included in the PR. - [x] Risk is outlined (performance impact, potential for breakage, maintainability, etc). - [x] Change is maintainable (easy to change, telemetry, documentation). - [x] [Library release note guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html) are followed. If no release note is required, add label `changelog/no-changelog`. - [x] Documentation is included (in-code, generated user docs, [public corp docs](https://github.com/DataDog/documentation/)). - [x] Backport labels are set (if [applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)) ## Reviewer Checklist - [x] Title is accurate. - [x] No unnecessary changes are introduced. - [x] Description motivates each change. - [x] Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes unless absolutely necessary. - [x] Testing strategy adequately addresses listed risk(s). - [x] Change is maintainable (easy to change, telemetry, documentation). - [x] Release note makes sense to a user of the library. - [x] Reviewer has explicitly acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment. - [x] Backport labels are set in a manner that is consistent with the [release branch maintenance policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting) - [x] If this PR touches code that signs or publishes builds or packages, or handles credentials of any kind, I've requested a review from `@DataDog/security-design-and-guidance`. - [x] This PR doesn't touch any of that. --------- Co-authored-by: Zachary Groves <32471391+ZStriker19@users.noreply.github.com> Co-authored-by: ZStriker19 --- ddtrace/settings/config.py | 14 ++++++++++---- ...ssing-queue-in-aws-lambda-99fd75820125906f.yaml | 4 ++++ 2 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 scripts/releasenotes/notes/do-not-use-multiprocessing-queue-in-aws-lambda-99fd75820125906f.yaml diff --git a/ddtrace/settings/config.py b/ddtrace/settings/config.py index f5a952f0a2..50f896bf11 100644 --- a/ddtrace/settings/config.py +++ b/ddtrace/settings/config.py @@ -28,6 +28,7 @@ from ..internal.constants import PROPAGATION_STYLE_B3_SINGLE from ..internal.logger import get_logger from ..internal.schema import DEFAULT_SPAN_SERVICE_NAME +from ..internal.serverless import in_aws_lambda from ..internal.utils.formats import asbool from ..internal.utils.formats import parse_tags_str from ..pin import Pin @@ -264,9 +265,11 @@ class Config(object): available and can be updated by users. """ - _extra_services_queue = multiprocessing.get_context("fork" if sys.platform != "win32" else "spawn").Queue( - 512 - ) # type: multiprocessing.Queue + _extra_services_queue = ( + None + if in_aws_lambda() + else multiprocessing.get_context("fork" if sys.platform != "win32" else "spawn").Queue(512) + ) # type: multiprocessing.Queue | None class _HTTPServerConfig(object): _error_statuses = "500-599" # type: str @@ -490,6 +493,8 @@ def __getattr__(self, name): return self._integration_configs[name] def _add_extra_service(self, service_name: str) -> None: + if self._extra_services_queue is None: + return if self._remote_config_enabled and service_name != self.service: try: self._extra_services_queue.put_nowait(service_name) @@ -498,7 +503,8 @@ def _add_extra_service(self, service_name: str) -> None: def _get_extra_services(self): # type: () -> set[str] - + if self._extra_services_queue is None: + return set() try: while True: self._extra_services.add(self._extra_services_queue.get(timeout=0.002)) diff --git a/scripts/releasenotes/notes/do-not-use-multiprocessing-queue-in-aws-lambda-99fd75820125906f.yaml b/scripts/releasenotes/notes/do-not-use-multiprocessing-queue-in-aws-lambda-99fd75820125906f.yaml new file mode 100644 index 0000000000..cc5b3891e6 --- /dev/null +++ b/scripts/releasenotes/notes/do-not-use-multiprocessing-queue-in-aws-lambda-99fd75820125906f.yaml @@ -0,0 +1,4 @@ +--- +fixes: + - | + lambda: This change disables the use of ``multiprocessing.queue`` in Lambda, because it is not supported in Lambda