Skip to content

Commit 668c03f

Browse files
authored
feat: Support and test Sentry.sendFeedback (#839)
1 parent e4c7597 commit 668c03f

File tree

8 files changed

+97
-12
lines changed

8 files changed

+97
-12
lines changed

src/common/normalize.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ export function normalizeEvent(event: Event, basePath: string): Event {
3434
request.url = normalizeUrlToBase(request.url, basePath);
3535
}
3636

37+
if (event.contexts?.feedback?.url && typeof event.contexts.feedback.url === 'string') {
38+
event.contexts.feedback.url = normalizeUrlToBase(event.contexts.feedback.url, basePath);
39+
}
40+
3741
event.contexts = {
3842
...event.contexts,
3943
runtime: {

src/main/ipc.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ function eventFromEnvelope(envelope: Envelope): [Event, Attachment[], Profile |
101101
let profile: Profile | undefined;
102102

103103
forEachEnvelopeItem(envelope, (item, type) => {
104-
if (type === 'event' || type === 'transaction') {
104+
if (type === 'event' || type === 'transaction' || type === 'feedback') {
105105
event = Array.isArray(item) ? (item as EventItem)[1] : undefined;
106106
} else if (type === 'attachment') {
107107
const [headers, data] = item as AttachmentItem;

test/e2e/server/index.ts

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Event, Profile, ReplayEvent, Session, Transaction } from '@sentry/types';
2-
import { forEachEnvelopeItem, parseEnvelope } from '@sentry/utils';
2+
import { dropUndefinedKeys, forEachEnvelopeItem, parseEnvelope } from '@sentry/utils';
33
import { Server } from 'http';
44
import Koa from 'koa';
55
import bodyParser from 'koa-bodyparser';
@@ -129,7 +129,12 @@ export class TestServer {
129129
let metrics: string | undefined;
130130

131131
forEachEnvelopeItem(envelope, ([headers, item]) => {
132-
if (headers.type === 'event' || headers.type === 'transaction' || headers.type === 'session') {
132+
if (
133+
headers.type === 'event' ||
134+
headers.type === 'transaction' ||
135+
headers.type === 'session' ||
136+
headers.type === 'feedback'
137+
) {
133138
data = item as Event | Transaction | Session;
134139
}
135140

@@ -155,15 +160,17 @@ export class TestServer {
155160
});
156161

157162
if (data || metrics) {
158-
this._addEvent({
159-
data: data || {},
160-
attachments,
161-
profile,
162-
metrics,
163-
appId: ctx.params.id,
164-
sentryKey: keyMatch[1],
165-
method: 'envelope',
166-
});
163+
this._addEvent(
164+
dropUndefinedKeys({
165+
data: data || {},
166+
attachments,
167+
profile,
168+
metrics,
169+
appId: ctx.params.id,
170+
sentryKey: keyMatch[1],
171+
method: 'envelope',
172+
}),
173+
);
167174

168175
ctx.status = 200;
169176
ctx.body = 'Success';
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"method": "envelope",
3+
"sentryKey": "37f8a2ee37c0409d8970bc7559c7c7e4",
4+
"appId": "277345",
5+
"data": {
6+
"contexts": {
7+
"feedback": {
8+
"contact_email": "[email protected]",
9+
"name": "John Doe",
10+
"message": "I really like your App, thanks!",
11+
"url": "app:///src/index.html",
12+
"source": "api"
13+
}
14+
},
15+
"type": "feedback"
16+
}
17+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "feedback",
3+
"version": "1.0.0",
4+
"main": "src/main.js",
5+
"dependencies": {
6+
"@sentry/electron": "3.0.0"
7+
}
8+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
description: User Feedback
2+
command: yarn
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="UTF-8" />
5+
</head>
6+
<body>
7+
<script>
8+
const crypto = require('crypto');
9+
const { init, sendFeedback } = require('@sentry/electron/renderer');
10+
11+
init({
12+
debug: true,
13+
});
14+
15+
setTimeout(() => {
16+
sendFeedback({
17+
name: 'John Doe',
18+
19+
message: 'I really like your App, thanks!',
20+
});
21+
}, 500);
22+
</script>
23+
</body>
24+
</html>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const path = require('path');
2+
3+
const { app, BrowserWindow } = require('electron');
4+
const { init } = require('@sentry/electron');
5+
6+
init({
7+
dsn: '__DSN__',
8+
debug: true,
9+
autoSessionTracking: false,
10+
onFatalError: () => {},
11+
});
12+
13+
app.on('ready', () => {
14+
const mainWindow = new BrowserWindow({
15+
show: false,
16+
webPreferences: {
17+
nodeIntegration: true,
18+
contextIsolation: false,
19+
},
20+
});
21+
22+
mainWindow.loadFile(path.join(__dirname, 'index.html'));
23+
});

0 commit comments

Comments
 (0)