-
-
Notifications
You must be signed in to change notification settings - Fork 344
feat: Add new captureFeedback API to RN SDK #4320
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
817eac8
Update the client implementation to use the new capture feedback js api
antonis 5370a99
Updates SDK API
antonis 42e2fa1
Adds new feedback button in the sample
antonis 514b102
Adds changelog
antonis 0935bbd
Removes unused mock
antonis 9ea5496
Update CHANGELOG.md
antonis da0d4ac
Directly use captureFeedback from sentry/core
antonis 3e36c6d
Use import from core
antonis 5f3df64
Fixes imports order lint issue
antonis 71b28e8
Fixes build issue
antonis f9d2b59
Adds captureFeedback tests from sentry-javascript
antonis d05d531
Update CHANGELOG.md
krystofwoldrich 2bb104b
Only deprecate client captureUserFeedback
antonis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
|
@@ -8,6 +8,26 @@ | |
|
||
## Unreleased | ||
|
||
### Features | ||
|
||
- Adds new `captureFeedback` and deprecates the `captureUserFeedback` API ([#4320](https://github.com/getsentry/sentry-react-native/pull/4320)) | ||
|
||
```jsx | ||
import * as Sentry from "@sentry/react-native"; | ||
import { SendFeedbackParams } from "@sentry/react-native"; | ||
|
||
const eventId = Sentry.captureMessage("My Message"); | ||
// OR: const eventId = Sentry.lastEventId(); | ||
|
||
const userFeedback: SendFeedbackParams = { | ||
name: "John Doe", | ||
email: "[email protected]", | ||
message: "Hello World!", | ||
associatedEventId: eventId,// Optional | ||
}; | ||
Sentry.captureFeedback(userFeedback); | ||
``` | ||
|
||
### Fixes | ||
|
||
- Return `lastEventId` export from `@sentry/core` ([#4315](https://github.com/getsentry/sentry-react-native/pull/4315)) | ||
|
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,15 @@ | ||
import * as mockedtimetodisplaynative from './tracing/mockedtimetodisplaynative'; | ||
jest.mock('../src/js/tracing/timetodisplaynative', () => mockedtimetodisplaynative); | ||
|
||
import { defaultStackParser } from '@sentry/browser'; | ||
import type { Envelope, Event, Outcome, Transport, TransportMakeRequestResponse } from '@sentry/types'; | ||
import { captureFeedback as captureFeedbackApi, defaultStackParser } from '@sentry/browser'; | ||
import type { | ||
Envelope, | ||
Event, | ||
Outcome, | ||
SendFeedbackParams, | ||
Transport, | ||
TransportMakeRequestResponse, | ||
} from '@sentry/types'; | ||
import { rejectedSyncPromise, SentryError } from '@sentry/utils'; | ||
import * as RN from 'react-native'; | ||
|
||
|
@@ -19,7 +26,6 @@ import { | |
envelopeItems, | ||
firstArg, | ||
getMockSession, | ||
getMockUserFeedback, | ||
getSyncPromiseRejectOnFirstCall, | ||
} from './testutils'; | ||
|
||
|
@@ -76,6 +82,14 @@ jest.mock( | |
}), | ||
); | ||
|
||
jest.mock('@sentry/browser', () => { | ||
const actual = jest.requireActual('@sentry/browser'); | ||
return { | ||
...actual, | ||
captureFeedback: jest.fn(), | ||
}; | ||
}); | ||
|
||
const EXAMPLE_DSN = 'https://[email protected]/148053'; | ||
|
||
const DEFAULT_OPTIONS: ReactNativeClientOptions = { | ||
|
@@ -187,15 +201,6 @@ describe('Tests ReactNativeClient', () => { | |
expect(mockTransport.send).not.toBeCalled(); | ||
}); | ||
|
||
test('captureUserFeedback does not call transport when enabled false', () => { | ||
const mockTransport = createMockTransport(); | ||
const client = createDisabledClientWith(mockTransport); | ||
|
||
client.captureUserFeedback(getMockUserFeedback()); | ||
|
||
expect(mockTransport.send).not.toBeCalled(); | ||
}); | ||
|
||
function createDisabledClientWith(transport: Transport) { | ||
return new ReactNativeClient({ | ||
...DEFAULT_OPTIONS, | ||
|
@@ -290,34 +295,25 @@ describe('Tests ReactNativeClient', () => { | |
}); | ||
|
||
describe('UserFeedback', () => { | ||
test('sends UserFeedback to native Layer', () => { | ||
const mockTransportSend: jest.Mock = jest.fn(() => Promise.resolve()); | ||
test('sends UserFeedback', () => { | ||
const client = new ReactNativeClient({ | ||
...DEFAULT_OPTIONS, | ||
dsn: EXAMPLE_DSN, | ||
transport: () => ({ | ||
send: mockTransportSend, | ||
flush: jest.fn(), | ||
}), | ||
}); | ||
jest.mock('@sentry/browser', () => ({ | ||
captureFeedback: jest.fn(), | ||
})); | ||
|
||
client.captureUserFeedback({ | ||
comments: 'Test Comments', | ||
const feedback: SendFeedbackParams = { | ||
message: 'Test Comments', | ||
email: '[email protected]', | ||
name: 'Test User', | ||
event_id: 'testEvent123', | ||
}); | ||
associatedEventId: 'testEvent123', | ||
}; | ||
|
||
expect(mockTransportSend.mock.calls[0][firstArg][envelopeHeader].event_id).toEqual('testEvent123'); | ||
expect(mockTransportSend.mock.calls[0][firstArg][envelopeItems][0][envelopeItemHeader].type).toEqual( | ||
'user_report', | ||
); | ||
expect(mockTransportSend.mock.calls[0][firstArg][envelopeItems][0][envelopeItemPayload]).toEqual({ | ||
comments: 'Test Comments', | ||
email: '[email protected]', | ||
name: 'Test User', | ||
event_id: 'testEvent123', | ||
}); | ||
client.captureFeedback(feedback); | ||
|
||
expect(captureFeedbackApi).toHaveBeenCalledWith(feedback); | ||
}); | ||
}); | ||
|
||
|
@@ -417,11 +413,6 @@ describe('Tests ReactNativeClient', () => { | |
client.captureSession(getMockSession()); | ||
expect(getSdkInfoFrom(mockTransportSend)).toStrictEqual(expectedSdkInfo); | ||
}); | ||
|
||
test('send SdkInfo in the user feedback envelope header', () => { | ||
client.captureUserFeedback(getMockUserFeedback()); | ||
expect(getSdkInfoFrom(mockTransportSend)).toStrictEqual(expectedSdkInfo); | ||
}); | ||
}); | ||
|
||
describe('event data enhancement', () => { | ||
|
This file contains hidden or 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 hidden or 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,7 +1,7 @@ | ||
import React from 'react'; | ||
import { View, StyleSheet, Text, TextInput, Image, Button } from 'react-native'; | ||
import * as Sentry from '@sentry/react-native'; | ||
import { UserFeedback } from '@sentry/react-native'; | ||
import { SendFeedbackParams, UserFeedback } from '@sentry/react-native'; | ||
|
||
export const DEFAULT_COMMENTS = "It's broken again! Please fix it."; | ||
|
||
|
@@ -48,6 +48,23 @@ export function UserFeedbackModal(props: { onDismiss: () => void }) { | |
}} | ||
/> | ||
<View style={styles.buttonSpacer} /> | ||
<Button | ||
title="Send feedback without event" | ||
color="#6C5FC7" | ||
onPress={async () => { | ||
onDismiss(); | ||
|
||
const userFeedback: SendFeedbackParams = { | ||
message: comments, | ||
name: 'John Doe', | ||
email: '[email protected]', | ||
}; | ||
|
||
Sentry.captureFeedback(userFeedback); | ||
clearComments(); | ||
}} | ||
/> | ||
<View style={styles.buttonSpacer} /> | ||
<Button | ||
title="Close" | ||
color="#6C5FC7" | ||
|
This file contains hidden or 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,7 +1,7 @@ | ||
import React from 'react'; | ||
import { View, StyleSheet, Text, TextInput, Image, Button } from 'react-native'; | ||
import * as Sentry from '@sentry/react-native'; | ||
import { UserFeedback } from '@sentry/react-native'; | ||
import { SendFeedbackParams, UserFeedback } from '@sentry/react-native'; | ||
|
||
export const DEFAULT_COMMENTS = "It's broken again! Please fix it."; | ||
|
||
|
@@ -48,6 +48,23 @@ export function UserFeedbackModal(props: { onDismiss: () => void }) { | |
}} | ||
/> | ||
<View style={styles.buttonSpacer} /> | ||
<Button | ||
title="Send feedback without event" | ||
color="#6C5FC7" | ||
onPress={async () => { | ||
onDismiss(); | ||
|
||
const userFeedback: SendFeedbackParams = { | ||
message: comments, | ||
name: 'John Doe', | ||
email: '[email protected]', | ||
}; | ||
|
||
Sentry.captureFeedback(userFeedback); | ||
clearComments(); | ||
}} | ||
/> | ||
<View style={styles.buttonSpacer} /> | ||
<Button | ||
title="Close" | ||
color="#6C5FC7" | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.