Skip to content

Commit

Permalink
chore(various): Tiny fixes (#3097)
Browse files Browse the repository at this point in the history
  • Loading branch information
lobsterkatie authored Dec 4, 2020
1 parent c55294f commit 22ecbcd
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 9 deletions.
12 changes: 11 additions & 1 deletion packages/browser/src/transports/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export abstract class BaseTransport implements Transport {
* https://developer.mozilla.org/en-US/docs/Web/API/Headers/get
*/
const limited = this._handleRateLimit(headers);
if (limited) logger.warn(`Too many requests, backing off till: ${this._disabledUntil(requestType)}`);
if (limited) logger.warn(`Too many requests, backing off until: ${this._disabledUntil(requestType)}`);

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

if (rlHeader) {
// rate limit headers are of the form
// <header>,<header>,..
// where each <header> is of the form
// <retry_after>: <categories>: <scope>: <reason_code>
// where
// <retry_after> is a delay in ms
// <categories> is the event type(s) (error, transaction, etc) being rate limited and is of the form
// <category>;<category>;...
// <scope> is what's being limited (org, project, or key) - ignored by SDK
// <reason_code> is an arbitrary string like "org_quota" - ignored by SDK
for (const limit of rlHeader.trim().split(',')) {
const parameters = limit.split(':', 2);
const headerDelay = parseInt(parameters[0], 10);
Expand Down
8 changes: 7 additions & 1 deletion packages/browser/src/transports/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,13 @@ export class FetchTransport extends BaseTransport {
'x-sentry-rate-limits': response.headers.get('X-Sentry-Rate-Limits'),
'retry-after': response.headers.get('Retry-After'),
};
this._handleResponse({ requestType: sentryRequest.type, response, headers, resolve, reject });
this._handleResponse({
requestType: sentryRequest.type,
response,
headers,
resolve,
reject,
});
})
.catch(reject);
}),
Expand Down
6 changes: 3 additions & 3 deletions packages/node/src/transports/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { SDK_NAME, SDK_VERSION } from '../version';
* Internal used interface for typescript.
* @hidden
*/
export interface HTTPRequest {
export interface HTTPModule {
/**
* Request wrapper
* @param options These are {@see TransportOptions}
Expand All @@ -37,7 +37,7 @@ export interface HTTPRequest {
/** Base Transport class implementation */
export abstract class BaseTransport implements Transport {
/** The Agent used for corresponding transport */
public module?: HTTPRequest;
public module?: HTTPModule;

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

/** JSDoc */
protected async _sendWithModule(httpModule: HTTPRequest, event: Event): Promise<Response> {
protected async _sendWithModule(httpModule: HTTPModule, event: Event): Promise<Response> {
if (new Date(Date.now()) < this._disabledUntil) {
return Promise.reject(new SentryError(`Transport locked till ${this._disabledUntil} due to too many requests.`));
}
Expand Down
2 changes: 2 additions & 0 deletions packages/node/test/integrations/http.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ describe('tracing', () => {
// TODO: For some reason in node 6 two request spans are appearing. Once we stop testing against it, this can go
// back to being `toEqual()`.
expect(spans.length).toBeGreaterThanOrEqual(2);

// our span is at index 1 because the transaction itself is at index 0
expect(spans[1].description).toEqual('GET http://dogs.are.great/');
expect(spans[1].op).toEqual('request');
});
Expand Down
8 changes: 4 additions & 4 deletions packages/tracing/test/span.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ describe('Span', () => {
expect(spy.mock.calls[0][0].contexts.trace).toEqual(transaction.getTraceContext());
});

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

test('if we sampled the transaction we do not want any children', () => {
test('no span recorder created if transaction.sampled is false', () => {
const _hub = new Hub(
new BrowserClient({
tracesSampleRate: 0,
tracesSampleRate: 1,
}),
);
const spy = jest.spyOn(_hub as any, 'captureEvent') as any;
const transaction = _hub.startTransaction({ name: 'test' });
const transaction = _hub.startTransaction({ name: 'test', sampled: false });
for (let i = 0; i < 10; i++) {
const child = transaction.startChild();
child.finish();
Expand Down

0 comments on commit 22ecbcd

Please sign in to comment.