Skip to content
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

Handle namespaces for metric_bucket rate limits #1728

Merged
merged 2 commits into from
Apr 4, 2024
Merged

Conversation

cleptric
Copy link
Member

@cleptric cleptric commented Apr 3, 2024

#1726 seemed to simple to be true, and it wasn't 😬

This adds proper handling of metric namespaces. While the SDK does not support adding a namespace to a metric, Relay could reply with a X-Sentry-Rate-Limits header that could contain none custom namespaces, in which case we're still good sending our, inferred custom namespaces metrics.

Refs getsentry/team-sdks#77

@cleptric cleptric self-assigned this Apr 3, 2024
@cleptric cleptric requested review from stayallive and jan-auer April 3, 2024 21:12
@cleptric cleptric force-pushed the metrics-ratelimits branch from 31263c6 to 637b69b Compare April 3, 2024 21:15
@cleptric cleptric force-pushed the metrics-ratelimits branch from 637b69b to e8fef31 Compare April 3, 2024 21:24
src/Serializer/EnvelopItems/MetricsItem.php Outdated Show resolved Hide resolved
Comment on lines +63 to +70
/**
* $parameters[0] - retry_after
* $parameters[1] - categories
* $parameters[2] - scope (not used)
* $parameters[3] - reason_code (not used)
* $parameters[4] - namespaces (only returned if categories contains "metric_bucket").
*/
$parameters = explode(':', $limit, 5);
Copy link
Member

Choose a reason for hiding this comment

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

Can you use something like list($retry_after, $categories, ...) here to translate the comment into code? Note that the last few components are optional, though.

Copy link
Member Author

Choose a reason for hiding this comment

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

This will fail miserably, if not set 😬

Copy link
Collaborator

@stayallive stayallive Apr 4, 2024

Choose a reason for hiding this comment

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

You can append str_repeat(':', 5) to the $limit so the explode always returns at least 5 parts 😉 Missing entries will be empty strings then.

Copy link
Collaborator

@stayallive stayallive left a comment

Choose a reason for hiding this comment

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

That is a lot more complex yeah, but looks good from a distance!

@cleptric cleptric merged commit b595385 into master Apr 4, 2024
31 checks passed
@cleptric cleptric deleted the metrics-ratelimits branch April 4, 2024 22:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants