Skip to content

(wip): misc(frontend): Add a useTimeseries hook #89417

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from

Conversation

colin-sentry
Copy link
Member

Legal Boilerplate

Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. and is gonna need some rights from me in order to utilize my contributions in this here PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms.

@github-actions github-actions bot added the Scope: Frontend Automatically applied to PRs that change frontend components label Apr 11, 2025
Copy link
Member

@gggritso gggritso left a comment

Choose a reason for hiding this comment

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

Right on, thanks for starting this off! It needs a bunch of changes, but mostly minor

@wmak there are a few things still with strange casing, is it too late to change them?

Comment on lines +6 to +8
/**
* Row represents a point in a timeseries - plotting (timestamp, value) with a line between them would represent a line chart.
*/
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this is even needed

/**
* Row represents a point in a timeseries - plotting (timestamp, value) with a line between them would represent a line chart.
*/
export interface Row {
Copy link
Member

Choose a reason for hiding this comment

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

This is more of a general note, but could you align this a little more with the existing TimeSeries types? e.g., this should be called TimeSeriesItem, SeriesMeta should be called TimeSeriesMeta, etc.

timestamp: number;

/** value: The float value of this point in the time series (i.e., how high it is in the graph) */
value: number;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
value: number;
value: number | null;

*/
export interface SeriesMeta {
/** valueType: The type of the unit, e.g., 'duration' or 'size' */
valueType: string;
Copy link
Member

Choose a reason for hiding this comment

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

This should be a string union of the known types, you can copy AttributeValueType from TimeSeries, or import it

order?: number;

/** valueUnit: The unit of this chart, e.g., 'microsecond' */
valueUnit?: string;
Copy link
Member

Choose a reason for hiding this comment

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

This should be a union of the known units, you can copy TimeSeriesValueUnit from TimeSeries or import it

field?: string[];

/** The keys to order by, e.g., -count() */
orderby?: string[];
Copy link
Member

Choose a reason for hiding this comment

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

😭 is it too late to make this orderBy?

},
},
],
{}
Copy link
Member

Choose a reason for hiding this comment

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

This needs a little more configuration.

  1. Retries for 409s, with a falloff (doDiscoverQuery does this)
  2. Intelligent staleTime (useSpansQuery does this)

timeseries: TimeSeries[];
}

export interface UseTimeseriesProps {
Copy link
Member

Choose a reason for hiding this comment

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

This needs a mandatory referrer parameter, please!

yAxis?: string[];
}

export function useTimeseries(props: UseTimeseriesProps) {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe useDiscoverTimeSeries or useEAPTimeSeries? useTimeseries is not specific enough

const {selection} = usePageFilters();
const {start: pageFilterStart, end: pageFilterEnd} = selection.datetime;
const organization = useOrganization();
return useApiQuery<StatsResponse>(
Copy link
Member

Choose a reason for hiding this comment

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

Please do a small transformation here, and convert the timeseries in the response into TimeSeries as defined in the widget code. You'll have to do that anyway to plot it, and I don't want yet another data format getting passed around.

It'll be easy, you'll need to concatenate the groupBy and yaxis into a field, convert the timestamps into strings and ... I think that's it actually?

I'll slowly chip away at aligning this time series with TimeSeries in the near future

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Scope: Frontend Automatically applied to PRs that change frontend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants