Skip to content
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

add helper to inject Rollbar.js configuration and snippet #569

Closed
tisba opened this issue Feb 14, 2017 · 7 comments
Closed

add helper to inject Rollbar.js configuration and snippet #569

tisba opened this issue Feb 14, 2017 · 7 comments

Comments

@tisba
Copy link

tisba commented Feb 14, 2017

The magic that is used in the middleware is quite scary and does not allow where the snippets gets injected. We wrote a very simple application helper to have more control over when and how the code for Rollbar.js gets injected.

It would be nice, if the rollbar-gem could provide a helper itself to do that.

@jondeandres
Copy link
Contributor

@tisba is in our roadmap improving the rollbar.js integration in the gem, but we'd like continuing with this automatic injection. We can provide eventually a flag to add or not automatically and then use a helper, yes.

@spdawson
Copy link

spdawson commented Mar 8, 2017

The magic that is used in the middleware is quite scary and does not allow where the snippets gets injected

scary/fragile indeed; 👍 for being able to control this

@swistak
Copy link

swistak commented Mar 17, 2017

👍 I've stumbled upon this issue while trying to find how to even put that snipet there.

@kylefox
Copy link

kylefox commented Sep 14, 2017

I ran into this as well. I need to do some munging of _rollbarConfig that cannot (currently) be accomplished in the Ruby initializer. 😕 But I would still like to use the JS snippet that's bundled in the gem so I only have one dependency to update.

I hacked a helper to inject the snippet, but would love an official way to include the snippet that doesn't rely on Rollbar's private internals 😬

For reference, here's my helper:

require 'rollbar/middleware/js'

module RollbarHelper
  def rollbar_js_snippet
    Rollbar::Middleware::Js::SNIPPET.html_safe
  end
end

(If you use this helper I'd recommend writing an accompanying test/spec to make sure that nothing breaks when upgrading Rollbar, since the helper relies on an unofficial API).

@rokob
Copy link
Contributor

rokob commented Sep 14, 2017

I am curious what cannot be accomplished in the initializer?

So you are handling the config injection yourself, and then using this helper method in your view to put the snippet after your definition of _rollbarConfig?

We can probably just expose essentially this helper of yours and make the injection configurable.

@kylefox
Copy link

kylefox commented Sep 15, 2017

I am curious what cannot be accomplished in the initializer?

I'd like to use the hostWhiteList to reduce noise. However, our application runs on an arbitrary, unknown number of domains (we allow users to configure custom domains). Our solution has been to dynamically set hostWhiteList to the current host in ERB, like so:

<script>
  var _rollbarConfig = {
    accessToken: "<%= ENV['rollbar_client_token'] %>",
    captureUncaught: true,
    payload: {
      environment: "<%= Rails.env %>"
    },
    hostWhiteList: ['<%= request.host %>']  // 👈 Dynamically set hostWhiteList
  };

  <%= rollbar_js_snippet %>
</script>

Another solution would be to allow a config.js_options to accept a proc that is passed the request (or similar).

We can probably just expose essentially this helper of yours and make the injection configurable.

That — and/or support for procs in the initializer — would be cool 👍

@rivkahstandig3636
Copy link
Contributor

Hi there, I’m closing out all issues opened before 2018 that haven’t had any activity on them since the start of this year. If this is still an issue for you, please comment here and we can reopen this. Thanks!

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

No branches or pull requests

8 participants