Sentry-ruby: Allow for multiple Raven clients with Rails integration.

Created on 11 Mar 2017  路  6Comments  路  Source: getsentry/sentry-ruby

I would like to send Raven messages to multiple DSNs based on the controller name / or some config.

But the integration assumes only one raven client.
Can I get a better way to integrate so that I can configure different raven-clients based on controllers.

documentation question

Most helpful comment

hello 馃憢, I'm the current maintainer of this gem and because v3 has been released and this will be a structural change, we need to push this to the next major release (v4). will keep you posted here 馃槈

All 6 comments

You can do this, we just have to document it.

You can have an unlimited amount of Raven::Instance objects, each which can have their own configuration (and thus DSN).

OK, I just realized you actually can't do this, because the Rack middleware uses the global instance.

If you could provide a Raven instance to the Rack middleware, you could:

  • Require Sentry without integrations. This will prevent the automatic Rack middleware injection.
  • In each controller you want Sentry to watch, add a new Sentry::Rack middleware, providing a config and context object.

This is a big feature, so deferring to 3.0.

@nateberkopec Is this feature available? :+1:

Welp - time for the yearly bump. I'm also interested in this feature.

hello 馃憢, I'm the current maintainer of this gem and because v3 has been released and this will be a structural change, we need to push this to the next major release (v4). will keep you posted here 馃槈

@sheki thanks for the long-waiting, but I have some good news here 馃槃

if you migrate to the new sentry-ruby SDK, the Scope & Hub structure will allow you to do that.

this is just a short example on how to initialize multiple hubs with different config objects:

dsn_1 = "DSN_1"
dsn_2 = "DSN_2"

config_1 = Sentry::Configuration.new.tap { |config| config.dsn = dsn_1 }
config_2 = Sentry::Configuration.new.tap { |config| config.dsn = dsn_2 }

hub_1 = Sentry::Hub.new(Sentry::Client.new(config_1), Sentry::Scope.new)
hub_2 = Sentry::Hub.new(Sentry::Client.new(config_2), Sentry::Scope.new)

hub_1.capture_message("message to DSN 1") #=> will be sent to DSN_1
hub_2.capture_message("message to DSN 2") #=> will be sent to DSN_2

I'm closing this now, but feel free to reopen it if you still have questions 馃檪

Was this page helpful?
0 / 5 - 0 ratings

Related issues

UsmannK picture UsmannK  路  6Comments

dcramer picture dcramer  路  8Comments

sanjibukai picture sanjibukai  路  5Comments

SirRawlins picture SirRawlins  路  7Comments

st0012 picture st0012  路  3Comments