Skip to content

dataCallback overwritten by angular plugin #477

Closed

Description

@thomasjachmann

When using the angular plugin, the dataCallback method I set in the config options is overwritten by the plugin.

Raven.config("mydsn", {
  dataCallback: function(data) {
    console.log "my data callback was called";
    return data;
  }
}).install();

The provided callback will be stored in _globalOptions.dataCallback during config(). After that, install() will call angularPlugin which calls Raven.setDataCallback - overwriting my callback. There are two solutions here:

  1. The plugin should create a wrapper method that first calls the already registered callback (if any) and then does it's own work.
  2. There should not only be one callback but several, registered in an array that will be called one after the other. The downside would be that:
    • either the name for registering data callbacks would be called setDataCallback although it wouldn't set but add it
    • or the method would be renamed, breaking backwards compatibility. This could be avoided by keeping setDataCallback which would erase all other callbacks and add addDataCallback or registerDataCallback which would just add the callback to the array.

I could create a PR if one approach is acceptable.

Activity

  1. thomasjachmann commented on Jan 18, 2016

    @thomasjachmann
    Author

    This is also true for the react-native plugin. There, setTransport also works the same and might lead to similar problems.

  2. benvinegar commented on Jan 18, 2016

    @benvinegar
    Contributor

    Thanks for reporting this.

    My first inclination is to have both plugins just dig into Raven's internals and wrap this._globalOptions.dataCallback (option 1), since that will quickly fix the problem and doesn't require us to modify Raven's public API. Since these are plugins maintained by us, I think touching the private API is okay.

    The flip side is that this is a recurring problem, and I'd like to see a longer term fix (e.g. addDataCallback or some other generic event API). But we've introduced a lot of thrash to Raven recently, and I think I'd like to hold out just a little longer on this.

  3. benvinegar commented on Jan 18, 2016

    @benvinegar
    Contributor
  4. benvinegar commented on Jan 18, 2016

    @benvinegar
    Contributor

    Hmm, thinking about this more, just wrapping the internal callback can still result in situations where the callback is clobbered.

    For example, if you call setDataCallback after install, it would clobber any plugin's callbacks:

    Raven
      .config('DSN')
      .addPlugin(Raven.Plugins.Angular)
      .install()
      .setDataCallback(myDataCallback);

    Admittedly, that's not how we document this in the docs, but it could happen. Hmm.

  5. thomasjachmann commented on Jan 18, 2016

    @thomasjachmann
    Author

    @benvinegar Right. That means the dataCallback option and setDataCallback function should only be used by the user while the plugins should use a different way to register their data enhancements. On the other hand, a user might want to achieve just this: Use the plugin's exception handler but not it's data callback. But this is rather hypothetical.

  6. kamilogorek commented on Sep 28, 2017

    @kamilogorek
    Contributor

    Already fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions