From c41534c5f4726e757b55d76f913860857ba5426f Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Tue, 25 Apr 2023 15:59:14 +0200 Subject: [PATCH 1/9] Add the to the span data. --- sentry_sdk/integrations/pymongo.py | 1 + 1 file changed, 1 insertion(+) diff --git a/sentry_sdk/integrations/pymongo.py b/sentry_sdk/integrations/pymongo.py index 0a94d46813..a4db4a1d84 100644 --- a/sentry_sdk/integrations/pymongo.py +++ b/sentry_sdk/integrations/pymongo.py @@ -123,6 +123,7 @@ def started(self, event): data["operation_ids"]["operation"] = event.operation_id data["operation_ids"]["request"] = event.request_id + data["db.system"] = "mongodb" try: lsid = command.pop("lsid")["id"] From 088cacd1ff158239d7fee0dc1f6dda49a9e76ea0 Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Tue, 25 Apr 2023 16:01:34 +0200 Subject: [PATCH 2/9] Updated tests --- tests/integrations/pymongo/test_pymongo.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/integrations/pymongo/test_pymongo.py b/tests/integrations/pymongo/test_pymongo.py index 16438ac971..092ebe1050 100644 --- a/tests/integrations/pymongo/test_pymongo.py +++ b/tests/integrations/pymongo/test_pymongo.py @@ -55,6 +55,7 @@ def test_transactions(sentry_init, capture_events, mongo_server, with_pii): "net.peer.port": str(mongo_server.port), } for span in find, insert_success, insert_fail: + assert span["data"]["db.system"] == "mongodb" for field, value in common_tags.items(): assert span["tags"][field] == value From 75eaa80faa7eb71b7df89ddb3c304a9acd9c484c Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Tue, 25 Apr 2023 16:05:08 +0200 Subject: [PATCH 3/9] Updated type --- sentry_sdk/integrations/pymongo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sentry_sdk/integrations/pymongo.py b/sentry_sdk/integrations/pymongo.py index a4db4a1d84..aaa96391f4 100644 --- a/sentry_sdk/integrations/pymongo.py +++ b/sentry_sdk/integrations/pymongo.py @@ -119,7 +119,7 @@ def started(self, event): except TypeError: pass - data = {"operation_ids": {}} # type: Dict[str, Dict[str, Any]] + data = {"operation_ids": {}} # type: Dict[str, Union[Dict[str, Any], str]] data["operation_ids"]["operation"] = event.operation_id data["operation_ids"]["request"] = event.request_id From bb65f59258d68addb18f454a102d69cde8d89ad5 Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Thu, 27 Apr 2023 12:07:20 +0200 Subject: [PATCH 4/9] Made it better --- sentry_sdk/integrations/pymongo.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sentry_sdk/integrations/pymongo.py b/sentry_sdk/integrations/pymongo.py index aaa96391f4..e098263bd8 100644 --- a/sentry_sdk/integrations/pymongo.py +++ b/sentry_sdk/integrations/pymongo.py @@ -2,6 +2,7 @@ import copy from sentry_sdk import Hub +from sentry_sdk.consts import SPANDATA from sentry_sdk.hub import _should_send_default_pii from sentry_sdk.integrations import DidNotEnable, Integration from sentry_sdk.tracing import Span @@ -123,7 +124,7 @@ def started(self, event): data["operation_ids"]["operation"] = event.operation_id data["operation_ids"]["request"] = event.request_id - data["db.system"] = "mongodb" + data[SPANDATA.DB_SYSTEM] = "mongodb" try: lsid = command.pop("lsid")["id"] From f6be24b4796e074b06e240091d3cc771498cb8bf Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Thu, 27 Apr 2023 13:16:22 +0200 Subject: [PATCH 5/9] Losened typing --- sentry_sdk/integrations/pymongo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sentry_sdk/integrations/pymongo.py b/sentry_sdk/integrations/pymongo.py index e098263bd8..0b057fe548 100644 --- a/sentry_sdk/integrations/pymongo.py +++ b/sentry_sdk/integrations/pymongo.py @@ -120,7 +120,7 @@ def started(self, event): except TypeError: pass - data = {"operation_ids": {}} # type: Dict[str, Union[Dict[str, Any], str]] + data = {"operation_ids": {}} # type: Dict[str, Any] data["operation_ids"]["operation"] = event.operation_id data["operation_ids"]["request"] = event.request_id From d3419a11c0a51de6fc4ecf54c6917c16ab847f03 Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Thu, 27 Apr 2023 13:17:41 +0200 Subject: [PATCH 6/9] using const instead of string --- tests/integrations/pymongo/test_pymongo.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/integrations/pymongo/test_pymongo.py b/tests/integrations/pymongo/test_pymongo.py index 092ebe1050..786c775e41 100644 --- a/tests/integrations/pymongo/test_pymongo.py +++ b/tests/integrations/pymongo/test_pymongo.py @@ -1,4 +1,5 @@ from sentry_sdk import capture_message, start_transaction +from sentry_sdk.consts import SPANDATA from sentry_sdk.integrations.pymongo import PyMongoIntegration, _strip_pii from mockupdb import MockupDB, OpQuery @@ -55,7 +56,7 @@ def test_transactions(sentry_init, capture_events, mongo_server, with_pii): "net.peer.port": str(mongo_server.port), } for span in find, insert_success, insert_fail: - assert span["data"]["db.system"] == "mongodb" + assert span["data"][SPANDATA.DB_SYSTEM] == "mongodb" for field, value in common_tags.items(): assert span["tags"][field] == value From de23430a2d14073397f0ef6b26f73680d7519b06 Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Thu, 27 Apr 2023 13:39:13 +0200 Subject: [PATCH 7/9] Pinned version of werkzeug used in linters env --- tox.ini | 1 + 1 file changed, 1 insertion(+) diff --git a/tox.ini b/tox.ini index 7a7b314fb2..bd15a8bea7 100644 --- a/tox.ini +++ b/tox.ini @@ -166,6 +166,7 @@ deps = py3.8-common: hypothesis linters: -r linter-requirements.txt + linters: werkzeug<2.3.0 # Common {py3.6,py3.7,py3.8,py3.9,py3.10,py3.11}-common: pytest-asyncio From a62a0c357e72f9f7e38d56b6073f3ac09c598f19 Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Thu, 27 Apr 2023 13:50:46 +0200 Subject: [PATCH 8/9] Pinning urllib version for boto3 tests --- tox.ini | 1 + 1 file changed, 1 insertion(+) diff --git a/tox.ini b/tox.ini index bd15a8bea7..4ab88ee6a9 100644 --- a/tox.ini +++ b/tox.ini @@ -197,6 +197,7 @@ deps = beam-master: git+https://github.com/apache/beam#egg=apache-beam&subdirectory=sdks/python # Boto3 + {py3.7,py3.8}-boto3: urllib3<1.26 boto3-v1.9: boto3>=1.9,<1.10 boto3-v1.10: boto3>=1.10,<1.11 boto3-v1.11: boto3>=1.11,<1.12 From 2854d17cb76daf7911d22d7e39eb55d212e4757f Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Thu, 27 Apr 2023 16:13:48 +0200 Subject: [PATCH 9/9] Cleanup --- tox.ini | 1 - 1 file changed, 1 deletion(-) diff --git a/tox.ini b/tox.ini index 4ab88ee6a9..bd15a8bea7 100644 --- a/tox.ini +++ b/tox.ini @@ -197,7 +197,6 @@ deps = beam-master: git+https://github.com/apache/beam#egg=apache-beam&subdirectory=sdks/python # Boto3 - {py3.7,py3.8}-boto3: urllib3<1.26 boto3-v1.9: boto3>=1.9,<1.10 boto3-v1.10: boto3>=1.10,<1.11 boto3-v1.11: boto3>=1.11,<1.12