Repository navigation
feat(deno): Send client reports #26604
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
5958fa0
e91a6c1
b3ce84c
cf4db75
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| import type { ClientReport, Envelope } from '@sentry/core'; | ||
| import { forEachEnvelopeItem } from '@sentry/core'; | ||
| import { assertEquals } from 'https://deno.land/std@0.212.0/assert/assert_equals.ts'; | ||
| import { close, getCurrentScope, init } from '../build/esm/index.js'; | ||
| import type { DenoOptions } from '../build/esm/index.js'; | ||
| import { makeTestTransport } from './transport.ts'; | ||
|
|
||
| function initWithClientReports(options: Partial<DenoOptions> = {}): ClientReport[] { | ||
| const clientReports: ClientReport[] = []; | ||
| getCurrentScope().setClient(undefined); | ||
| init({ | ||
| dsn: 'https://233a45e5efe34c47a3536797ce15dafa@nothing.here/5650507', | ||
| defaultIntegrations: false, | ||
| beforeSend: () => null, | ||
| transport: makeTestTransport((envelope: Envelope) => { | ||
| forEachEnvelopeItem(envelope, (item, type) => { | ||
| if (type === 'client_report') { | ||
| clientReports.push(item[1] as ClientReport); | ||
| } | ||
| }); | ||
| }), | ||
| ...options, | ||
| }); | ||
| return clientReports; | ||
| } | ||
|
|
||
| async function waitForClientReport(clientReports: ClientReport[]): Promise<void> { | ||
| const deadline = Date.now() + 5_000; | ||
| while (clientReports.length === 0) { | ||
| if (Date.now() > deadline) { | ||
| throw new Error('Timed out waiting for a client report'); | ||
| } | ||
| await new Promise(resolve => setTimeout(resolve, 10)); | ||
| } | ||
| } | ||
|
|
||
| Deno.test('sends client reports on the flush interval', async () => { | ||
| const clientReports = initWithClientReports({ clientReportFlushInterval: 50 }); | ||
|
|
||
| getCurrentScope().captureMessage('dropped'); | ||
| await waitForClientReport(clientReports); | ||
|
|
||
| assertEquals( | ||
| clientReports.map(report => report.discarded_events), | ||
| [[{ reason: 'before_send', category: 'error', quantity: 1 }]], | ||
| ); | ||
|
|
||
| await close(); | ||
| }); | ||
|
|
||
| Deno.test('flushes client reports when unload fires', async () => { | ||
| const clientReports = initWithClientReports(); | ||
|
|
||
| getCurrentScope().captureMessage('dropped'); | ||
| globalThis.dispatchEvent(new Event('unload')); | ||
| await waitForClientReport(clientReports); | ||
|
|
||
| assertEquals( | ||
| clientReports.map(report => report.discarded_events), | ||
| [[{ reason: 'before_send', category: 'error', quantity: 1 }]], | ||
| ); | ||
|
|
||
| await close(); | ||
| }); | ||
|
|
||
|
sentry-junior[bot] marked this conversation as resolved.
Resolved
|
||
| Deno.test('does not send client reports when sendClientReports is false', async () => { | ||
| const clientReports = initWithClientReports({ sendClientReports: false }); | ||
|
|
||
| getCurrentScope().captureMessage('dropped'); | ||
| await close(); | ||
|
|
||
| assertEquals(clientReports, []); | ||
| }); | ||
|
cursor[bot] marked this conversation as resolved.
Resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Disable path is not actually testedMedium Severity The Triggered by project rule: PR Review Guidelines for Cursor Bot Reviewed by Cursor Bugbot for commit cf4db75. Configure here. |
||


Uh oh!
There was an error while loading. Please reload this page.