Skip to content

feat: send public alias in stats endpoint#104346

Merged
shruthilayaj merged 11 commits intomasterfrom
shruthi/feat/send-internal-and-public-alias
Dec 3, 2025
Merged

feat: send public alias in stats endpoint#104346
shruthilayaj merged 11 commits intomasterfrom
shruthi/feat/send-internal-and-public-alias

Conversation

@shruthilayaj
Copy link
Copy Markdown
Member

No description provided.

@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Dec 3, 2025
continue

for bucket in attribute.buckets:
name = translate_internal_to_public_alias(attribute.attribute_name)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Bug: Missing required parameters in translate_internal_to_public_alias call will raise a TypeError.
Severity: CRITICAL | Confidence: High

🔍 Detailed Analysis

The translate_internal_to_public_alias function is invoked at src/sentry/snuba/spans_rpc.py, line 333, with only one argument (attribute.attribute_name). However, its definition requires three parameters: internal_alias, type, and item_type. This mismatch will result in a TypeError at runtime when the run_stats_query method is called with "attributeDistributions" in stats_types, specifically during iteration over attribute.buckets. This unhandled exception will cause the process handling the request to terminate.

💡 Suggested Fix

Provide the missing type and item_type arguments to translate_internal_to_public_alias. Additionally, unpack the three-element tuple returned by the function, for example: name, _, _ = translate_internal_to_public_alias(attribute.attribute_name, "string", SupportedTraceItemType.SPANS).

🤖 Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: src/sentry/snuba/spans_rpc.py#L333

Potential issue: The `translate_internal_to_public_alias` function is invoked at
`src/sentry/snuba/spans_rpc.py`, line 333, with only one argument
(`attribute.attribute_name`). However, its definition requires three parameters:
`internal_alias`, `type`, and `item_type`. This mismatch will result in a `TypeError` at
runtime when the `run_stats_query` method is called with `"attributeDistributions"` in
`stats_types`, specifically during iteration over `attribute.buckets`. This unhandled
exception will cause the process handling the request to terminate.

Did we get this right? 👍 / 👎 to inform future reviews.
Reference ID: 5308109

Base automatically changed from shruthi/feat/parallelize-trace-item-stats to master December 3, 2025 20:53
@shruthilayaj shruthilayaj requested review from a team as code owners December 3, 2025 20:53
Comment on lines 333 to 335
name = translate_internal_to_public_alias(
attribute.attribute_name, "string", SupportedTraceItemType.SPANS
)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Bug: The name variable receives a tuple from translate_internal_to_public_alias but is used as a string for the "label" key.
Severity: CRITICAL | Confidence: High

🔍 Detailed Analysis

The name variable is assigned the full tuple returned by translate_internal_to_public_alias, which is tuple[str | None, str | None, AttributeSource]. This tuple is then directly used as the value for the "label" key in a dictionary. Since the API expects a string for "label", this will lead to JSON serialization failures when the response is generated, breaking the API contract and causing runtime errors.

💡 Suggested Fix

Unpack the tuple returned by translate_internal_to_public_alias to extract the desired string value for name. For example, change name = translate_internal_to_public_alias(...) to name, _, _ = translate_internal_to_public_alias(...).

🤖 Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: src/sentry/snuba/spans_rpc.py#L333-L335

Potential issue: The `name` variable is assigned the full tuple returned by
`translate_internal_to_public_alias`, which is `tuple[str | None, str | None,
AttributeSource]`. This tuple is then directly used as the value for the `"label"` key
in a dictionary. Since the API expects a string for `"label"`, this will lead to JSON
serialization failures when the response is generated, breaking the API contract and
causing runtime errors.

Did we get this right? 👍 / 👎 to inform future reviews.
Reference ID: 5309255

Comment on lines +333 to +336
name = translate_internal_to_public_alias(
attribute.attribute_name, "string", SupportedTraceItemType.SPANS
)
attrs[name].append({"label": bucket.label, "value": bucket.value})
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Bug: The return value of translate_internal_to_public_alias is not unpacked, causing name to be a tuple instead of a string.
Severity: CRITICAL | Confidence: High

🔍 Detailed Analysis

The translate_internal_to_public_alias function returns a tuple, but its return value is not unpacked when assigned to name in src/sentry/snuba/spans_rpc.py:333-336. This causes name to be a tuple, not a string, when used as a dictionary key in attrs[name]. As a result, the attrs dictionary will contain tuple keys instead of string keys. The API response will then include malformed attribute distribution data, as JSON cannot represent Python tuples, leading to failures or corrupted data for downstream consumers.

💡 Suggested Fix

Unpack the tuple returned by translate_internal_to_public_alias by changing the assignment to name, _, _ = translate_internal_to_public_alias(...).

🤖 Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: src/sentry/snuba/spans_rpc.py#L333-L336

Potential issue: The `translate_internal_to_public_alias` function returns a tuple, but
its return value is not unpacked when assigned to `name` in
`src/sentry/snuba/spans_rpc.py:333-336`. This causes `name` to be a tuple, not a string,
when used as a dictionary key in `attrs[name]`. As a result, the `attrs` dictionary will
contain tuple keys instead of string keys. The API response will then include malformed
attribute distribution data, as JSON cannot represent Python tuples, leading to failures
or corrupted data for downstream consumers.

Did we get this right? 👍 / 👎 to inform future reviews.
Reference ID: 5310058

attribute.attribute_name, "string", SupportedTraceItemType.SPANS
)
public_alias = public_alias or attribute.attribute_name
attrs[public_alias].append({"label": bucket.label, "value": bucket.value})
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Bug: Translation computed inside inner loop instead of outer

The translate_internal_to_public_alias call is placed inside the for bucket in attribute.buckets loop, but it only depends on attribute.attribute_name which doesn't change between buckets. This causes the same translation to be computed redundantly up to 75 times per attribute (once per bucket). Moving lines 333-336 outside the bucket loop and before it would compute the public_alias once per attribute instead.

Fix in Cursor Fix in Web

@shruthilayaj shruthilayaj merged commit d1b5461 into master Dec 3, 2025
67 checks passed
@shruthilayaj shruthilayaj deleted the shruthi/feat/send-internal-and-public-alias branch December 3, 2025 21:35
@github-actions github-actions bot locked and limited conversation to collaborators Dec 19, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants