From 81aadbb0424ba7f2b287996d438e39b9c1bfbe78 Mon Sep 17 00:00:00 2001 From: Francesco Vigliaturo Date: Thu, 20 Mar 2025 17:06:30 +0100 Subject: [PATCH 1/4] add platform header to the chunk item-type in the envelope --- sentry_sdk/envelope.py | 2 +- tests/profiler/test_continuous_profiler.py | 21 +++++++++++++-------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/sentry_sdk/envelope.py b/sentry_sdk/envelope.py index 5f61e689c5..40f0997fe6 100644 --- a/sentry_sdk/envelope.py +++ b/sentry_sdk/envelope.py @@ -79,7 +79,7 @@ def add_profile_chunk( ): # type: (...) -> None self.add_item( - Item(payload=PayloadRef(json=profile_chunk), type="profile_chunk") + Item(payload=PayloadRef(json=profile_chunk), type="profile_chunk", headers={"platform": profile_chunk.get("platform")}) ) def add_checkin( diff --git a/tests/profiler/test_continuous_profiler.py b/tests/profiler/test_continuous_profiler.py index 78335d7b87..21df6d021e 100644 --- a/tests/profiler/test_continuous_profiler.py +++ b/tests/profiler/test_continuous_profiler.py @@ -141,6 +141,11 @@ def assert_single_transaction_with_profile_chunks( if max_chunks is not None: assert len(items["profile_chunk"]) <= max_chunks + for chunk_item in items["profile_chunk"]: + chunk = chunk_item.payload.json + headers = chunk_item.headers + assert chunk["platform"]==headers["platform"] + transaction = items["transaction"][0].payload.json trace_context = transaction["contexts"]["trace"] @@ -215,12 +220,12 @@ def assert_single_transaction_without_profile_chunks(envelopes): pytest.param( start_profile_session, stop_profile_session, - id="start_profile_session/stop_profile_session", + id="start_profile_session/stop_profile_session (deprecated)", ), pytest.param( start_profiler, stop_profiler, - id="start_profiler/stop_profiler (deprecated)", + id="start_profiler/stop_profiler", ), ], ) @@ -292,12 +297,12 @@ def test_continuous_profiler_auto_start_and_manual_stop( pytest.param( start_profile_session, stop_profile_session, - id="start_profile_session/stop_profile_session", + id="start_profile_session/stop_profile_session (deprecated)", ), pytest.param( start_profiler, stop_profiler, - id="start_profiler/stop_profiler (deprecated)", + id="start_profiler/stop_profiler", ), ], ) @@ -374,12 +379,12 @@ def test_continuous_profiler_manual_start_and_stop_sampled( pytest.param( start_profile_session, stop_profile_session, - id="start_profile_session/stop_profile_session", + id="start_profile_session/stop_profile_session (deprecated)", ), pytest.param( start_profiler, stop_profiler, - id="start_profiler/stop_profiler (deprecated)", + id="start_profiler/stop_profiler", ), ], ) @@ -544,12 +549,12 @@ def test_continuous_profiler_auto_start_and_stop_unsampled( pytest.param( start_profile_session, stop_profile_session, - id="start_profile_session/stop_profile_session", + id="start_profile_session/stop_profile_session (deprecated)", ), pytest.param( start_profiler, stop_profiler, - id="start_profiler/stop_profiler (deprecated)", + id="start_profiler/stop_profiler", ), ], ) From c62897bd0d3dcb549d9506e50b1f49f3f0425f5e Mon Sep 17 00:00:00 2001 From: Francesco Vigliaturo Date: Thu, 20 Mar 2025 17:11:56 +0100 Subject: [PATCH 2/4] fix linter --- tests/profiler/test_continuous_profiler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/profiler/test_continuous_profiler.py b/tests/profiler/test_continuous_profiler.py index 21df6d021e..991f8bda5d 100644 --- a/tests/profiler/test_continuous_profiler.py +++ b/tests/profiler/test_continuous_profiler.py @@ -144,7 +144,7 @@ def assert_single_transaction_with_profile_chunks( for chunk_item in items["profile_chunk"]: chunk = chunk_item.payload.json headers = chunk_item.headers - assert chunk["platform"]==headers["platform"] + assert chunk["platform"] == headers["platform"] transaction = items["transaction"][0].payload.json From 0d1a30d5bc0305a09b4fc9a2ce4a984a3fa366bc Mon Sep 17 00:00:00 2001 From: Francesco Vigliaturo Date: Thu, 20 Mar 2025 17:20:40 +0100 Subject: [PATCH 3/4] fix blake linter warning --- sentry_sdk/envelope.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sentry_sdk/envelope.py b/sentry_sdk/envelope.py index 40f0997fe6..5ca63ea47e 100644 --- a/sentry_sdk/envelope.py +++ b/sentry_sdk/envelope.py @@ -79,7 +79,11 @@ def add_profile_chunk( ): # type: (...) -> None self.add_item( - Item(payload=PayloadRef(json=profile_chunk), type="profile_chunk", headers={"platform": profile_chunk.get("platform")}) + Item( + payload=PayloadRef(json=profile_chunk), + type="profile_chunk", + headers={"platform": profile_chunk.get("platform")}, + ) ) def add_checkin( From 1002ac6a49a08d3bdffd780d895d6d6fe10ed5e6 Mon Sep 17 00:00:00 2001 From: Francesco Vigliaturo Date: Fri, 21 Mar 2025 09:38:15 +0100 Subject: [PATCH 4/4] add default value as a fallback when getting the platform for the chunk item header --- sentry_sdk/envelope.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sentry_sdk/envelope.py b/sentry_sdk/envelope.py index 5ca63ea47e..044d282005 100644 --- a/sentry_sdk/envelope.py +++ b/sentry_sdk/envelope.py @@ -82,7 +82,7 @@ def add_profile_chunk( Item( payload=PayloadRef(json=profile_chunk), type="profile_chunk", - headers={"platform": profile_chunk.get("platform")}, + headers={"platform": profile_chunk.get("platform", "python")}, ) )