Skip to content

Commit

Permalink
feat(profiles): Allow Android chunk ingestion (#79696)
Browse files Browse the repository at this point in the history
  • Loading branch information
phacops authored Oct 24, 2024
1 parent 4862dc2 commit 368ee65
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
11 changes: 8 additions & 3 deletions src/sentry/profiles/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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)


Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
9 changes: 6 additions & 3 deletions tests/sentry/profiles/test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit 368ee65

Please sign in to comment.