|
1 | | -import type { TransportMakeRequestResponse } from '@sentry/types'; |
| 1 | +import type { DataCategory, TransportMakeRequestResponse } from '@sentry/types'; |
2 | 2 |
|
3 | 3 | // Intentionally keeping the key broad, as we don't know for sure what rate limit headers get returned from backend |
4 | 4 | export type RateLimits = Record<string, number>; |
@@ -32,15 +32,15 @@ export function parseRetryAfterHeader(header: string, now: number = Date.now()): |
32 | 32 | * |
33 | 33 | * @return the time in ms that the category is disabled until or 0 if there's no active rate limit. |
34 | 34 | */ |
35 | | -export function disabledUntil(limits: RateLimits, category: string): number { |
36 | | - return limits[category] || limits.all || 0; |
| 35 | +export function disabledUntil(limits: RateLimits, dataCategory: DataCategory): number { |
| 36 | + return limits[dataCategory] || limits.all || 0; |
37 | 37 | } |
38 | 38 |
|
39 | 39 | /** |
40 | 40 | * Checks if a category is rate limited |
41 | 41 | */ |
42 | | -export function isRateLimited(limits: RateLimits, category: string, now: number = Date.now()): boolean { |
43 | | - return disabledUntil(limits, category) > now; |
| 42 | +export function isRateLimited(limits: RateLimits, dataCategory: DataCategory, now: number = Date.now()): boolean { |
| 43 | + return disabledUntil(limits, dataCategory) > now; |
44 | 44 | } |
45 | 45 |
|
46 | 46 | /** |
@@ -74,6 +74,8 @@ export function updateRateLimits( |
74 | 74 | * <category>;<category>;... |
75 | 75 | * <scope> is what's being limited (org, project, or key) - ignored by SDK |
76 | 76 | * <reason_code> is an arbitrary string like "org_quota" - ignored by SDK |
| 77 | + * <namespaces> Semicolon-separated list of metric namespace identifiers. Defines which namespace(s) will be affected. |
| 78 | + * Only present if rate limit applies to the metric_bucket data category. |
77 | 79 | */ |
78 | 80 | for (const limit of rateLimitHeader.trim().split(',')) { |
79 | 81 | const [retryAfter, categories] = limit.split(':', 2); |
|
0 commit comments