Skip to content
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

feat(sdk): Add ClientReports #2496

Merged
merged 12 commits into from
Sep 27, 2022
39 changes: 36 additions & 3 deletions src/js/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,23 @@ import { BrowserTransportOptions } from '@sentry/browser/types/transports/types'
import { FetchImpl } from '@sentry/browser/types/transports/utils';
import { BaseClient } from '@sentry/core';
import {
ClientReportEnvelope,
ClientReportItem,
Envelope,
Event,
EventHint,
SeverityLevel,
Transport,
UserFeedback,
} from '@sentry/types';
import { dateTimestampInSeconds } from '@sentry/utils';
// @ts-ignore LogBox introduced in RN 0.63
import { Alert, LogBox, YellowBox } from 'react-native';

import { defaultSdkInfo } from './integrations/sdkinfo';
import { ReactNativeClientOptions } from './options';
import { NativeTransport } from './transports/native';
import { createUserFeedbackEnvelope } from './utils/envelope';
import { createUserFeedbackEnvelope, items } from './utils/envelope';
import { NATIVE } from './wrapper';

/**
Expand Down Expand Up @@ -116,8 +120,18 @@ export class ReactNativeClient extends BaseClient<ReactNativeClientOptions> {
}

/**
* Starts native client with dsn and options
*/
* @inheritdoc
*/
protected _sendEnvelope(envelope: Envelope): void {
if (this._options.sendClientReports) {
this._attachClientReportTo(envelope as ClientReportEnvelope);
}
super._sendEnvelope(envelope);
}

/**
* Starts native client with dsn and options
*/
private async _initNativeSdk(): Promise<void> {
let didCallNativeInit = false;

Expand All @@ -144,4 +158,23 @@ export class ReactNativeClient extends BaseClient<ReactNativeClientOptions> {
);
}
}

/**
*
*/
private _attachClientReportTo(envelope: ClientReportEnvelope): void {
const outcomes = this._clearOutcomes();

if (outcomes.length > 0) {
const clientReportItem: ClientReportItem = [
{ type: 'client_report' },
{
timestamp: dateTimestampInSeconds(),
discarded_events: outcomes,
},
];

envelope[items].push(clientReportItem);
krystofwoldrich marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
1 change: 1 addition & 0 deletions src/js/sdk.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const DEFAULT_OPTIONS: ReactNativeOptions = {
transportOptions: {
textEncoder: makeUtf8TextEncoder(),
},
sendClientReports: true,
krystofwoldrich marked this conversation as resolved.
Show resolved Hide resolved
krystofwoldrich marked this conversation as resolved.
Show resolved Hide resolved
};

/**
Expand Down
3 changes: 3 additions & 0 deletions src/js/utils/envelope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import {
} from '@sentry/types';
import { createEnvelope, dsnToString } from '@sentry/utils';

export const header = 0;
export const items = 1;

/**
* Creates an envelope from a user feedback.
*/
Expand Down