Skip to content

Commit 032baa9

Browse files
committed
map statsd to metric_bucket
1 parent 129189b commit 032baa9

File tree

5 files changed

+16
-13
lines changed

5 files changed

+16
-13
lines changed

packages/core/src/transports/base.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ export function createTransport(
4949

5050
// Drop rate limited items from envelope
5151
forEachEnvelopeItem(envelope, (item, type) => {
52-
const envelopeItemDataCategory = envelopeItemTypeToDataCategory(type);
53-
if (isRateLimited(rateLimits, envelopeItemDataCategory)) {
52+
const dataCategory = envelopeItemTypeToDataCategory(type);
53+
if (isRateLimited(rateLimits, dataCategory)) {
5454
const event: Event | undefined = getEventForEnvelopeItem(item, type);
55-
options.recordDroppedEvent('ratelimit_backoff', envelopeItemDataCategory, event);
55+
options.recordDroppedEvent('ratelimit_backoff', dataCategory, event);
5656
} else {
5757
filteredEnvelopeItems.push(item);
5858
}

packages/types/src/datacategory.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// This type is used in various places like Client Reports and Rate Limit Categories
22
// See:
33
// - https://develop.sentry.dev/sdk/rate-limiting/#definitions
4-
// - https://github.com/getsentry/relay/blob/c3b339e151c1e548ede489a01c65db82472c8751/relay-common/src/constants.rs#L139-L152
4+
// - https://github.com/getsentry/relay/blob/ec791fed9c2260688f25ea6a6d53ab913927e9a5/relay-base-schema/src/data_category.rs#L91
55
// - https://develop.sentry.dev/sdk/client-reports/#envelope-item-payload under `discarded_events`
66
export type DataCategory =
77
// Reserved and only used in edgecases, unlikely to be ever actually used
@@ -26,8 +26,8 @@ export type DataCategory =
2626
| 'monitor'
2727
// Feedback type event (v2)
2828
| 'feedback'
29-
// Statsd type event for metrics
30-
| 'statsd'
29+
// Metrics sent via the statsd or metrics envelope items. `namespace` defines which namespace(s) will be affected
30+
| 'metric_bucket'
3131
// Span
3232
| 'span'
3333
// Unknown data category

packages/types/src/envelope.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ export type DynamicSamplingContext = {
3030
sampled?: string;
3131
};
3232

33+
// https://github.com/getsentry/relay/blob/311b237cd4471042352fa45e7a0824b8995f216f/relay-server/src/envelope.rs#L154
34+
// https://develop.sentry.dev/sdk/envelopes/#data-model
3335
export type EnvelopeItemType =
3436
| 'client_report'
3537
| 'user_report'

packages/utils/src/envelope.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ const ITEM_TYPE_TO_DATA_CATEGORY_MAP: Record<EnvelopeItemType, DataCategory> = {
210210
check_in: 'monitor',
211211
feedback: 'feedback',
212212
span: 'span',
213-
statsd: 'statsd',
213+
statsd: 'metric_bucket',
214214
};
215215

216216
/**
@@ -220,7 +220,7 @@ export function envelopeItemTypeToDataCategory(type: EnvelopeItemType): DataCate
220220
return ITEM_TYPE_TO_DATA_CATEGORY_MAP[type];
221221
}
222222

223-
/** Extracts the minimal SDK info from from the metadata or an events */
223+
/** Extracts the minimal SDK info from the metadata or an events */
224224
export function getSdkMetadataForEnvelopeHeader(metadataOrEvent?: SdkMetadata | Event): SdkInfo | undefined {
225225
if (!metadataOrEvent || !metadataOrEvent.sdk) {
226226
return;

packages/utils/src/ratelimit.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { TransportMakeRequestResponse } from '@sentry/types';
1+
import type { DataCategory, TransportMakeRequestResponse } from '@sentry/types';
22

33
// Intentionally keeping the key broad, as we don't know for sure what rate limit headers get returned from backend
44
export type RateLimits = Record<string, number>;
@@ -32,15 +32,15 @@ export function parseRetryAfterHeader(header: string, now: number = Date.now()):
3232
*
3333
* @return the time in ms that the category is disabled until or 0 if there's no active rate limit.
3434
*/
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;
3737
}
3838

3939
/**
4040
* Checks if a category is rate limited
4141
*/
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;
4444
}
4545

4646
/**
@@ -74,6 +74,7 @@ export function updateRateLimits(
7474
* <category>;<category>;...
7575
* <scope> is what's being limited (org, project, or key) - ignored by SDK
7676
* <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
7778
*/
7879
for (const limit of rateLimitHeader.trim().split(',')) {
7980
const [retryAfter, categories] = limit.split(':', 2);

0 commit comments

Comments
 (0)