|
@@ -1,15 +1,19 @@
|
|
|
+from datetime import datetime
|
|
|
from time import sleep, time
|
|
|
-from typing import Any, MutableMapping
|
|
|
+from typing import Any, MutableMapping, Optional
|
|
|
|
|
|
from django.conf import settings
|
|
|
+from pytz import UTC
|
|
|
from symbolic import ProguardMapper # type: ignore
|
|
|
|
|
|
+from sentry.constants import DataCategory
|
|
|
from sentry.lang.native.symbolicator import Symbolicator
|
|
|
from sentry.models import Project, ProjectDebugFile
|
|
|
from sentry.profiles.device import classify_device
|
|
|
from sentry.tasks.base import instrumented_task
|
|
|
from sentry.tasks.symbolication import RetrySymbolication
|
|
|
from sentry.utils import json, kafka_config
|
|
|
+from sentry.utils.outcomes import Outcome, track_outcome
|
|
|
from sentry.utils.pubsub import KafkaPublisher
|
|
|
|
|
|
processed_profiles_publisher = None
|
|
@@ -22,11 +26,15 @@ processed_profiles_publisher = None
|
|
|
max_retries=5,
|
|
|
acks_late=True,
|
|
|
)
|
|
|
-def process_profile(profile: MutableMapping[str, Any], **kwargs: Any) -> None:
|
|
|
+def process_profile(
|
|
|
+ profile: MutableMapping[str, Any], key_id: Optional[int], **kwargs: Any
|
|
|
+) -> None:
|
|
|
+ project = Project.objects.get_from_cache(id=profile["project_id"])
|
|
|
+
|
|
|
if profile["platform"] == "cocoa":
|
|
|
- profile = _symbolicate(profile=profile)
|
|
|
+ profile = _symbolicate(profile=profile, project=project)
|
|
|
elif profile["platform"] == "android":
|
|
|
- profile = _deobfuscate(profile=profile)
|
|
|
+ profile = _deobfuscate(profile=profile, project=project)
|
|
|
|
|
|
profile = _normalize(profile=profile)
|
|
|
|
|
@@ -43,6 +51,18 @@ def process_profile(profile: MutableMapping[str, Any], **kwargs: Any) -> None:
|
|
|
json.dumps(profile),
|
|
|
)
|
|
|
|
|
|
+ track_outcome(
|
|
|
+ org_id=project.organization_id,
|
|
|
+ project_id=project.id,
|
|
|
+ key_id=key_id,
|
|
|
+ outcome=Outcome.ACCEPTED,
|
|
|
+ reason=None,
|
|
|
+ timestamp=datetime.utcnow().replace(tzinfo=UTC),
|
|
|
+ event_id=profile["transaction_id"],
|
|
|
+ category=DataCategory.PROFILE,
|
|
|
+ quantity=1,
|
|
|
+ )
|
|
|
+
|
|
|
|
|
|
def _normalize(profile: MutableMapping[str, Any]) -> MutableMapping[str, Any]:
|
|
|
classification_options = {
|
|
@@ -70,8 +90,7 @@ def _normalize(profile: MutableMapping[str, Any]) -> MutableMapping[str, Any]:
|
|
|
return profile
|
|
|
|
|
|
|
|
|
-def _symbolicate(profile: MutableMapping[str, Any]) -> MutableMapping[str, Any]:
|
|
|
- project = Project.objects.get_from_cache(id=profile["project_id"])
|
|
|
+def _symbolicate(profile: MutableMapping[str, Any], project: Project) -> MutableMapping[str, Any]:
|
|
|
symbolicator = Symbolicator(project=project, event_id=profile["profile_id"])
|
|
|
modules = profile["debug_meta"]["images"]
|
|
|
stacktraces = [
|
|
@@ -120,12 +139,11 @@ def _symbolicate(profile: MutableMapping[str, Any]) -> MutableMapping[str, Any]:
|
|
|
return profile
|
|
|
|
|
|
|
|
|
-def _deobfuscate(profile: MutableMapping[str, Any]) -> MutableMapping[str, Any]:
|
|
|
+def _deobfuscate(profile: MutableMapping[str, Any], project: Project) -> MutableMapping[str, Any]:
|
|
|
debug_file_id = profile.get("build_id")
|
|
|
if debug_file_id is None or debug_file_id == "":
|
|
|
return profile
|
|
|
|
|
|
- project = Project.objects.get_from_cache(id=profile["project_id"])
|
|
|
dif_paths = ProjectDebugFile.difcache.fetch_difs(project, [debug_file_id], features=["mapping"])
|
|
|
debug_file_path = dif_paths.get(debug_file_id)
|
|
|
if debug_file_path is None:
|