JulianMar / nuxt-bugsnag

Bugsnag module for nuxt.js
MIT License
49 stars 18 forks source link

changing bugsnag config on runtime? #58

Closed natemate90 closed 1 year ago

natemate90 commented 1 year ago

Hi @JulianMar many thanks for providing this module. I'm trying to update certain bugsnag config values (i.e. redacted keys) on the fly during runtime, after bugsnag.start has been called already. Do you know how I can I do this? Was trying to update nuxtApp.$config.public.bugsnag.redactedKeys on the fly, in order to make exceptions for whitelisting possible; but as it seems, this has no effect. Maybe I should do this in a different way?

JulianMar commented 1 year ago

Hey, you can use the runtime config to change these values. It will always have priority. e.x. I have it set like this:

  runtimeConfig: {
    public: {
      bugsnag: {
        environment: 'dev',
        appVersion: '2.0.0',
        releaseStage: 'dev',
      },
    }
}

With this i can set the environment by adding the NUXT_PUBLIC_BUGSNAG_ENVIRONMENT=production in the .env file.

The Problem just might be at what time of the startup you are setting this key. Can you provide me with a little reproduction where we can discuss further?

natemate90 commented 1 year ago

I was thinking; Bugsnag.start(options) on the server / client is only called once, when the nuxt App loads the plugin. In case the runtime config changes on the fly, shouldn't it rerun?

JulianMar commented 1 year ago

Yes you are right. It will only run once on the server side. But on the client it's started for every request to the nuxt app. So you could use the new config there.

What problem are you trying to solve?

natemate90 commented 1 year ago

Concerning the config I'm trying to whitelist certain redactedKeys for a single time use (then reset it back to the initially provided redactedKeys). The reason for this is that redactedKeys should be the general situation but we still want to deviate sometimes from that.

JulianMar commented 1 year ago

So you are using this redactedKey as replacement for the api token?

natemate90 commented 1 year ago

No I'm just trying to add additional data to this tab here:

Screenshot 2023-08-30 at 15 21 06

the key in this example is "data". This should normally be redacted but not in specific cases. (To add some more complexity, I'm trying to use your module inside my own module :-))

natemate90 commented 1 year ago

So right before calling the $bugsnag.notify(), I'm trying to change the runtimeconfig and remove the "data" property. And add it back after $bugsnag.notify has been called

JulianMar commented 1 year ago

Haha that sounds awesome! Keep it up :)

It seems to me, that this might solve your problem. this is called after the event is fired but not yet sent to the server. https://docs.bugsnag.com/platforms/javascript/customizing-error-reports/#updating-events-using-callbacks

natemate90 commented 1 year ago

Yeah that might indeed make more sense 👍

JulianMar commented 1 year ago

Hit me up if you have some more issues. I'm happy to help :)

natemate90 commented 1 year ago

thanks!

natemate90 commented 1 year ago

@JulianMar just so you know, I ended up overwriting the config in bugsnag directly:

const updatedRedactedKeys = ['list of keys which has removed the whitelisted key']
nuxtApp.$bugsnag._config.redactedKeys = updatedRedactedKeys

So as it seems, I was mistaken in the sense that the runtimeconfig can't be adjusted on the fly

JulianMar commented 1 year ago

Awesome! I'm glad it worked! But it's not the nuxt runtimeConfig which you changed. It's the bugsnag one. Quite a bit different but nice experiment!

natemate90 commented 1 year ago

Yeah true, ideally I would have done it in the nuxt runtimeconfig indeed. But that seems not possible during a single request cycle. But this seems to be more a nuxt issue