From 368ee65eed2270d415282bad8c3a20b8a1fde871 Mon Sep 17 00:00:00 2001 From: Pierre Massat Date: Thu, 24 Oct 2024 16:49:51 -0400 Subject: [PATCH] feat(profiles): Allow Android chunk ingestion (#79696) --- src/sentry/profiles/task.py | 11 ++++++++--- tests/sentry/profiles/test_task.py | 9 ++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/sentry/profiles/task.py b/src/sentry/profiles/task.py index 0149b9159366d6..9c5e1b9dd3577f 100644 --- a/src/sentry/profiles/task.py +++ b/src/sentry/profiles/task.py @@ -131,6 +131,8 @@ def process_profile_task( set_measurement("profile.samples", len(profile["profile"]["samples"])) set_measurement("profile.stacks", len(profile["profile"]["stacks"])) set_measurement("profile.frames", len(profile["profile"]["frames"])) + elif "profiler_id" in profile and profile["platform"] == "android": + sentry_sdk.set_tag("format", "android_chunk") else: sentry_sdk.set_tag("format", "legacy") @@ -193,7 +195,7 @@ def process_profile_task( _track_duration_outcome(profile=profile, project=project) except Exception as e: sentry_sdk.capture_exception(e) - if profile.get("version") != "2": + if "profiler_id" not in profile: _track_outcome(profile=profile, project=project, outcome=Outcome.ACCEPTED) @@ -997,7 +999,7 @@ def _track_outcome( def _insert_vroom_profile(profile: Profile) -> bool: with sentry_sdk.start_span(op="task.profiling.insert_vroom"): try: - path = "/chunk" if profile.get("version") == "2" else "/profile" + path = "/chunk" if "profiler_id" in profile else "/profile" response = get_from_profiling_service(method="POST", path=path, json_data=profile) if response.status == 204: @@ -1073,7 +1075,10 @@ class _ProjectKeyKwargs(TypedDict): @lru_cache(maxsize=100) def get_metrics_dsn(project_id: int) -> str: - kwargs: _ProjectKeyKwargs = {"project_id": project_id, "use_case": UseCase.PROFILING.value} + kwargs: _ProjectKeyKwargs = { + "project_id": project_id, + "use_case": UseCase.PROFILING.value, + } try: project_key, _ = ProjectKey.objects.get_or_create(**kwargs) except ProjectKey.MultipleObjectsReturned: diff --git a/tests/sentry/profiles/test_task.py b/tests/sentry/profiles/test_task.py index 4491a027bf3301..2b299a7951cd4e 100644 --- a/tests/sentry/profiles/test_task.py +++ b/tests/sentry/profiles/test_task.py @@ -524,7 +524,10 @@ def test_process_symbolicator_results_for_sample(): ] _process_symbolicator_results_for_sample( - profile, stacktraces, set(range(len(profile["profile"]["frames"]))), profile["platform"] + profile, + stacktraces, + set(range(len(profile["profile"]["frames"]))), + profile["platform"], ) assert profile["profile"]["stacks"] == [[0, 1, 2, 3, 4, 5]] @@ -948,7 +951,7 @@ def test_process_profile_task_should_emit_profile_duration_outcome( assert _track_duration_outcome.call_count == 1 - if profile.get("version") != "2": + if "profiler_id" not in profile: assert _track_outcome.call_count == 1 else: assert _track_outcome.call_count == 0 @@ -994,7 +997,7 @@ def test_process_profile_task_should_not_emit_profile_duration_outcome( organization=organization, profile=profile ) - if profile.get("version") != "2": + if "profiler_id" not in profile: assert _track_outcome.call_count == 1 else: assert _track_outcome.call_count == 0