-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Rewrite transport and queue to improve memory consumption (#1795)
* fix: Limit concurrent FS calls to prevent memory fragmentation * fix: Move limiter to node, Add frameContextLines option * Update .gitignore * feat: Pass string into transport, Use request buffer directly in transport * feat: Use buffer in transport * feat: Add all changes for transport and buffers * fix: Linter * fix: Wording * fix: Don't break the API * feat: Add simple lru cache for readFiles * meta: Code Review * meta: Linter errros * fix: Changelog + docs * fix: Browser integration tests * fix: Also cache if the file wasn't readable * fix: Linter
- Loading branch information
1 parent
1fb4808
commit 1d64ace
Showing
40 changed files
with
571 additions
and
331 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,33 @@ | ||
import { SentryEvent, SentryResponse, Status } from '@sentry/types'; | ||
import { serialize } from '@sentry/utils/object'; | ||
import { SentryResponse, Status } from '@sentry/types'; | ||
import { BaseTransport } from './base'; | ||
|
||
/** `XHR` based transport */ | ||
export class XHRTransport extends BaseTransport { | ||
/** | ||
* @inheritDoc | ||
*/ | ||
public async captureEvent(event: SentryEvent): Promise<SentryResponse> { | ||
return new Promise<SentryResponse>((resolve, reject) => { | ||
const request = new XMLHttpRequest(); | ||
public async sendEvent(body: string): Promise<SentryResponse> { | ||
return this.buffer.add( | ||
new Promise<SentryResponse>((resolve, reject) => { | ||
const request = new XMLHttpRequest(); | ||
|
||
request.onreadystatechange = () => { | ||
if (request.readyState !== 4) { | ||
return; | ||
} | ||
request.onreadystatechange = () => { | ||
if (request.readyState !== 4) { | ||
return; | ||
} | ||
|
||
if (request.status === 200) { | ||
resolve({ | ||
status: Status.fromHttpCode(request.status), | ||
}); | ||
} | ||
if (request.status === 200) { | ||
resolve({ | ||
status: Status.fromHttpCode(request.status), | ||
}); | ||
} | ||
|
||
reject(request); | ||
}; | ||
reject(request); | ||
}; | ||
|
||
request.open('POST', this.url); | ||
request.send(serialize(event)); | ||
}); | ||
request.open('POST', this.url); | ||
request.send(body); | ||
}), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,7 @@ | ||
import { expect } from 'chai'; | ||
import { SentryEvent, SentryResponse, Status } from '../src'; | ||
import { Status } from '../src'; | ||
import { BrowserBackend } from '../src/backend'; | ||
import { BaseTransport } from '../src/transports'; | ||
|
||
class SimpleTransport extends BaseTransport { | ||
public async captureEvent(_: SentryEvent): Promise<SentryResponse> { | ||
return { | ||
status: Status.fromHttpCode(200), | ||
}; | ||
} | ||
} | ||
import { SimpleTransport } from './mocks/simpletransport'; | ||
|
||
const dsn = 'https://[email protected]/42'; | ||
const testEvent = { | ||
|
@@ -34,7 +26,7 @@ describe('BrowserBackend', () => { | |
} | ||
}); | ||
|
||
it('should call captureEvent() on provided transport', async () => { | ||
it('should call sendEvent() on provided transport', async () => { | ||
backend = new BrowserBackend({ dsn, transport: SimpleTransport }); | ||
const status = await backend.sendEvent(testEvent); | ||
expect(status.status).equal(Status.Success); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
import { expect } from 'chai'; | ||
import { SinonSpy, spy, stub } from 'sinon'; | ||
import { SinonSpy, spy } from 'sinon'; | ||
import { | ||
addBreadcrumb, | ||
BrowserBackend, | ||
BrowserClient, | ||
captureEvent, | ||
captureException, | ||
|
@@ -13,20 +12,21 @@ import { | |
Integrations, | ||
Scope, | ||
SentryEvent, | ||
Status, | ||
} from '../src'; | ||
import { SimpleTransport } from './mocks/simpletransport'; | ||
|
||
const dsn = 'https://[email protected]/4291'; | ||
|
||
declare var global: any; | ||
|
||
describe('SentryBrowser', () => { | ||
const beforeSend: SinonSpy = spy(); | ||
const beforeSend: SinonSpy = spy((event: SentryEvent) => event); | ||
|
||
before(() => { | ||
init({ | ||
beforeSend, | ||
dsn, | ||
transport: SimpleTransport, | ||
}); | ||
}); | ||
|
||
|
@@ -69,16 +69,6 @@ describe('SentryBrowser', () => { | |
}); | ||
|
||
describe('breadcrumbs', () => { | ||
let s: sinon.SinonStub; | ||
|
||
beforeEach(() => { | ||
s = stub(BrowserBackend.prototype, 'sendEvent').returns(Promise.resolve({ status: Status.Success })); | ||
}); | ||
|
||
afterEach(() => { | ||
s.restore(); | ||
}); | ||
|
||
it('should record breadcrumbs', async () => { | ||
addBreadcrumb({ message: 'test1' }); | ||
addBreadcrumb({ message: 'test2' }); | ||
|
@@ -90,16 +80,6 @@ describe('SentryBrowser', () => { | |
}); | ||
|
||
describe('capture', () => { | ||
let s: sinon.SinonStub; | ||
|
||
beforeEach(() => { | ||
s = stub(BrowserBackend.prototype, 'sendEvent').returns(Promise.resolve({ status: Status.Success })); | ||
}); | ||
|
||
afterEach(() => { | ||
s.restore(); | ||
}); | ||
|
||
it('should capture an exception', async () => { | ||
try { | ||
throw new Error('test'); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { SentryResponse, Status } from '../../src'; | ||
import { BaseTransport } from '../../src/transports'; | ||
|
||
export class SimpleTransport extends BaseTransport { | ||
public async sendEvent(_: string): Promise<SentryResponse> { | ||
return this.buffer.add( | ||
Promise.resolve({ | ||
status: Status.fromHttpCode(200), | ||
}), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,13 +6,13 @@ const testDsn = 'https://[email protected]/42'; | |
class SimpleTransport extends BaseTransport {} | ||
|
||
describe('BaseTransport', () => { | ||
it('doesnt provide captureEvent() implementation', async () => { | ||
it('doesnt provide sendEvent() implementation', async () => { | ||
const transport = new SimpleTransport({ dsn: testDsn }); | ||
|
||
try { | ||
await transport.captureEvent({}); | ||
await transport.sendEvent(''); | ||
} catch (e) { | ||
expect(e.message).equal('Transport Class has to implement `captureEvent` method'); | ||
expect(e.message).equal('Transport Class has to implement `sendEvent` method'); | ||
} | ||
}); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.