コード例 #1
0
    def handle_data(
        self,
        request: Request,
        organization: Organization,
        project_ids: Sequence[int],
        results: Optional[Sequence[Any]],
    ) -> Optional[Sequence[Any]]:
        if not results:
            return results

        first_row = results[0]

        # TODO(mark) move all of this result formatting into discover.query()
        # once those APIs are used across the application.
        if "transaction.status" in first_row:
            for row in results:
                row["transaction.status"] = SPAN_STATUS_CODE_TO_NAME.get(row["transaction.status"])

        fields = self.get_field_list(organization, request)
        if "issue" in fields:  # Look up the short ID and return that in the results
            self.handle_issues(results, project_ids, organization)

        if not ("project.id" in first_row or "projectid" in first_row):
            return results

        for result in results:
            for key in ("projectid", "project.id"):
                if key in result and key not in fields:
                    del result[key]

        return results
コード例 #2
0
 def full_dict(self, detailed: bool = False) -> FullResponse:
     result = cast(FullResponse, self.to_dict())
     if detailed and "transaction.status" in self.event:
         result.update({
             "transaction.status":
             SPAN_STATUS_CODE_TO_NAME.get(self.event["transaction.status"],
                                          "unknown"),
         })
     if self.nodestore_event:
         result["timestamp"] = self.nodestore_event.data.get("timestamp")
         result["start_timestamp"] = self.nodestore_event.data.get(
             "start_timestamp")
         if detailed:
             if "measurements" in self.nodestore_event.data:
                 result["measurements"] = self.nodestore_event.data.get(
                     "measurements")
             result["_meta"] = {}
             result["tags"], result["_meta"]["tags"] = get_tags_with_meta(
                 self.nodestore_event)
     # Only add children that have nodestore events, which may be missing if we're pruning for trace navigator
     result["children"] = [
         child.full_dict(detailed) for child in self.children
         if child.nodestore_event
     ]
     return result
コード例 #3
0
    def handle_data(self, request, organization, project_ids, results):
        if not results:
            return results

        first_row = results[0]

        # TODO(mark) move all of this result formatting into discover.query()
        # once those APIs are used across the application.
        if "transaction.status" in first_row:
            for row in results:
                row["transaction.status"] = SPAN_STATUS_CODE_TO_NAME.get(
                    row["transaction.status"])

        fields = request.GET.getlist("field")
        has_issues = "issue" in fields
        if has_issues:  # Look up the short ID and return that in the results
            if has_issues:
                issue_ids = set(row.get("issue.id") for row in results)
                issues = Group.issues_mapping(issue_ids, project_ids,
                                              organization)
            for result in results:
                if has_issues and "issue.id" in result:
                    result["issue"] = issues.get(result["issue.id"], "unknown")

        if not ("project.id" in first_row or "projectid" in first_row):
            return results

        for result in results:
            for key in ("projectid", "project.id"):
                if key in result:
                    if key not in fields:
                        del result[key]

        return results
コード例 #4
0
    def handle_data(self, request, organization, project_ids, results):
        if not results:
            return results

        first_row = results[0]

        # TODO(mark) move all of this result formatting into discover.query()
        # once those APIs are used across the application.
        tests = {
            "transaction.status": "transaction.status" in first_row,
            "trace": "trace" in first_row,
        }
        if any(tests.values()):
            for row in results:
                if tests["transaction.status"]:
                    row["transaction.status"] = SPAN_STATUS_CODE_TO_NAME.get(
                        row["transaction.status"]
                    )
                if tests["trace"]:
                    row["trace"] = uuid.UUID(row["trace"]).hex

        fields = request.GET.getlist("field")
        issues = {}
        if "issue" in fields:  # Look up the short ID and return that in the results
            issue_ids = set(row["issue.id"] for row in results)
            issues = {
                i.id: i.qualified_short_id
                for i in Group.objects.filter(
                    id__in=issue_ids, project_id__in=project_ids, project__organization=organization
                )
            }
            for result in results:
                if "issue.id" in result:
                    result["issue"] = issues[result["issue.id"]]

        if not ("project.id" in first_row or "projectid" in first_row):
            return results

        projects = {
            p["id"]: p["slug"]
            for p in Project.objects.filter(organization=organization, id__in=project_ids).values(
                "id", "slug"
            )
        }
        for result in results:
            for key in ("projectid", "project.id"):
                if key in result:
                    # Handle bizarre empty case
                    if result[key] == 0:
                        result["project.name"] = ""
                    else:
                        result["project.name"] = projects[result[key]]
                    if key not in fields:
                        del result[key]

        return results
コード例 #5
0
 def serialize_event(self, event, *args, **kwargs):
     result = super().serialize_event(event, *args, **kwargs)
     if "transaction.status" in event:
         result.update({
             "transaction.status":
             SPAN_STATUS_CODE_TO_NAME.get(event["transaction.status"],
                                          "unknown"),
         })
     result.update({
         "children": [],
     })
     return result
コード例 #6
0
    def handle_data(self, request, organization, project_ids, results, omit_nan=False):
        if not results:
            return results

        first_row = results[0]

        # TODO(mark) move all of this result formatting into discover.query()
        # once those APIs are used across the application.
        if "transaction.status" in first_row:
            for row in results:
                row["transaction.status"] = SPAN_STATUS_CODE_TO_NAME.get(row["transaction.status"])

        fields = request.GET.getlist("field")
        has_issues = "issue" in fields
        if has_issues or omit_nan:  # Look up the short ID and return that in the results
            if has_issues:
                issue_ids = set(row.get("issue.id") for row in results)
                issues = Group.issues_mapping(issue_ids, project_ids, organization)
            for result in results:
                if has_issues and "issue.id" in result:
                    result["issue"] = issues.get(result["issue.id"], "unknown")
                # Remove any potential NaN or Inf cause python json accepts either, but js doesn't
                if omit_nan:
                    for key in result.keys():
                        if isinstance(result[key], float) and (
                            math.isnan(result[key]) or math.isinf(result[key])
                        ):
                            result[key] = None

        if not ("project.id" in first_row or "projectid" in first_row):
            return results

        for result in results:
            for key in ("projectid", "project.id"):
                if key in result:
                    if key not in fields:
                        del result[key]

        return results
コード例 #7
0
ファイル: organization_events.py プロジェクト: jiangge/sentry
    def handle_data(self, request, organization, project_ids, results):
        if not results:
            return results

        first_row = results[0]

        # TODO(mark) move all of this result formatting into discover.query()
        # once those APIs are used across the application.
        if "transaction.status" in first_row:
            for row in results:
                row["transaction.status"] = SPAN_STATUS_CODE_TO_NAME.get(
                    row["transaction.status"])

        fields = request.GET.getlist("field")
        issues = {}
        if "issue" in fields:  # Look up the short ID and return that in the results
            issue_ids = set(row["issue.id"] for row in results)
            issues = {
                i.id: i.qualified_short_id
                for i in Group.objects.filter(
                    id__in=issue_ids,
                    project_id__in=project_ids,
                    project__organization=organization)
            }
            for result in results:
                if "issue.id" in result:
                    result["issue"] = issues.get(result["issue.id"], "unknown")

        if not ("project.id" in first_row or "projectid" in first_row):
            return results

        for result in results:
            for key in ("projectid", "project.id"):
                if key in result:
                    if key not in fields:
                        del result[key]

        return results
コード例 #8
0
    def handle_data(self, request, organization, project_ids, results):
        if not results:
            return results

        first_row = results[0]

        # TODO(mark) move all of this result formatting into discover.query()
        # once those APIs are used across the application.
        tests = {
            "transaction.status": "transaction.status" in first_row,
            "trace": "trace" in first_row,
        }
        if any(tests.values()):
            for row in results:
                if tests["transaction.status"]:
                    row["transaction.status"] = SPAN_STATUS_CODE_TO_NAME.get(
                        row["transaction.status"]
                    )
                if tests["trace"]:
                    row["trace"] = uuid.UUID(row["trace"]).hex

        if not ("project.id" in first_row or "projectid" in first_row):
            return results
        fields = request.GET.getlist("field")
        projects = {
            p["id"]: p["slug"]
            for p in Project.objects.filter(organization=organization, id__in=project_ids).values(
                "id", "slug"
            )
        }
        for result in results:
            for key in ("projectid", "project.id"):
                if key in result:
                    result["project.name"] = projects[result[key]]
                    if key not in fields:
                        del result[key]

        return results