Class: Trackets::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/trackets/client.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(exception, env) ⇒ Client

Returns a new instance of Client.



20
21
22
23
# File 'lib/trackets/client.rb', line 20

def initialize(exception, env)
  @exception = exception
  @env = env
end

Instance Attribute Details

#envObject (readonly)

Returns the value of attribute env.



18
19
20
# File 'lib/trackets/client.rb', line 18

def env
  @env
end

#exceptionObject (readonly)

Returns the value of attribute exception.



18
19
20
# File 'lib/trackets/client.rb', line 18

def exception
  @exception
end

Class Method Details

.notify(exception, env) ⇒ Object



12
13
14
# File 'lib/trackets/client.rb', line 12

def notify(exception, env)
  new(exception, env).send
end

Instance Method Details

#backtraceObject



25
26
27
# File 'lib/trackets/client.rb', line 25

def backtrace
  @backtrace ||= Backtrace.new(exception.backtrace)
end

#configObject



67
68
69
# File 'lib/trackets/client.rb', line 67

def config
  Trackets.configuration
end

#filter_env_val(value) ⇒ Object



44
45
46
47
48
49
50
51
# File 'lib/trackets/client.rb', line 44

def filter_env_val(value)
  value.scan(/(?:^|&|\?)([^=?&]+)=([^&]+)/).each do |match|
    next unless params.blacklisted?(match[0])
    value.gsub!(/#{match[1]}/, '[FILTERED]')
  end

  value
end

#filtered_envObject



37
38
39
40
41
42
# File 'lib/trackets/client.rb', line 37

def filtered_env
  whitelisted_env.inject({}) do |result, (key, val)|
    result[key] = filter_env_val(val) if key && val =~ /\S/
    result
  end
end

#paramsObject



29
30
31
# File 'lib/trackets/client.rb', line 29

def params
  @params ||= Params.new(env)
end

#payloadObject



53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/trackets/client.rb', line 53

def payload
  {
    language:         "ruby",
    message:          exception.message,
    class_name:       exception.class.to_s,
    stacktrace:       backtrace.parse.join("\n"),
    env:              filtered_env,
    environment_name: config.environment_name,
    project_root:     config.project_root,
    framework:        config.framework,
    params:           params.filtered
  }
end

#sendObject



71
72
73
# File 'lib/trackets/client.rb', line 71

def send
  self.class.post "#{config.api_url}/reports/#{config.api_key}", body: { error: payload }
end

#whitelisted_envObject



33
34
35
# File 'lib/trackets/client.rb', line 33

def whitelisted_env
  env.reject { |k,v| !Trackets.configuration.whitelisted_env.include?(k) }
end