-
-
Notifications
You must be signed in to change notification settings - Fork 344
chore(feedback): Update the samples with an attachment/tags example #4322
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
krystofwoldrich
merged 25 commits into
main
from
antonis/3859-newCaptureFeedbackAPI-hint
Dec 2, 2024
Merged
Changes from 10 commits
Commits
Show all changes
25 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 fc22384
Adds event hint
antonis 8b55e8a
Updates samples
antonis cd178f4
Updates changelog
antonis 8a7018e
Fix lint issue
antonis fa41526
Updates changelog
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 0e54497
Merge branch 'antonis/3859-newCaptureFeedbackAPI' into antonis/3859-n…
antonis 8428d38
Removes unused import
antonis bd027d8
Removes unneeded PR from changelog
antonis d05d531
Update CHANGELOG.md
krystofwoldrich 2bb104b
Only deprecate client captureUserFeedback
antonis dd4be93
Merge branch 'antonis/3859-newCaptureFeedbackAPI' into antonis/3859-n…
antonis 3ec17bd
Upload a simple textfile
antonis 70ce204
Merge branch 'main' into antonis/3859-newCaptureFeedbackAPI-hint
antonis a3a83bd
Update CHANGELOG.md
krystofwoldrich 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,36 @@ | |
|
||
## Unreleased | ||
|
||
### Features | ||
|
||
- Adds new `captureFeedback` and deprecates the `captureUserFeedback` API ([#4320](https://github.com/getsentry/sentry-react-native/pull/4320), [#4322](https://github.com/getsentry/sentry-react-native/pull/4322)) | ||
|
||
```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, { | ||
captureContext: { | ||
tags: { 'tag-key': 'tag-value' }, | ||
}, | ||
attachments: [ | ||
{ | ||
filename: 'screenshot.png', | ||
data: 'base64-encoded-image', | ||
}, | ||
], | ||
}); | ||
``` | ||
|
||
### 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,58 @@ 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', | ||
}; | ||
|
||
client.captureFeedback(feedback); | ||
|
||
expect(captureFeedbackApi).toHaveBeenCalledWith(feedback, undefined); | ||
}); | ||
|
||
test('sends UserFeedback with hint', () => { | ||
const client = new ReactNativeClient({ | ||
...DEFAULT_OPTIONS, | ||
dsn: EXAMPLE_DSN, | ||
}); | ||
jest.mock('@sentry/browser', () => ({ | ||
captureFeedback: jest.fn(), | ||
})); | ||
|
||
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', | ||
const feedback: SendFeedbackParams = { | ||
message: 'Test Comments', | ||
email: '[email protected]', | ||
name: 'Test User', | ||
event_id: 'testEvent123', | ||
}); | ||
associatedEventId: 'testEvent123', | ||
}; | ||
|
||
const hint = { | ||
captureContext: { | ||
tags: { testtag: 'testvalue' }, | ||
}, | ||
attachments: [ | ||
{ | ||
filename: 'screenshot.png', | ||
data: 'base64Image', | ||
}, | ||
], | ||
}; | ||
|
||
client.captureFeedback(feedback, hint); | ||
|
||
expect(captureFeedbackApi).toHaveBeenCalledWith(feedback, hint); | ||
}); | ||
}); | ||
|
||
|
@@ -417,11 +446,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,53 @@ 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="Send feedback with attachment and tags" | ||
color="#6C5FC7" | ||
onPress={async () => { | ||
onDismiss(); | ||
|
||
const base64Image = | ||
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/wcAAgUBA+kZYq8AAAAASUVORK5CYII='; | ||
|
||
const userFeedback: SendFeedbackParams = { | ||
message: comments, | ||
name: 'John Doe', | ||
email: '[email protected]', | ||
}; | ||
|
||
Sentry.captureFeedback(userFeedback, { | ||
captureContext: { | ||
tags: { testtag: 'testvalue' }, | ||
}, | ||
attachments: [ | ||
{ | ||
filename: 'screenshot.png', | ||
data: base64Image, | ||
}, | ||
], | ||
}); | ||
clearComments(); | ||
}} | ||
/> | ||
<View style={styles.buttonSpacer} /> | ||
<Button | ||
title="Close" | ||
color="#6C5FC7" | ||
|
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just an one pixel image. I avoided to add extra library dependencies to handle a real image attachment at this point for simplicity. This sample will be enhanced along with the capture feedback UI implementation #4302
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For simplicity avoiding extra lib is okay. I'm not sure if this will get correctly recognized in Sentry.
The data type is
UInt8Array | string
, but when string is used it's expected the string is the raw data.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's check if the image is correctly processed if not, we can just bake in here the UInt8Array.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This example is not working - the file attached on sentry is just a text file with base64
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the feedback @radiodario 🙇
That is true. We currently support only raw data attachments (updated code, User Feedback API documentation). In order to upload an image you need to pass a
Uint8Array
in thedata
field.Alternatively you may Integrate with an Image Picker Library or Implementing the
onAddScreenshot
Callback.