Class: Rack::Indicium::Sentry

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/indicium/sentry.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Sentry

Returns a new instance of Sentry.



6
7
8
9
10
11
12
13
14
# File 'lib/rack/indicium/sentry.rb', line 6

def initialize(app)
  @app = app

  if defined?(Raven)
    @sentry_client = Raven
  else
    warn "%s: Raven not definied, can't send JWT headers to Sentry." % self.class.to_s
  end
end

Instance Method Details

#call(env) ⇒ Object



16
17
18
19
# File 'lib/rack/indicium/sentry.rb', line 16

def call(env)
  check_for_jwt(env) if enabled?
  @app.call(env)
end

#check_for_jwt(env) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/rack/indicium/sentry.rb', line 21

def check_for_jwt(env)
  context = {
    "jwt.raw" => env["jwt.raw"],
    "jwt.header" => env["jwt.header"],
    "jwt.payload" => env["jwt.payload"],
  }
  client.extra_context(context)
end

#clientObject



30
31
32
# File 'lib/rack/indicium/sentry.rb', line 30

def client
  @sentry_client
end

#enabled?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/rack/indicium/sentry.rb', line 34

def enabled?
  !!@sentry_client
end