Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 59 additions & 54 deletions src/sentry/api/endpoints/organization_trace_item_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,70 +275,75 @@ def get(self, request: Request, organization: Organization) -> Response:
include_internal = is_active_superuser(request) or is_active_staff(request)

def data_fn(offset: int, limit: int):
rpc_request = TraceItemAttributeNamesRequest(
meta=meta,
limit=limit,
page_token=PageToken(offset=offset),
type=attr_type,
value_substring_match=value_substring_match,
intersecting_attributes_filter=query_filter,
)
with sentry_sdk.start_span(op="query", name="attribute_names") as span:
rpc_request = TraceItemAttributeNamesRequest(
meta=meta,
limit=limit,
page_token=PageToken(offset=offset),
type=attr_type,
value_substring_match=value_substring_match,
intersecting_attributes_filter=query_filter,
)

with handle_query_errors():
rpc_response = snuba_rpc.attribute_names_rpc(rpc_request)

if use_sentry_conventions:
attribute_keys = {}
for attribute in rpc_response.attributes:
if attribute.name and can_expose_attribute(
attribute.name,
trace_item_type,
include_internal=include_internal,
):
attr_key = as_attribute_key(
with handle_query_errors():
rpc_response = snuba_rpc.attribute_names_rpc(rpc_request)

if use_sentry_conventions:
attribute_keys = {}
for attribute in rpc_response.attributes:
if attribute.name and can_expose_attribute(
attribute.name,
serialized["attribute_type"],
trace_item_type,
)
public_alias = attr_key["name"]
replacement = translate_to_sentry_conventions(public_alias, trace_item_type)
if public_alias != replacement:
include_internal=include_internal,
):
attr_key = as_attribute_key(
replacement,
attribute.name,
serialized["attribute_type"],
trace_item_type,
)

attribute_keys[attr_key["name"]] = attr_key

attributes = list(attribute_keys.values())
public_alias = attr_key["name"]
replacement = translate_to_sentry_conventions(
public_alias, trace_item_type
)
if public_alias != replacement:
attr_key = as_attribute_key(
replacement,
serialized["attribute_type"],
trace_item_type,
)

attribute_keys[attr_key["name"]] = attr_key

attributes = list(attribute_keys.values())
sentry_sdk.set_context("api_response", {"attributes": attributes})
return attributes
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Missing span debug data in sentry conventions branch

The span.set_data() calls for attribute_count and attribute_type are only executed in the use_sentry_conventions=False branch. When use_sentry_conventions is True, the function returns early at line 319 without setting this debug data on the span. Given this PR intends to add debug data to the endpoint, this inconsistency appears to be an oversight.

Additional Locations (1)

Fix in Cursor Fix in Web


attributes = list(
filter(
lambda x: not is_sentry_convention_replacement_attribute(
x["name"], trace_item_type
),
[
as_attribute_key(
attribute.name,
serialized["attribute_type"],
trace_item_type,
)
for attribute in rpc_response.attributes
if attribute.name
and can_expose_attribute(
attribute.name,
trace_item_type,
include_internal=include_internal,
)
],
)
)
sentry_sdk.set_context("api_response", {"attributes": attributes})
span.set_data("attribute_count", len(attributes))
span.set_data("attribute_type", attribute_type)
return attributes

attributes = list(
filter(
lambda x: not is_sentry_convention_replacement_attribute(
x["name"], trace_item_type
),
[
as_attribute_key(
attribute.name,
serialized["attribute_type"],
trace_item_type,
)
for attribute in rpc_response.attributes
if attribute.name
and can_expose_attribute(
attribute.name,
trace_item_type,
include_internal=include_internal,
)
],
)
)
sentry_sdk.set_context("api_response", {"attributes": attributes})
return attributes

return self.paginate(
request=request,
paginator=TraceItemAttributesNamesPaginator(data_fn=data_fn),
Expand Down
Loading