You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, we have a web app with offline capabilities deployed, and it would be great to use Sentry for the application monitoring. We already use it for our back end and it works great!
Unfortunately i don't see support in raven js for this, so i think that we would be forced to roll out our own solution. Can you confirm this? What would be your suggestions about how to proceed? Would you recommend trying to reuse some logic from raven js?
Reacted by Iuri de Silvio, Mathieu Maes, Olivier Tassinari, Sergey Korochansky, Steve Shaffer, Shannon Skinner, Ricardo Seromenho, Sébastien Lorber, Nicolas PENNEC, C-A de Salaberry and 1 more
Great, thanks for the collaboration. I could detect the user being online even just testing Sentry reachability. For this i could listen the transmission failure events, but then how to retry?
About using captureException, that would be fine, but i would like to keep the excellent handler raven provides for unhandled exceptions. I would need to add some middle logic between raven error detection and error transmission
Yeah, lemme think about this. I think there's a nice way that we can either just support this automatically in raven-js, or provide a hook to do it. I think that's fair.
I'm looking for the same funtionality as well. After examining the docs it seems that a work around could be to use shouldSendCallback, something like this:
This is piggybacking a bit, but I have a similar issue. We can't report errors when the client loses connection to the host (though they are not necessarily offline). Trolling around, I see that there's a ravenFailure event being triggered on the window, but I can't get enough data from this event to accomplish what I'm trying to do: retry sending the error on failure.
I see a few possible approaches to this:
A per-instance or per-message retry option, which might specify how often to retry sending events, how many times to try before giving up, etc.
A callback/callback(s) on the captureException(),sendMessage()`, etc. methods which is/are triggered on success/failure
Promisifying those methods (meh)
Triggering events (where?) on failure and providing enough context in the event data to attempt a re-send of that event
You should probably have an offline storage facility so the error messages can be sent later in time. Possibly even after the user closes the app and later reopens it while online. Similar to an "offline first" approach: http://offlinefirst.org/
I have faced the same issue. At first, I wanted to solve it similarly to how I'm solving the offline google-analytics issue with a service worker. The approach is well explained by Google here.
However, when targeting Cordova, Service Worker might not be available.
And a hackysolution is needed. I have came up with this one:
I agree with @webberig. I was actually a little surprised this wasn't already part of raven since it's pretty impressive in a lot of other cool ways. Depending on an app's architecture, there could potentially be a non-trivial percentage of the errors that are the RESULT of being offline. Being able to report on those is pretty critical in a lot of implementations.
So my vote is that this should be baked in and automatic. When there's an error sending the message to sentry, the message should be stored and tried again later (either on a timer, on an event, or even just on the next message transmission if you want to keep it simple).
I was actually a little surprised this wasn't already part of raven since it's pretty impressive in a lot of other cool ways. Depending on an app's architecture, there could potentially be a non-trivial percentage of the errors that are the RESULT of being offline.
Totally fair. But I'm not sure it should be done by default. There are many scenarios where, if a script doesn't load, the app isn't going to work no matter what. And I would say most apps just straight-up don't work offline, and don't expect to. Whether that's good practice or not is another thing.
It's sort of why we don't log AJAX errors by default, even though a good chunk of Raven users have written code to do so. But we'll try to make it easy to do so if you want. And I'd like to do the same thing here.
But we'll try to make it easy to do so if you want. And I'd like to do the same thing here.
So, in the interest of helping make a design decision, here's some thoughts:
If I'm understanding the docs correctly, the transport config option allows one to basically take control of the last part of the pipeline where Sentry sends the data to the server and become responsible for making that transmission happen. In that case, that seems like the best place to plugin an offline queue. Instead of sending the data to the server, send it to a queue that uploads to the server in the background. That would be if someone were writing their own code to make it happen.
In a similar vein, would it be simple enough to also expose a config option (includeOffline?) that would replace the default HTTP transport with an official Raven-rolled offline-capable queue?
For browser compatibility, maybe store the queue in localStorage and have it check for connection on a timeout.
For better performance and stability, maybe leverage service workers to manage the queue so errors could even be uploaded after the page is closed. But is it a little presumptuous for a utility library to be spinning up its own service workers at this point?
@Freundschaft No, not yet. As I understand it, for now you'll have to override the transport option or use the shouldSendCallback to build a queue for sending later.
If there is no connection, out logStorageService will save the event's data
varoptions={
...
shouldSendCallback: function(data){if(connectionStatus.check()&&Raven.isSetup()){returntrue;}else{// store log data somewherelogStorageService.set(data);returnfalse;}}...};Raven.config(SENTRY_KEY,options).install();
Queue trying to send logs
Queue fires this code every 25 seconds, eventually delivering all of the events to Sentry
I ran into a need for this today as I have an offline capable feature. I store all my own data using indexdb but it would be nice to have an out of the box offline functionality for Sentry. If it it could use it's own local database to store events and periodically/on network changes attempt to send and clear out the db that would be super useful.
If I do store exceptions for sending later when I come online, is there a way for me to set the timestamp on the exceptions to indicate that they didn't happen now when I'm sending them to sentry, but at some point in the past? I guess I could just add it in the extra, but it would be nice to be able to set the actual timestamp.
Activity
mattrobenolt commentedon Oct 31, 2014
Can you detect if the user is offline?
If so, it wouldn't be impossible to collect events and queue them up. When the user gets back online, send them through
Raven.captureExceptionagain.I can probably help with how that'd work or add a hook in to help this.
danse commentedon Oct 31, 2014
Great, thanks for the collaboration. I could detect the user being online even just testing Sentry reachability. For this i could listen the transmission failure events, but then how to retry?
About using
captureException, that would be fine, but i would like to keep the excellent handler raven provides for unhandled exceptions. I would need to add some middle logic between raven error detection and error transmissionmattrobenolt commentedon Oct 31, 2014
Yeah, lemme think about this. I think there's a nice way that we can either just support this automatically in raven-js, or provide a hook to do it. I think that's fair.
lauritzen commentedon Jan 3, 2015
I'm looking for the same funtionality as well. After examining the docs it seems that a work around could be to use
shouldSendCallback, something like this:And then listen for network connectivity and process the queue using
Raven.captureException:window.addEventListener('online', checkAndProcessQueue);cappslock commentedon Sep 25, 2015
This is piggybacking a bit, but I have a similar issue. We can't report errors when the client loses connection to the host (though they are not necessarily offline). Trolling around, I see that there's a
ravenFailureevent being triggered on the window, but I can't get enough data from this event to accomplish what I'm trying to do: retry sending the error on failure.I see a few possible approaches to this:
retryoption, which might specify how often to retry sending events, how many times to try before giving up, etc.captureException(),sendMessage()`, etc. methods which is/are triggered on success/failurewebberig commentedon May 18, 2016
You should probably have an offline storage facility so the error messages can be sent later in time. Possibly even after the user closes the app and later reopens it while online. Similar to an "offline first" approach:
http://offlinefirst.org/
oliviertassinari commentedon Jun 27, 2016
I have faced the same issue. At first, I wanted to solve it similarly to how I'm solving the offline google-analytics issue with a service worker. The approach is well explained by Google here.
However, when targeting Cordova, Service Worker might not be available.
And a hacky solution is needed. I have came up with this one:
https://gist.github.com/oliviertassinari/73389727fe58373eef7b63d2d2c5ce5d
cudasteve commentedon Jun 27, 2016
I agree with @webberig. I was actually a little surprised this wasn't already part of raven since it's pretty impressive in a lot of other cool ways. Depending on an app's architecture, there could potentially be a non-trivial percentage of the errors that are the RESULT of being offline. Being able to report on those is pretty critical in a lot of implementations.
So my vote is that this should be baked in and automatic. When there's an error sending the message to sentry, the message should be stored and tried again later (either on a timer, on an event, or even just on the next message transmission if you want to keep it simple).
Also, what's the "DDN" label mean?
benvinegar commentedon Jun 27, 2016
Totally fair. But I'm not sure it should be done by default. There are many scenarios where, if a script doesn't load, the app isn't going to work no matter what. And I would say most apps just straight-up don't work offline, and don't expect to. Whether that's good practice or not is another thing.
It's sort of why we don't log AJAX errors by default, even though a good chunk of Raven users have written code to do so. But we'll try to make it easy to do so if you want. And I'd like to do the same thing here.
Not sure. @mattrobenolt?
mattrobenolt commentedon Jun 27, 2016
Design decision needed. :)
cudasteve commentedon Jun 29, 2016
Ya that makes sense.
So, in the interest of helping make a design decision, here's some thoughts:
If I'm understanding the docs correctly, the
transportconfig option allows one to basically take control of the last part of the pipeline where Sentry sends the data to the server and become responsible for making that transmission happen. In that case, that seems like the best place to plugin an offline queue. Instead of sending the data to the server, send it to a queue that uploads to the server in the background. That would be if someone were writing their own code to make it happen.In a similar vein, would it be simple enough to also expose a config option (
includeOffline?) that would replace the default HTTP transport with an official Raven-rolled offline-capable queue?Freundschaft commentedon Jul 27, 2016
has this functionality now been built in somehow to raven?
cudasteve commentedon Jul 27, 2016
@Freundschaft No, not yet. As I understand it, for now you'll have to override the
transportoption or use theshouldSendCallbackto build a queue for sending later.Freundschaft commentedon Jul 27, 2016
@cudasteve thanks!
someone got a working sample implementation? if not I'll try to write one and post it here
3 remaining items
peresbruno commentedon Sep 29, 2016
+1
ddddm commentedon Sep 30, 2016
Our solution:
Pass
shouldSendCallbackto Raven initIf there is no connection, out logStorageService will save the event's data
Queue trying to send logs
Queue fires this code every 25 seconds, eventually delivering all of the events to Sentry
panbhag commentedon May 18, 2017
Has this feature been added to the library yet.
alexcroox commentedon Nov 17, 2017
I ran into a need for this today as I have an offline capable feature. I store all my own data using indexdb but it would be nice to have an out of the box offline functionality for Sentry. If it it could use it's own local database to store events and periodically/on network changes attempt to send and clear out the db that would be super useful.
kamilogorek commentedon Jan 18, 2018
Addressed here #1165
Add an offline integration for offline errors
Add an integration for offline errors
Add an integration for offline errors
nbrustein commentedon May 14, 2020
If I do store exceptions for sending later when I come online, is there a way for me to set the timestamp on the exceptions to indicate that they didn't happen now when I'm sending them to sentry, but at some point in the past? I guess I could just add it in the extra, but it would be nice to be able to set the actual timestamp.
I don't see any such option in
captureException