Skip to content

Commit 288ca57

Browse files
authored
feat(profiling): Detect chunks without client sdk (#89195)
There were a few sdk versions where the chunks did not contain the client sdk info. This picks them out and assigns a default to them as we want to identify them.
1 parent 76a0ee1 commit 288ca57

File tree

2 files changed

+76
-9
lines changed

2 files changed

+76
-9
lines changed

src/sentry/profiles/task.py

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,19 +1137,38 @@ def determine_profile_type(profile: Profile) -> EventType:
11371137
raise UnknownProfileTypeException
11381138

11391139

1140-
def track_latest_sdk(project: Project, profile: Profile) -> None:
1141-
event_type = determine_profile_type(profile)
1142-
1140+
def determine_client_sdk(profile: Profile, event_type: EventType) -> tuple[str, str]:
11431141
client_sdk = profile.get("client_sdk")
11441142

1145-
if not client_sdk:
1146-
raise UnknownClientSDKException
1143+
if client_sdk:
1144+
sdk_name = client_sdk.get("name")
1145+
sdk_version = client_sdk.get("version")
1146+
1147+
if sdk_name and sdk_version:
1148+
return sdk_name, sdk_version
1149+
1150+
# some older sdks were sending the profile chunk without the
1151+
# sdk info, here we hard code a few and assign them a guaranteed
1152+
# outdated version
1153+
if event_type == EventType.PROFILE_CHUNK:
1154+
if profile["platform"] == "python":
1155+
return "sentry.python", "0.0.0"
1156+
elif profile["platform"] == "cocoa":
1157+
return "sentry.cocoa", "0.0.0"
1158+
elif profile["platform"] == "node":
1159+
# there are other node platforms but it's not straight forward
1160+
# to figure out which it is here so collapse them all into just node
1161+
return "sentry.javascript.node", "0.0.0"
11471162

1148-
sdk_name = client_sdk.get("name")
1149-
sdk_version = client_sdk.get("version")
1163+
# Other platforms do not have a version released where it sends
1164+
# a profile chunk without the client sdk info
11501165

1151-
if not sdk_name or not sdk_version:
1152-
raise UnknownClientSDKException
1166+
raise UnknownClientSDKException
1167+
1168+
1169+
def track_latest_sdk(project: Project, profile: Profile) -> None:
1170+
event_type = determine_profile_type(profile)
1171+
sdk_name, sdk_version = determine_client_sdk(profile, event_type)
11531172

11541173
try:
11551174
ProjectSDK.update_with_newest_version_or_create(

tests/sentry/profiles/test_task.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -977,3 +977,51 @@ def test_track_latest_sdk(
977977
)
978978
is not None
979979
)
980+
981+
982+
@patch("sentry.profiles.task._push_profile_to_vroom")
983+
@patch("sentry.profiles.task._symbolicate_profile")
984+
@patch("sentry.models.projectsdk.get_sdk_index")
985+
@pytest.mark.parametrize(
986+
["platform", "sdk_name"],
987+
[
988+
("python", "sentry.python"),
989+
("cocoa", "sentry.cocoa"),
990+
("node", "sentry.javascript.node"),
991+
],
992+
)
993+
@django_db_all
994+
def test_unknown_sdk(
995+
get_sdk_index,
996+
_symbolicate_profile,
997+
_push_profile_to_vroom,
998+
platform,
999+
sdk_name,
1000+
organization,
1001+
project,
1002+
request,
1003+
):
1004+
_push_profile_to_vroom.return_value = True
1005+
_symbolicate_profile.return_value = True
1006+
get_sdk_index.return_value = {
1007+
sdk_name: {},
1008+
}
1009+
1010+
profile = request.getfixturevalue("sample_v2_profile")
1011+
profile["organization_id"] = organization.id
1012+
profile["project_id"] = project.id
1013+
profile["platform"] = platform
1014+
del profile["client_sdk"]
1015+
1016+
with Feature("organizations:profiling-sdks"):
1017+
process_profile_task(profile=profile)
1018+
1019+
assert (
1020+
ProjectSDK.objects.get(
1021+
project=project,
1022+
event_type=EventType.PROFILE_CHUNK.value,
1023+
sdk_name=sdk_name,
1024+
sdk_version="0.0.0",
1025+
)
1026+
is not None
1027+
)

0 commit comments

Comments
 (0)