Skip to content

Commit

Permalink
fix(tracer): fix multiprocessing queue on aws lambda (#7612)
Browse files Browse the repository at this point in the history
#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 <zach.groves@datadoghq.com>
  • Loading branch information
3 people committed Nov 20, 2023
1 parent 0cfc263 commit 1656e7d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
14 changes: 10 additions & 4 deletions ddtrace/settings/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
fixes:
- |
lambda: This change disables the use of ``multiprocessing.queue`` in Lambda, because it is not supported in Lambda

0 comments on commit 1656e7d

Please sign in to comment.