Skip to content

Commit

Permalink
fix(trace-explorer): Breakdown by project and sdk (#70463)
Browse files Browse the repository at this point in the history
For full stack projects that use a single project for all the data, we
need to break it down further using sdk.
  • Loading branch information
Zylphrex committed May 7, 2024
1 parent 874db7e commit 80ed536
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/sentry/api/endpoints/organization_traces.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

class TraceInterval(TypedDict):
project: str | None
sdkName: str | None
start: int
end: int
kind: Literal["project", "missing", "other"]
Expand Down Expand Up @@ -637,6 +638,8 @@ def process_final_results(
# mapping of trace id to a tuple of project slug + transaction name
traces_names: MutableMapping[str, tuple[str, str]] = {}
for row in traces_breakdown_projects_results["data"]:
if row["trace"] in traces_names:
continue
# The underlying column is a Nullable(UInt64) but we write a default of 0 to it.
# So make sure to handle both in case something changes.
if not row["parent_span"] or int(row["parent_span"], 16) == 0:
Expand Down Expand Up @@ -706,6 +709,7 @@ def get_traces_breakdown_projects_query(
selected_columns=[
"trace",
"project",
"sdk.name",
"parent_span",
"transaction",
"precise.start_ts",
Expand Down Expand Up @@ -748,6 +752,7 @@ def get_traces_breakdown_categories_query(
"project",
"transaction",
"span.category",
"sdk.name",
"precise.start_ts",
"precise.finish_ts",
],
Expand Down Expand Up @@ -986,6 +991,7 @@ def should_merge(interval_a, interval_b):
return (
interval_a["end"] >= interval_b["start"]
and interval_a["project"] == interval_b["project"]
and interval_a["sdkName"] == interval_b["sdkName"]
and interval_a["opCategory"] == interval_b["opCategory"]
)

Expand Down Expand Up @@ -1014,6 +1020,7 @@ def breakdown_push(trace, interval):
{
"kind": "missing",
"project": None,
"sdkName": None,
"opCategory": None,
"start": last_interval["end"],
"end": interval["start"],
Expand Down Expand Up @@ -1069,6 +1076,7 @@ def stack_clear(trace, until=None):
cur: TraceInterval = {
"kind": "project",
"project": row["project"],
"sdkName": row["sdk.name"],
"opCategory": row.get("span.category"),
"start": span_start,
"end": span_end,
Expand All @@ -1092,6 +1100,7 @@ def stack_clear(trace, until=None):
other: TraceInterval = {
"kind": "other",
"project": None,
"sdkName": None,
"opCategory": None,
"start": trace_range["start"],
"end": trace_range["end"],
Expand Down
3 changes: 3 additions & 0 deletions src/sentry/testutils/cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -1487,6 +1487,7 @@ def store_segment(
measurements: Mapping[str, int | float] | None = None,
timestamp: datetime | None = None,
store_metrics_summary: Mapping[str, Sequence[Mapping[str, Any]]] | None = None,
sdk_name: str | None = None,
):
if span_id is None:
span_id = self._random_span_id()
Expand Down Expand Up @@ -1520,6 +1521,8 @@ def store_segment(
payload["_metrics_summary"] = store_metrics_summary
if parent_span_id:
payload["parent_span_id"] = parent_span_id
if sdk_name is not None:
payload["sentry_tags"]["sdk.name"] = sdk_name

self.store_span(payload)

Expand Down

0 comments on commit 80ed536

Please sign in to comment.