From 2286068853204ddd4262ab904ade5fe8cd125094 Mon Sep 17 00:00:00 2001 From: quinna-h Date: Wed, 23 Oct 2024 12:45:44 -0400 Subject: [PATCH 01/10] add pin check --- ddtrace/contrib/internal/pymongo/client.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ddtrace/contrib/internal/pymongo/client.py b/ddtrace/contrib/internal/pymongo/client.py index cb7466ac7a8..d5b2530d1f7 100644 --- a/ddtrace/contrib/internal/pymongo/client.py +++ b/ddtrace/contrib/internal/pymongo/client.py @@ -103,7 +103,10 @@ def _trace_topology_select_server(func, args, kwargs): # Ensure the pin used on the traced mongo client is passed down to the topology instance # This allows us to pass the same pin in traced server objects. topology_instance = get_argument_value(args, kwargs, 0, "self") - ddtrace.Pin.get_from(topology_instance).onto(server) + pin = ddtrace.Pin.get_from(topology_instance) + + if pin is not None: + pin.onto(server) return server From 5b6e672bd573d84d92b899e1156d9b7dcd442ac7 Mon Sep 17 00:00:00 2001 From: quinna-h Date: Fri, 25 Oct 2024 11:12:07 -0400 Subject: [PATCH 02/10] add release note --- releasenotes/notes/pymongo-check-pin-c3cb9d1fbdc82fb3.yaml | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 releasenotes/notes/pymongo-check-pin-c3cb9d1fbdc82fb3.yaml diff --git a/releasenotes/notes/pymongo-check-pin-c3cb9d1fbdc82fb3.yaml b/releasenotes/notes/pymongo-check-pin-c3cb9d1fbdc82fb3.yaml new file mode 100644 index 00000000000..aae2cff00b4 --- /dev/null +++ b/releasenotes/notes/pymongo-check-pin-c3cb9d1fbdc82fb3.yaml @@ -0,0 +1,4 @@ +--- +fixes: + - | + pymongo: add type checking to solve an issue where `NoneType` instead of expected `Pin` object would throw an error in `TracedTopology` method. From 83cb251be77a975210672264d9bbc9d403bb5aa7 Mon Sep 17 00:00:00 2001 From: Quinna Halim Date: Mon, 28 Oct 2024 13:48:42 -0400 Subject: [PATCH 03/10] Update releasenotes/notes/pymongo-check-pin-c3cb9d1fbdc82fb3.yaml Co-authored-by: Emmett Butler <723615+emmettbutler@users.noreply.github.com> --- releasenotes/notes/pymongo-check-pin-c3cb9d1fbdc82fb3.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/releasenotes/notes/pymongo-check-pin-c3cb9d1fbdc82fb3.yaml b/releasenotes/notes/pymongo-check-pin-c3cb9d1fbdc82fb3.yaml index aae2cff00b4..1f1ad12a669 100644 --- a/releasenotes/notes/pymongo-check-pin-c3cb9d1fbdc82fb3.yaml +++ b/releasenotes/notes/pymongo-check-pin-c3cb9d1fbdc82fb3.yaml @@ -1,4 +1,4 @@ --- fixes: - | - pymongo: add type checking to solve an issue where `NoneType` instead of expected `Pin` object would throw an error in `TracedTopology` method. + pymongo: add type checking to solve an issue where ``NoneType`` instead of expected ``Pin`` object would throw an error in ``TracedTopology`` method. From 4dee5d2ff1b6fe3285da5c6d9d6b7703be4b98dd Mon Sep 17 00:00:00 2001 From: quinna-h Date: Tue, 29 Oct 2024 10:37:22 -0400 Subject: [PATCH 04/10] test increase delay in django server --- tests/contrib/django/test_django_snapshots.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/contrib/django/test_django_snapshots.py b/tests/contrib/django/test_django_snapshots.py index feaead253d8..a9b27ad0694 100644 --- a/tests/contrib/django/test_django_snapshots.py +++ b/tests/contrib/django/test_django_snapshots.py @@ -66,7 +66,7 @@ def daphne_client(django_asgi, additional_env=None): # Wait for the server to start up try: print("Waiting for server to start") - client.wait(max_tries=120, delay=0.2, initial_wait=2.0) + client.wait(max_tries=120, delay=1.0, initial_wait=2.0) print("Server started") except Exception: raise AssertionError( From 0ca7d495e703fe5afc4ad37b9f6d9d9a53587ff6 Mon Sep 17 00:00:00 2001 From: quinna-h Date: Tue, 29 Oct 2024 10:38:59 -0400 Subject: [PATCH 05/10] test change client wait time back to default --- tests/contrib/django/test_django_snapshots.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/contrib/django/test_django_snapshots.py b/tests/contrib/django/test_django_snapshots.py index a9b27ad0694..6e967910cfe 100644 --- a/tests/contrib/django/test_django_snapshots.py +++ b/tests/contrib/django/test_django_snapshots.py @@ -66,7 +66,7 @@ def daphne_client(django_asgi, additional_env=None): # Wait for the server to start up try: print("Waiting for server to start") - client.wait(max_tries=120, delay=1.0, initial_wait=2.0) + client.wait() print("Server started") except Exception: raise AssertionError( From 337d908917a9ed0cbe205f3a112dcaf33c1d5cc4 Mon Sep 17 00:00:00 2001 From: quinna-h Date: Tue, 29 Oct 2024 11:57:10 -0400 Subject: [PATCH 06/10] increase initial wait for django server --- tests/contrib/django/test_django_snapshots.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/contrib/django/test_django_snapshots.py b/tests/contrib/django/test_django_snapshots.py index 6e967910cfe..db9a642373f 100644 --- a/tests/contrib/django/test_django_snapshots.py +++ b/tests/contrib/django/test_django_snapshots.py @@ -66,7 +66,7 @@ def daphne_client(django_asgi, additional_env=None): # Wait for the server to start up try: print("Waiting for server to start") - client.wait() + client.wait(max_tries=120, delay=0.2, initial_wait=5) print("Server started") except Exception: raise AssertionError( From ccc24fa7c60667a164261e3a79a3516575fac7d3 Mon Sep 17 00:00:00 2001 From: quinna-h Date: Tue, 29 Oct 2024 12:16:29 -0400 Subject: [PATCH 07/10] add log warning --- tests/contrib/django/test_django_snapshots.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/contrib/django/test_django_snapshots.py b/tests/contrib/django/test_django_snapshots.py index db9a642373f..1d4e5a1d523 100644 --- a/tests/contrib/django/test_django_snapshots.py +++ b/tests/contrib/django/test_django_snapshots.py @@ -6,6 +6,7 @@ import django import pytest +import logging from tests.utils import _build_env from tests.utils import flaky @@ -68,7 +69,8 @@ def daphne_client(django_asgi, additional_env=None): print("Waiting for server to start") client.wait(max_tries=120, delay=0.2, initial_wait=5) print("Server started") - except Exception: + except Exception as e: + logging.warning(f"Exception: {e}") raise AssertionError( "Server failed to start, see stdout and stderr logs" "\n=== Captured STDOUT ===\n%s=== End of captured STDOUT ===" From ecd02c00275440e49e923c58630dbd0ececd5521 Mon Sep 17 00:00:00 2001 From: quinna-h Date: Tue, 29 Oct 2024 12:25:53 -0400 Subject: [PATCH 08/10] make linter happy --- tests/contrib/django/test_django_snapshots.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/contrib/django/test_django_snapshots.py b/tests/contrib/django/test_django_snapshots.py index 1d4e5a1d523..2263dca1b2b 100644 --- a/tests/contrib/django/test_django_snapshots.py +++ b/tests/contrib/django/test_django_snapshots.py @@ -1,4 +1,5 @@ from contextlib import contextmanager +import logging import os from pathlib import Path import subprocess @@ -6,7 +7,6 @@ import django import pytest -import logging from tests.utils import _build_env from tests.utils import flaky @@ -67,10 +67,10 @@ def daphne_client(django_asgi, additional_env=None): # Wait for the server to start up try: print("Waiting for server to start") - client.wait(max_tries=120, delay=0.2, initial_wait=5) + client.wait(max_tries=130, delay=0.2, initial_wait=5) print("Server started") except Exception as e: - logging.warning(f"Exception: {e}") + logging.warning(e) raise AssertionError( "Server failed to start, see stdout and stderr logs" "\n=== Captured STDOUT ===\n%s=== End of captured STDOUT ===" From d9ceb90dc4451192586a0ef0ad284730f03aeeef Mon Sep 17 00:00:00 2001 From: quinna-h Date: Tue, 29 Oct 2024 16:40:36 -0400 Subject: [PATCH 09/10] more testing timeout --- tests/contrib/django/test_django_snapshots.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/contrib/django/test_django_snapshots.py b/tests/contrib/django/test_django_snapshots.py index 2263dca1b2b..5e8a684b461 100644 --- a/tests/contrib/django/test_django_snapshots.py +++ b/tests/contrib/django/test_django_snapshots.py @@ -67,7 +67,7 @@ def daphne_client(django_asgi, additional_env=None): # Wait for the server to start up try: print("Waiting for server to start") - client.wait(max_tries=130, delay=0.2, initial_wait=5) + client.wait(max_tries=120, delay=0.2, initial_wait=2.0) print("Server started") except Exception as e: logging.warning(e) @@ -94,7 +94,7 @@ def test_urlpatterns_include(client): When a view is specified using `django.urls.include` The view is traced """ - assert client.get("/include/test/", timeout=5).status_code == 200 + assert client.get("/include/test/").status_code == 200 @snapshot( @@ -259,7 +259,7 @@ def test_psycopg3_query_default(client, snapshot_context, psycopg3_patched): @pytest.mark.parametrize("django_asgi", ["application", "channels_application"]) def test_asgi_200(django_asgi): with daphne_client(django_asgi) as (client, _): - resp = client.get("/", timeout=10) + resp = client.get("/") assert resp.status_code == 200 assert resp.content == b"Hello, test app." @@ -280,7 +280,7 @@ def test_asgi_200_simple_app(): @snapshot(ignores=SNAPSHOT_IGNORES + ["meta.http.useragent"]) def test_asgi_200_traced_simple_app(): with daphne_client("channels_application") as (client, _): - resp = client.get("/traced-simple-asgi-app/", timeout=10) + resp = client.get("/traced-simple-asgi-app/") assert resp.status_code == 200 assert resp.content == b"Hello World. It's me simple asgi app" @@ -308,7 +308,7 @@ def test_asgi_500(): def test_templates_enabled(): """Default behavior to compare with disabled variant""" with daphne_client("application") as (client, _): - resp = client.get("/template-view/", timeout=10) + resp = client.get("/template-view/") assert resp.status_code == 200 assert resp.content == b"some content\n" @@ -323,7 +323,7 @@ def test_templates_enabled(): def test_templates_disabled(): """Template instrumentation disabled""" with daphne_client("application", additional_env={"DD_DJANGO_INSTRUMENT_TEMPLATES": "false"}) as (client, _): - resp = client.get("/template-view/", timeout=10) + resp = client.get("/template-view/") assert resp.status_code == 200 assert resp.content == b"some content\n" From fddd901d8ec002ea329828707f5d661799c229c7 Mon Sep 17 00:00:00 2001 From: quinna-h Date: Wed, 30 Oct 2024 09:20:57 -0400 Subject: [PATCH 10/10] revert django snapshot --- tests/contrib/django/test_django_snapshots.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/tests/contrib/django/test_django_snapshots.py b/tests/contrib/django/test_django_snapshots.py index 5e8a684b461..feaead253d8 100644 --- a/tests/contrib/django/test_django_snapshots.py +++ b/tests/contrib/django/test_django_snapshots.py @@ -1,5 +1,4 @@ from contextlib import contextmanager -import logging import os from pathlib import Path import subprocess @@ -69,8 +68,7 @@ def daphne_client(django_asgi, additional_env=None): print("Waiting for server to start") client.wait(max_tries=120, delay=0.2, initial_wait=2.0) print("Server started") - except Exception as e: - logging.warning(e) + except Exception: raise AssertionError( "Server failed to start, see stdout and stderr logs" "\n=== Captured STDOUT ===\n%s=== End of captured STDOUT ===" @@ -94,7 +92,7 @@ def test_urlpatterns_include(client): When a view is specified using `django.urls.include` The view is traced """ - assert client.get("/include/test/").status_code == 200 + assert client.get("/include/test/", timeout=5).status_code == 200 @snapshot( @@ -259,7 +257,7 @@ def test_psycopg3_query_default(client, snapshot_context, psycopg3_patched): @pytest.mark.parametrize("django_asgi", ["application", "channels_application"]) def test_asgi_200(django_asgi): with daphne_client(django_asgi) as (client, _): - resp = client.get("/") + resp = client.get("/", timeout=10) assert resp.status_code == 200 assert resp.content == b"Hello, test app." @@ -280,7 +278,7 @@ def test_asgi_200_simple_app(): @snapshot(ignores=SNAPSHOT_IGNORES + ["meta.http.useragent"]) def test_asgi_200_traced_simple_app(): with daphne_client("channels_application") as (client, _): - resp = client.get("/traced-simple-asgi-app/") + resp = client.get("/traced-simple-asgi-app/", timeout=10) assert resp.status_code == 200 assert resp.content == b"Hello World. It's me simple asgi app" @@ -308,7 +306,7 @@ def test_asgi_500(): def test_templates_enabled(): """Default behavior to compare with disabled variant""" with daphne_client("application") as (client, _): - resp = client.get("/template-view/") + resp = client.get("/template-view/", timeout=10) assert resp.status_code == 200 assert resp.content == b"some content\n" @@ -323,7 +321,7 @@ def test_templates_enabled(): def test_templates_disabled(): """Template instrumentation disabled""" with daphne_client("application", additional_env={"DD_DJANGO_INSTRUMENT_TEMPLATES": "false"}) as (client, _): - resp = client.get("/template-view/") + resp = client.get("/template-view/", timeout=10) assert resp.status_code == 200 assert resp.content == b"some content\n"