Skip to content

Conversation

@phacops
Copy link
Contributor

@phacops phacops commented Jan 22, 2026

Summary

  • Add FUNCTION_ANY to the EAP RPC aggregation functions
  • Support both non-extrapolated and extrapolated queries
  • Support string, int, and boolean attribute types for any() results
  • Add comprehensive tests

Details

The any() aggregation function returns any non-null value from a group. This is useful for retrieving representative values when the specific value doesn't matter.

Implementation:

  • Added anyIfOrNull to aggregation_to_expression() for non-extrapolated queries
  • Added anyIfOrNull to get_extrapolated_function() for extrapolated queries
  • Skip round() wrapper for FUNCTION_ANY since it can return non-numeric types
  • Added type-based converters for FUNCTION_ANY in trace item table to properly handle string/int/boolean results

Note: This requires sentry-protos>=0.4.14 which includes FUNCTION_ANY (value 13).

Test plan

  • Added test_any for basic time series aggregation without extrapolation
  • Added test_any_extrapolated for time series aggregation with sample-weighted extrapolation
  • Added test_any_aggregation_with_string_attribute - inserts many spans with the same string attribute value (custom_tag="blah") and verifies any() returns the string correctly in trace item table
  • Verified existing aggregation tests still pass

🤖 Generated with Claude Code

@phacops phacops requested review from a team as code owners January 22, 2026 17:24
@phacops phacops force-pushed the feat/eap-any-aggregation branch from 0fcdd58 to b4acbf1 Compare January 22, 2026 17:30
Copy link
Member

@volokluev volokluev left a comment

Choose a reason for hiding this comment

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

looks good, please add a test for TraceItemTable also

Comment on lines +310 to +338
def test_any(self) -> None:
# store a test metric with a value of 1, every second of one hour
granularity_secs = 300
query_duration = 60 * 30
store_spans_timeseries(
BASE_TIME,
1,
3600,
metrics=[DummyMetric("test_metric", get_value=lambda x: 1)],
)

message = TimeSeriesRequest(
meta=RequestMeta(
project_ids=[1, 2, 3],
organization_id=1,
cogs_category="something",
referrer="something",
start_timestamp=Timestamp(seconds=int(BASE_TIME.timestamp())),
end_timestamp=Timestamp(seconds=int(BASE_TIME.timestamp() + query_duration)),
trace_item_type=TraceItemType.TRACE_ITEM_TYPE_SPAN,
),
aggregations=[
AttributeAggregation(
aggregate=Function.FUNCTION_ANY,
key=AttributeKey(type=AttributeKey.TYPE_FLOAT, name="test_metric"),
label="any",
extrapolation_mode=ExtrapolationMode.EXTRAPOLATION_MODE_NONE,
),
],
Copy link
Member

Choose a reason for hiding this comment

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

this test is basically the same thing as the test below only one is necessary

Add FUNCTION_ANY to the EAP RPC aggregation functions, enabling queries
to return any non-null value from a group. This is useful for retrieving
representative values when the specific value doesn't matter.

Changes:
- Add anyIfOrNull to both extrapolated and non-extrapolated function maps
- Skip round() for FUNCTION_ANY to support non-numeric returns
- Add proper type-based converters for FUNCTION_ANY in trace item table
- Add tests for time series, extrapolation, and string attribute scenarios

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@phacops phacops force-pushed the feat/eap-any-aggregation branch from b4acbf1 to 85b17b3 Compare January 22, 2026 20:43
@phacops phacops requested a review from volokluev January 22, 2026 21:29
Extract converter creation logic into helper functions:
- _get_converter_for_type(): Returns converter based on AttributeKey type
- _get_double_converter(): Returns converter for numeric aggregations

This reduces code duplication and improves maintainability.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@phacops phacops enabled auto-merge (squash) January 22, 2026 22:12
@phacops phacops merged commit 91a5895 into master Jan 22, 2026
34 checks passed
@phacops phacops deleted the feat/eap-any-aggregation branch January 22, 2026 22:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants