-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Sentry headers are not sent in sentry/browser, instead it is sent in query params #1992
Comments
Can you elaborate how this surfaces into an error or bug on your side? |
@HazAT Thanks for the response. https://docs.sentry.io/development/sdk-dev/overview/#authentication Hence, I expect this to be available in the SDK.. |
Yeah, I mean since this is not breaking anything right now we won't change it since we have more important things to work on. We are open to receiving PRs :) |
@HazAT Thanks 👍 |
EasyPrivacy is blocking any POST requests with Is it possible to make this configurable? I understand sending the information in headers will cause a pre-flight request.. But it's kind of essential to bypass ad-blockers when using a relay. |
@jetxr we are in the process of writing a workaround for this issue. I'll keep this issue updated once we release it. |
I'm also looking forward to this workaround.
|
The original issue seems to be outdated. As for dealing with adblockers, the solution has been shipped in Cheers! |
Hi @kamilogorek, I just tried to use this and I was unable to make it work. I get 400 Bad Request with Here's my code: async function handleRequest(request) {
const envelope = await request.text();
const pieces = envelope.split('\n', 2);
const header = JSON.parse(pieces[0]);
if (header?.dsn) {
console.log('Found DSN', header.dsn);
const dsn = new URL(header.dsn);
const projectId = parseInt(dsn.pathname.slice(1)
.split('/')[0]);
const options = {
headers: {
'Content-Type': 'text/plain;charset=UTF-8',
},
method: 'POST',
body: envelope,
};
const response = await fetch(`https://${dsn.host}/api/${projectId}/envelope/`, options);
// do something with response
}
return new Response('OK', {
headers: {
'Content-Type': 'text/plain',
'Access-Control-Allow-Origin': '*',
},
})
} Am I doing something wrong? |
@alexm92 no, I messed up, sorry about that. Fix is on it's way #3676 const parseEnvelope = (body) => {
const [envelopeHeaderString, itemHeaderString, itemString] = body.split("\n");
return {
envelopeHeader: JSON.parse(envelopeHeaderString),
itemHeader: JSON.parse(itemHeaderString),
item: JSON.parse(itemString),
};
};
async function handleRequest(request) {
const body = await request.text();
const { envelopeHeader, itemHeader, item } = parseEnvelope(body);
if (envelopeHeader.dsn) {
const dsn = new URL(header.dsn);
itemHeader.type = itemHeader.type ?? 'event';
const envelope = `${JSON.stringify(envelopeHeader)}\n${JSON.stringify(itemHeader)}\n${JSON.stringify(item)}`
const options = {
headers: {
'Content-Type': 'application/octet-stream',
},
method: 'POST',
body: envelope,
};
const response = await fetch(`https://${dsn.host}/api/${dsn.pathname}/envelope/`, options);
// do something with response
}
return new Response('OK', {
headers: {
'Content-Type': 'text/plain',
'Access-Control-Allow-Origin': '*',
},
})
} |
Awesome, thanks @kamilogorek Did some more changes and ended up using the following as serverless API on Cloudflare Workers. addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
const corsAllowedDomains = new Set([
'https://example.com',
]);
/**
* Process the envelope header sent by Sentry client
*
* @param body
* @returns {{item: any, envelopeHeader: any, itemHeader: any}}
*/
const parseEnvelope = (body) => {
const [envelopeHeaderString, itemHeaderString, itemString] = body.split("\n");
return {
envelopeHeader: JSON.parse(envelopeHeaderString),
itemHeader: JSON.parse(itemHeaderString),
item: JSON.parse(itemString),
};
};
/**
* Respond with OK or Sentry response
*
* @param {Request} request
*/
async function handleRequest(request) {
const defaultResponse = new Response('OK');
const originHeader = request.headers.get('Origin');
if (corsAllowedDomains.has(originHeader)) {
defaultResponse.headers.set('Access-Control-Allow-Origin', originHeader);
}
const body = await request.text();
const { envelopeHeader, itemHeader, item } = parseEnvelope(body);
if (envelopeHeader?.dsn) {
const dsn = new URL(envelopeHeader.dsn);
itemHeader.type = itemHeader.type ?? 'event';
const envelope = `${JSON.stringify(envelopeHeader)}\n${JSON.stringify(itemHeader)}\n${JSON.stringify(item)}`
const projectId = parseInt(dsn.pathname.slice(1).split('/')[0]);
const options = {
headers: {
'Content-Type': 'application/octet-stream',
},
method: 'POST',
body: envelope,
};
// Proxy request to Sentry ingest
const sentryResponse = await fetch(`https://${dsn.host}/api/${projectId}/envelope/`, options);
// Reconstruct the Response object to make its headers mutable.
const response = new Response(sentryResponse.body, sentryResponse);
if (corsAllowedDomains.has(originHeader)) {
response.headers.set('Access-Control-Allow-Origin', originHeader);
}
return response;
}
return defaultResponse;
} |
Thank you @alexm92 (and @kamilogorek) this tunnel is very useful. That said, I noticed that Sentry session tracking events do not send the DSN. Is that on purpose? |
Thanks for catching that @ping-localhost #3680 |
@ping-localhost @alexm92 both fixes released in You can remove this part from your code: itemHeader.type = itemHeader.type ?? 'event';
const envelope = `${JSON.stringify(envelopeHeader)}\n${JSON.stringify(itemHeader)}\n${JSON.stringify(item)}` And pass |
Package + Version
@sentry/browser
@sentry/node
raven-js
raven-node
(raven for node)Version:
Description
Though from the new sentry/browser sdk the support for sending
sentry_secret
is dropped.It is not sending the remaining query params
in headers. And there is no option to handle configure this as well.
I hope this is supported in @sentry/node.
Sample url generated in @sentry/browser is
The text was updated successfully, but these errors were encountered: