-
-
Save ndmanvar/7ae7b4db7bf1cda30545c1480fde77fe to your computer and use it in GitHub Desktop.
'use strict'; | |
var request = require('request'); | |
function HTTPSProxyTransport() {} | |
HTTPSProxyTransport.prototype.send = function (client, message, headers, eventId, cb) { | |
var options = { | |
url: 'https://' + client.dsn.host + client.dsn.path + 'api/' + client.dsn.project_id + '/store/', | |
headers: headers, | |
method: 'POST', | |
ca: client.ca, | |
body: message | |
}; | |
request(options, function (error, response, body) { | |
if (!error && response.statusCode == 200 && response.statusCode < 300) { | |
client.emit('logged', eventId); | |
cb && cb(null, eventId); | |
} else { | |
var reason = response.headers['x-sentry-error']; | |
var e = new Error('HTTP Error (' + response.statusCode + '): ' + reason); | |
e.response = response; | |
e.statusCode = response.statusCode; | |
e.reason = reason; | |
e.sendMessage = message; | |
e.requestHeaders = headers; | |
e.eventId = eventId; | |
client.emit('error', e); | |
cb && cb(e); | |
} | |
}); | |
}; | |
module.exports.HTTPSProxyTransport = HTTPSProxyTransport; |
Thanks for sharing this code!
I think there's a minor bug in the if statement:
https://gist.github.com/ndmanvar/7ae7b4db7bf1cda30545c1480fde77fe#file-customtransport-js-L16
It should be:
if (!error && response.statusCode >= 200 && response.statusCode < 300) {
Yeah, you're right!!
Hi Laurent!
We are in progress of rewriting our SDKs. I will surface this request/ask to our dev team and see what the answer/reply is here.
New upcoming JS SDK (in case you want to keep track / dig in): https://github.com/getsentry/sentry-javascript
Also, thank @tyiu for finding the bug and suggesting the fix!
-Neil
Is there a similar solution to LaurentGoderre fix for the latest JS SDK? Where is transport config modified now @ndmanvar ?
Hi @timwaddell
There is now native support for proxies in JS + Node SDKs
- https://docs.sentry.io/learn/configuration/?platform=browser#http-proxy
- https://docs.sentry.io/learn/configuration/?platform=node#http-proxy
You can also specify transport if you would like as well: https://docs.sentry.io/learn/configuration/?platform=node#transport
Thanks @ndmanvar
I can see it's in the docs but can't see any implementation on the latest master? Can you point me to whereabouts if so?
@timwaddell we missed it, my bad. Here's a PR for it - getsentry/sentry-javascript#1761
Coming in the next release.
Using this syntax
You can do:
or