-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Feedback widget with screenshot via tunnelling not working #16112
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
Comments
hey, I guess the tunnel is not handling attachments properly 🤔 cc @ryan953 or @AbhiPrasad any idea how the tunnel has to be adjusted so that tunneling an attachment would work? |
attachments should work afaik, we shouldn't do anything with the envelope. @timfish do any problems here ring a bell for you? |
I think the issue is that you can't safely convert entire envelopes containing non-text attachments to a string like this: const envelopeBytes = await request.arrayBuffer();
const envelope = new TextDecoder().decode(envelopeBytes); You need to slice the header from the envelope at the first newline in bytes before converting in to text: export const POST: RequestHandler = async ({ request }) => {
try {
const envelopeBytes = new Uint8Array(await req.arrayBuffer());
const headerEnd = envelopeBytes.indexOf(0x0a); // Find the first newline
const headerBytes = envelopeBytes.subarray(0, headerEnd);
const header = JSON.parse(new TextDecoder().decode(headerBytes));
const dsn = new URL(header['dsn']);
const project_id = dsn.pathname?.replace('/', '');
if (dsn.hostname !== SENTRY_HOST) {
throw new Error(`Invalid sentry hostname: ${dsn.hostname}`);
} |
I'll test the code changes above and make the appropriate changes to the docs where that code sample comes from: |
@timfish thank you for helping, but I still getting same error after changed the code export const POST: RequestHandler = async ({ request }) => {
try {
const envelopeBytes = new Uint8Array(await request.arrayBuffer());
const headerEnd = envelopeBytes.indexOf(0x0a); // Find the first newline
const headerBytes = envelopeBytes.subarray(0, headerEnd);
const header = JSON.parse(new TextDecoder().decode(headerBytes));
const dsn = new URL(header['dsn']);
const project_id = dsn.pathname?.replace('/', '');
if (dsn.hostname !== SENTRY_HOST) {
throw new Error(`Invalid sentry hostname: ${dsn.hostname}`);
}
if (!project_id || !SENTRY_PROJECT_IDS.includes(project_id)) {
throw new Error(`invalid sentry project id: ${project_id}`);
}
const upstream_sentry_url = `https://${SENTRY_HOST}/api/${project_id}/envelope/`;
await fetch(upstream_sentry_url, {
method: 'POST',
body: envelopeBytes
});
return json({ status: 200 });
} catch (e) {
logger.error('error tunneling to sentry', e);
return json({ error: 'error tunneling to sentry' }, { status: 500 });
}
}; ERROR: error tunneling to sentry:
SyntaxError: Unexpected end of JSON input |
Looks like I need to do more testing! |
@anatoliy-t7 can you share a project that reproduces this error or log the result of |
@timfish Without a screenshot: TUNNEL LOG of new TextDecoder().decode(headerBytes) -> {"event_id":"9c3b730f7fc749f492678f137cc781a9","sent_at":"2025-04-24T10:26:29.807Z","sdk":{"name":"sentry.javascript.sveltekit","version":"9.13.0"},"dsn":"hidden","trace":{"environment":"dev","release":"dev","public_key":"hidden","trace_id":"1003740a940c7217cbadb09f8da0a1a4","transaction":"GET /(protected)/surveys","sampled":"true","sample_rand":"0.6976181215617028","sample_rate":"1"}}
2025-04-24 10:26:34.877 ERROR /src/hooks.server.ts:59 dev handle error {
status: 500,
message: 'Internal Error',
error: SyntaxError: Unexpected end of JSON input With a screenshot: 2025-04-24 10:28:56.447 ERROR /src/hooks.server.ts:59 dev handle error {
status: 500,
message: 'Internal Error',
error: SyntaxError: Unexpected end of JSON input |
@anatoliy-t7 can you please also share the content of |
@tcurdt log on |
No idea what's going on here, doesn't make much sense on the surface. If you can supply a reproduction I can take a look and debug it! |
@timfish since it sounds like the frontend code is not even reaching the tunnel - maybe you could just have a look on our test environment? If that's an option we can enable the feedback widget. |
Sounds like a plan. |
It's also worth noting that in my testing it looks like the tunnel endpoint gets instrumented by Sentry. If transactions are being captured for these incoming requests you're going to have a server transaction for every frontend envelope sent! |
You mean the transaction itself will also show up in sentry? |
Right ... but wasn't there a way to remove some of those?
|
Yes, you can manually filter these out via We are planning some improvements to the tunnel option, including making it simpler and more streamlined to setup. Filtering out these transactions automatically can go on that list! |
First tests show this to be working. I'll wait for some more testing. Thanks for your help! |
Thanks for the response! I added the |
Is there an existing issue for this?
How do you use Sentry?
Sentry Saas (sentry.io)
Which SDK are you using?
@sentry/sveltekit
SDK Version
9.13.0
Framework Version
2.20.7
Link to Sentry event
No response
Reproduction Example/SDK Setup
src/hooks.client.ts
src/routes/(public)/sentry/+server.ts
Steps to Reproduce
Expected Result
A feedback should reach sentry with a screenshot attached
Actual Result
Unable to send Feedback. This could be because of network issues, or because you are using an ad-blocker
SyntaxError Unexpected end of JSON input
Sentry gets a feedback without a screenshot, but a tunnel backend endpoint gets error from sentry response too
SyntaxError Unexpected end of JSON input
The text was updated successfully, but these errors were encountered: