-
-
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.
Merge pull request #8560 from getsentry/prepare-release/7.59.0
- Loading branch information
Showing
45 changed files
with
1,000 additions
and
112 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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import type { EventItem, EventProcessor, Hub, Integration } from '@sentry/types'; | ||
import { forEachEnvelopeItem } from '@sentry/utils'; | ||
|
||
import { addMetadataToStackFrames, stripMetadataFromStackFrames } from '../metadata'; | ||
|
||
/** | ||
* Adds module metadata to stack frames. | ||
* | ||
* Metadata can be injected by the Sentry bundler plugins using the `_experiments.moduleMetadata` config option. | ||
* | ||
* When this integration is added, the metadata passed to the bundler plugin is added to the stack frames of all events | ||
* under the `module_metadata` property. This can be used to help in tagging or routing of events from different teams | ||
* our sources | ||
*/ | ||
export class ModuleMetadata implements Integration { | ||
/* | ||
* @inheritDoc | ||
*/ | ||
public static id: string = 'ModuleMetadata'; | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public name: string = ModuleMetadata.id; | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public setupOnce(addGlobalEventProcessor: (processor: EventProcessor) => void, getCurrentHub: () => Hub): void { | ||
const client = getCurrentHub().getClient(); | ||
|
||
if (!client || typeof client.on !== 'function') { | ||
return; | ||
} | ||
|
||
// We need to strip metadata from stack frames before sending them to Sentry since these are client side only. | ||
client.on('beforeEnvelope', envelope => { | ||
forEachEnvelopeItem(envelope, (item, type) => { | ||
if (type === 'event') { | ||
const event = Array.isArray(item) ? (item as EventItem)[1] : undefined; | ||
|
||
if (event) { | ||
stripMetadataFromStackFrames(event); | ||
item[1] = event; | ||
} | ||
} | ||
}); | ||
}); | ||
|
||
const stackParser = client.getOptions().stackParser; | ||
|
||
addGlobalEventProcessor(event => { | ||
addMetadataToStackFrames(stackParser, event); | ||
return event; | ||
}); | ||
} | ||
} |
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,66 @@ | ||
import type { Event } from '@sentry/types'; | ||
import { createStackParser, GLOBAL_OBJ, nodeStackLineParser, parseEnvelope } from '@sentry/utils'; | ||
import { TextDecoder, TextEncoder } from 'util'; | ||
|
||
import { createTransport, getCurrentHub, ModuleMetadata } from '../../../src'; | ||
import { getDefaultTestClientOptions, TestClient } from '../../mocks/client'; | ||
|
||
const stackParser = createStackParser(nodeStackLineParser()); | ||
|
||
const stack = new Error().stack || ''; | ||
|
||
describe('ModuleMetadata integration', () => { | ||
beforeEach(() => { | ||
TestClient.sendEventCalled = undefined; | ||
TestClient.instance = undefined; | ||
|
||
GLOBAL_OBJ._sentryModuleMetadata = GLOBAL_OBJ._sentryModuleMetadata || {}; | ||
GLOBAL_OBJ._sentryModuleMetadata[stack] = { team: 'frontend' }; | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
test('Adds and removes metadata from stack frames', done => { | ||
const options = getDefaultTestClientOptions({ | ||
dsn: 'https://username@domain/123', | ||
enableSend: true, | ||
stackParser, | ||
integrations: [new ModuleMetadata()], | ||
beforeSend: (event, _hint) => { | ||
// copy the frames since reverse in in-place | ||
const lastFrame = [...(event.exception?.values?.[0].stacktrace?.frames || [])].reverse()[0]; | ||
// Ensure module_metadata is populated in beforeSend callback | ||
expect(lastFrame?.module_metadata).toEqual({ team: 'frontend' }); | ||
return event; | ||
}, | ||
transport: () => | ||
createTransport({ recordDroppedEvent: () => undefined, textEncoder: new TextEncoder() }, async req => { | ||
const [, items] = parseEnvelope(req.body, new TextEncoder(), new TextDecoder()); | ||
|
||
expect(items[0][1]).toBeDefined(); | ||
const event = items[0][1] as Event; | ||
const error = event.exception?.values?.[0]; | ||
|
||
// Ensure we're looking at the same error we threw | ||
expect(error?.value).toEqual('Some error'); | ||
|
||
const lastFrame = [...(error?.stacktrace?.frames || [])].reverse()[0]; | ||
// Ensure the last frame is in fact for this file | ||
expect(lastFrame?.filename).toEqual(__filename); | ||
|
||
// Ensure module_metadata has been stripped from the event | ||
expect(lastFrame?.module_metadata).toBeUndefined(); | ||
|
||
done(); | ||
return {}; | ||
}), | ||
}); | ||
|
||
const client = new TestClient(options); | ||
const hub = getCurrentHub(); | ||
hub.bindClient(client); | ||
hub.captureException(new Error('Some error')); | ||
}); | ||
}); |
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,10 +6,11 @@ import type { | |
TransactionEvent, | ||
Transport, | ||
} from '@sentry/types'; | ||
import { createClientReportEnvelope, createEnvelope, dsnFromString } from '@sentry/utils'; | ||
import { TextEncoder } from 'util'; | ||
import { createClientReportEnvelope, createEnvelope, dsnFromString, parseEnvelope } from '@sentry/utils'; | ||
import { TextDecoder, TextEncoder } from 'util'; | ||
|
||
import { createTransport, getEnvelopeEndpointWithUrlEncodedAuth, makeMultiplexedTransport } from '../../../src'; | ||
import { eventFromEnvelope } from '../../../src/transports/multiplexed'; | ||
|
||
const DSN1 = 'https://[email protected]/4321'; | ||
const DSN1_URL = getEnvelopeEndpointWithUrlEncodedAuth(dsnFromString(DSN1)!); | ||
|
@@ -47,7 +48,7 @@ const CLIENT_REPORT_ENVELOPE = createClientReportEnvelope( | |
123456, | ||
); | ||
|
||
type Assertion = (url: string, body: string | Uint8Array) => void; | ||
type Assertion = (url: string, release: string | undefined, body: string | Uint8Array) => void; | ||
|
||
const createTestTransport = (...assertions: Assertion[]): ((options: BaseTransportOptions) => Transport) => { | ||
return (options: BaseTransportOptions) => | ||
|
@@ -57,7 +58,10 @@ const createTestTransport = (...assertions: Assertion[]): ((options: BaseTranspo | |
if (!assertion) { | ||
throw new Error('No assertion left'); | ||
} | ||
assertion(options.url, request.body); | ||
|
||
const event = eventFromEnvelope(parseEnvelope(request.body, new TextEncoder(), new TextDecoder()), ['event']); | ||
|
||
assertion(options.url, event?.release, request.body); | ||
resolve({ statusCode: 200 }); | ||
}); | ||
}); | ||
|
@@ -111,6 +115,21 @@ describe('makeMultiplexedTransport', () => { | |
await transport.send(ERROR_ENVELOPE); | ||
}); | ||
|
||
it('DSN and release can be overridden via match callback', async () => { | ||
expect.assertions(2); | ||
|
||
const makeTransport = makeMultiplexedTransport( | ||
createTestTransport((url, release) => { | ||
expect(url).toBe(DSN2_URL); | ||
expect(release).toBe('[email protected]'); | ||
}), | ||
() => [{ dsn: DSN2, release: '[email protected]' }], | ||
); | ||
|
||
const transport = makeTransport({ url: DSN1_URL, ...transportOptions }); | ||
await transport.send(ERROR_ENVELOPE); | ||
}); | ||
|
||
it('match callback can return multiple DSNs', async () => { | ||
expect.assertions(2); | ||
|
||
|
Oops, something went wrong.