Skip to content

Commit 22ecbcd

Browse files
authored
chore(various): Tiny fixes (#3097)
1 parent c55294f commit 22ecbcd

File tree

5 files changed

+27
-9
lines changed

5 files changed

+27
-9
lines changed

packages/browser/src/transports/base.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export abstract class BaseTransport implements Transport {
6767
* https://developer.mozilla.org/en-US/docs/Web/API/Headers/get
6868
*/
6969
const limited = this._handleRateLimit(headers);
70-
if (limited) logger.warn(`Too many requests, backing off till: ${this._disabledUntil(requestType)}`);
70+
if (limited) logger.warn(`Too many requests, backing off until: ${this._disabledUntil(requestType)}`);
7171

7272
if (status === Status.Success) {
7373
resolve({ status });
@@ -100,6 +100,16 @@ export abstract class BaseTransport implements Transport {
100100
const raHeader = headers['retry-after'];
101101

102102
if (rlHeader) {
103+
// rate limit headers are of the form
104+
// <header>,<header>,..
105+
// where each <header> is of the form
106+
// <retry_after>: <categories>: <scope>: <reason_code>
107+
// where
108+
// <retry_after> is a delay in ms
109+
// <categories> is the event type(s) (error, transaction, etc) being rate limited and is of the form
110+
// <category>;<category>;...
111+
// <scope> is what's being limited (org, project, or key) - ignored by SDK
112+
// <reason_code> is an arbitrary string like "org_quota" - ignored by SDK
103113
for (const limit of rlHeader.trim().split(',')) {
104114
const parameters = limit.split(':', 2);
105115
const headerDelay = parseInt(parameters[0], 10);

packages/browser/src/transports/fetch.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,13 @@ export class FetchTransport extends BaseTransport {
6161
'x-sentry-rate-limits': response.headers.get('X-Sentry-Rate-Limits'),
6262
'retry-after': response.headers.get('Retry-After'),
6363
};
64-
this._handleResponse({ requestType: sentryRequest.type, response, headers, resolve, reject });
64+
this._handleResponse({
65+
requestType: sentryRequest.type,
66+
response,
67+
headers,
68+
resolve,
69+
reject,
70+
});
6571
})
6672
.catch(reject);
6773
}),

packages/node/src/transports/base.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { SDK_NAME, SDK_VERSION } from '../version';
1212
* Internal used interface for typescript.
1313
* @hidden
1414
*/
15-
export interface HTTPRequest {
15+
export interface HTTPModule {
1616
/**
1717
* Request wrapper
1818
* @param options These are {@see TransportOptions}
@@ -37,7 +37,7 @@ export interface HTTPRequest {
3737
/** Base Transport class implementation */
3838
export abstract class BaseTransport implements Transport {
3939
/** The Agent used for corresponding transport */
40-
public module?: HTTPRequest;
40+
public module?: HTTPModule;
4141

4242
/** The Agent used for corresponding transport */
4343
public client?: http.Agent | https.Agent;
@@ -96,7 +96,7 @@ export abstract class BaseTransport implements Transport {
9696
}
9797

9898
/** JSDoc */
99-
protected async _sendWithModule(httpModule: HTTPRequest, event: Event): Promise<Response> {
99+
protected async _sendWithModule(httpModule: HTTPModule, event: Event): Promise<Response> {
100100
if (new Date(Date.now()) < this._disabledUntil) {
101101
return Promise.reject(new SentryError(`Transport locked till ${this._disabledUntil} due to too many requests.`));
102102
}

packages/node/test/integrations/http.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ describe('tracing', () => {
4343
// TODO: For some reason in node 6 two request spans are appearing. Once we stop testing against it, this can go
4444
// back to being `toEqual()`.
4545
expect(spans.length).toBeGreaterThanOrEqual(2);
46+
47+
// our span is at index 1 because the transaction itself is at index 0
4648
expect(spans[1].description).toEqual('GET http://dogs.are.great/');
4749
expect(spans[1].op).toEqual('request');
4850
});

packages/tracing/test/span.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ describe('Span', () => {
195195
expect(spy.mock.calls[0][0].contexts.trace).toEqual(transaction.getTraceContext());
196196
});
197197

198-
test('span child limit', () => {
198+
test('maxSpans correctly limits number of spans', () => {
199199
const _hub = new Hub(
200200
new BrowserClient({
201201
_experiments: { maxSpans: 3 },
@@ -212,14 +212,14 @@ describe('Span', () => {
212212
expect(spy.mock.calls[0][0].spans).toHaveLength(3);
213213
});
214214

215-
test('if we sampled the transaction we do not want any children', () => {
215+
test('no span recorder created if transaction.sampled is false', () => {
216216
const _hub = new Hub(
217217
new BrowserClient({
218-
tracesSampleRate: 0,
218+
tracesSampleRate: 1,
219219
}),
220220
);
221221
const spy = jest.spyOn(_hub as any, 'captureEvent') as any;
222-
const transaction = _hub.startTransaction({ name: 'test' });
222+
const transaction = _hub.startTransaction({ name: 'test', sampled: false });
223223
for (let i = 0; i < 10; i++) {
224224
const child = transaction.startChild();
225225
child.finish();

0 commit comments

Comments
 (0)