|  | 
| 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,15 +74,16 @@ 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. Only present if rate limit applies to the metric_bucket data category | 
| 77 | 78 |      */ | 
| 78 | 79 |     for (const limit of rateLimitHeader.trim().split(',')) { | 
| 79 |  | -      const [retryAfter, categories] = limit.split(':', 2); | 
|  | 80 | +      const [retryAfter, connectedCategories] = limit.split(':', 2); | 
| 80 | 81 |       const headerDelay = parseInt(retryAfter, 10); | 
| 81 | 82 |       const delay = (!isNaN(headerDelay) ? headerDelay : 60) * 1000; // 60sec default | 
| 82 |  | -      if (!categories) { | 
|  | 83 | +      if (!connectedCategories) { | 
| 83 | 84 |         updatedRateLimits.all = now + delay; | 
| 84 | 85 |       } else { | 
| 85 |  | -        for (const category of categories.split(';')) { | 
|  | 86 | +        for (const category of connectedCategories.split(';')) { | 
| 86 | 87 |           updatedRateLimits[category] = now + delay; | 
| 87 | 88 |         } | 
| 88 | 89 |       } | 
|  | 
0 commit comments