Skip to content

Commit 5ee90a2

Browse files
authored
feat(llm-detection): Accept additional_attributes param in get_trace_waterfall (#112239)
Allow callers to specify which additional span attributes to fetch, defaulting to `["span.status_code"]` for backward compatibility. pairs with getsentry/seer#5633
1 parent b82a004 commit 5ee90a2

File tree

2 files changed

+39
-7
lines changed

2 files changed

+39
-7
lines changed

src/sentry/seer/explorer/tools.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,9 @@ def execute_trace_table_query(
371371
raise
372372

373373

374-
def get_trace_waterfall(trace_id: str, organization_id: int) -> EAPTrace | None:
374+
def get_trace_waterfall(
375+
trace_id: str, organization_id: int, additional_attributes: list[str] | None = None
376+
) -> EAPTrace | None:
375377
"""
376378
Get the full span waterfall and connected errors for a trace.
377379
@@ -382,6 +384,8 @@ def get_trace_waterfall(trace_id: str, organization_id: int) -> EAPTrace | None:
382384
Returns:
383385
The spans and errors in the trace, along with the full 32-character trace ID.
384386
"""
387+
if additional_attributes is None:
388+
additional_attributes = ["span.status_code"]
385389

386390
try:
387391
organization = Organization.objects.get(id=organization_id)
@@ -416,7 +420,7 @@ def get_trace_waterfall(trace_id: str, organization_id: int) -> EAPTrace | None:
416420
events = query_trace_data(
417421
snuba_params,
418422
full_trace_id,
419-
additional_attributes=["span.status_code"],
423+
additional_attributes=additional_attributes,
420424
referrer=Referrer.SEER_EXPLORER_TOOLS,
421425
organization=organization,
422426
)
@@ -428,8 +432,10 @@ def get_trace_waterfall(trace_id: str, organization_id: int) -> EAPTrace | None:
428432
)
429433

430434

431-
def rpc_get_trace_waterfall(trace_id: str, organization_id: int) -> dict[str, Any]:
432-
trace = get_trace_waterfall(trace_id, organization_id)
435+
def rpc_get_trace_waterfall(
436+
trace_id: str, organization_id: int, additional_attributes: list[str] | None = None
437+
) -> dict[str, Any]:
438+
trace = get_trace_waterfall(trace_id, organization_id, additional_attributes)
433439
return trace.dict() if trace else {}
434440

435441

tests/sentry/seer/explorer/test_tools.py

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -760,11 +760,10 @@ def test_get_trace_waterfall_sliding_window_beyond_limit(self) -> None:
760760
assert result is None
761761

762762
def test_get_trace_waterfall_includes_status_code(self) -> None:
763-
"""Test that span.status_code is included in additional_attributes."""
763+
"""Test that span.status_code is included if additional_attributes is not provided"""
764764
transaction_name = "api/test/status"
765765
trace_id = uuid.uuid4().hex
766766

767-
# Create a span with status_code
768767
span = self.create_span(
769768
{
770769
"description": "http-request",
@@ -782,11 +781,38 @@ def test_get_trace_waterfall_includes_status_code(self) -> None:
782781
result = get_trace_waterfall(trace_id, self.organization.id)
783782
assert isinstance(result, EAPTrace)
784783

785-
# Find the span and verify additional_attributes contains status_code
786784
root_span = result.trace[0]
787785
assert "additional_attributes" in root_span
788786
assert root_span["additional_attributes"].get("span.status_code") == "500"
789787

788+
def test_get_trace_waterfall_includes_additional_attributes(self) -> None:
789+
"""Test that additional_attributes passed into the function are included on returned traces"""
790+
transaction_name = "api/test/status"
791+
trace_id = uuid.uuid4().hex
792+
793+
span = self.create_span(
794+
{
795+
"description": "http-request",
796+
"sentry_tags": {
797+
"transaction": transaction_name,
798+
"status_code": "500",
799+
"request.url": "best-url-ev3r.biz",
800+
},
801+
"trace_id": trace_id,
802+
"is_segment": True,
803+
},
804+
start_ts=self.ten_mins_ago,
805+
)
806+
self.store_spans([span])
807+
808+
result = get_trace_waterfall(trace_id, self.organization.id, ["request.url"])
809+
assert isinstance(result, EAPTrace)
810+
811+
root_span = result.trace[0]
812+
assert "additional_attributes" in root_span
813+
assert root_span["additional_attributes"].get("span.status_code") is None
814+
assert root_span["additional_attributes"].get("request.url") == "best-url-ev3r.biz"
815+
790816

791817
class TestTraceTableQuery(APITransactionTestCase, SnubaTestCase, SpanTestCase):
792818
def setUp(self) -> None:

0 commit comments

Comments
 (0)