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
8.26.0
Framework Version
Sveltekit 2.5.18
Link to Sentry event
No response
Reproduction Example/SDK Setup
Using the example provided from the documentation does not work with replay requests. The docs show using an array buffer. This works well with traces, however for replays the code error on parsing piece. In this case the envelopeBytes is 0 and envelope empty.
https://docs.sentry.io/platforms/javascript/troubleshooting/#dealing-with-ad-blockers
constSENTRY_HOST="oXXXXXX.ingest.sentry.io";constSENTRY_PROJECT_IDS=["123456"];exportconstPOST: RequestHandler=async({ request })=>{try{constenvelopeBytes=awaitrequest.arrayBuffer();constenvelope=newTextDecoder().decode(envelopeBytes);console.log(envelopeBytes,envelope);constpiece=envelope.split('\n')[0];constheader=JSON.parse(piece);constdsn=newURL(header['dsn']);constproject_id=dsn.pathname?.replace('/','');if(dsn.hostname!==SENTRY_HOST){thrownewError(`Invalid sentry hostname: ${dsn.hostname}`);}if(!project_id||!SENTRY_PROJECT_IDS.has(project_id)){thrownewError(`Invalid sentry project id: ${project_id}`);}constupstream_sentry_url=`https://${SENTRY_HOST}/api/${project_id}/envelope/`;awaitfetch(upstream_sentry_url,{method: 'POST',body: envelopeBytes,});returnjson({},{status: 200});}catch(error){console.error('error tunneling to sentry',error);returnjson({error: 'error tunneling to sentry'},{status: 500});}};Steps to Reproduce
- Create an API route, eg
/api/errors/+server.ts. - Export a POST api.
- Configure sentry client to tunnel through
/api/errors.
Expected Result
The replays get sent to sentry successfully.
Actual Result
Traces are tunneled. Replays result in this error:
// console.log(envelopeBytes, envelope);ArrayBuffer{[Uint8Contents]: <>, byteLength: 0 }errortunnelingtosentrySyntaxError: UnexpectedendofJSONinputatJSON.parse(<anonymous>)
at POST (/src/routes/api/errors/+server.ts:17:25)
at async Module.render_endpoint (/node_modules/.pnpm/@sveltejs+kit@2.5.18_@sveltejs+vite-plugin-svelte@3.1.1_svelte@4.2.18_vite@5.3.3_@types+node@_l5lnugt2i4tpym4dqtslohvg24/node_modules/@sveltejs/kit/src/runtime/server/endpoint.js:49:18)
at async resolve (/node_modules/.pnpm/@sveltejs+kit@2.5.18_@sveltejs+vite-plugin-svelte@3.1.1_svelte@4.2.18_vite@5.3.3_@types+node@_l5lnugt2i4tpym4dqtslohvg24/node_modules/@sveltejs/kit/src/runtime/server/respond.js:454:17)
at async documentPolicy (/src/lib/hooks/document-policy.ts:6:20)
at async /node_modules/.pnpm/@sentry+sveltekit@8.26.0_@opentelemetry+api@1.9.0_@opentelemetry+core@1.25.1_@opentelemetry+a_gixmxtpq6bgq6uyfpgkkbh5rvy/node_modules/@sentry/sveltekit/build/cjs/server/handle.js:140:21
at async instrumentHandle (/node_modules/.pnpm/@sentry+sveltekit@8.26.0_@opentelemetry+api@1.9.0_@opentelemetry+core@1.25.1_@opentelemetry+a_gixmxtpq6bgq6uyfpgkkbh5rvy/node_modules/@sentry/sveltekit/build/cjs/server/handle.js:128:27)
at async Module.respond (/node_modules/.pnpm/@sveltejs+kit@2.5.18_@sveltejs+vite-plugin-svelte@3.1.1_svelte@4.2.18_vite@5.3.3_@types+node@_l5lnugt2i4tpym4dqtslohvg24/node_modules/@sveltejs/kit/src/runtime/server/respond.js:330:20)
at async file:///node_modules/.pnpm/@sveltejs+kit@2.5.18_@sveltejs+vite-plugin-svelte@3.1.1_svelte@4.2.18_vite@5.3.3_@types+node@_l5lnugt2i4tpym4dqtslohvg24/node_modules/@sveltejs/kit/src/exports/vite/dev/index.js:524:22
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
8.26.0
Framework Version
Sveltekit 2.5.18
Link to Sentry event
No response
Reproduction Example/SDK Setup
Using the example provided from the documentation does not work with replay requests. The docs show using an array buffer. This works well with traces, however for replays the code error on parsing
piece. In this case theenvelopeBytesis 0 andenvelopeempty.https://docs.sentry.io/platforms/javascript/troubleshooting/#dealing-with-ad-blockers
Steps to Reproduce
/api/errors/+server.ts./api/errors.Expected Result
The replays get sent to sentry successfully.
Actual Result
Traces are tunneled. Replays result in this error: