Class: Trackets::Client
- Inherits:
-
Object
- Object
- Trackets::Client
- Includes:
- HTTParty
- Defined in:
- lib/trackets/client.rb
Instance Attribute Summary collapse
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#exception ⇒ Object
readonly
Returns the value of attribute exception.
Class Method Summary collapse
Instance Method Summary collapse
- #backtrace ⇒ Object
- #config ⇒ Object
- #filter_env_val(value) ⇒ Object
- #filtered_env ⇒ Object
-
#initialize(exception, env) ⇒ Client
constructor
A new instance of Client.
- #params ⇒ Object
- #payload ⇒ Object
- #send ⇒ Object
- #whitelisted_env ⇒ Object
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
#env ⇒ Object (readonly)
Returns the value of attribute env.
18 19 20 |
# File 'lib/trackets/client.rb', line 18 def env @env end |
#exception ⇒ Object (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
#backtrace ⇒ Object
25 26 27 |
# File 'lib/trackets/client.rb', line 25 def backtrace @backtrace ||= Backtrace.new(exception.backtrace) end |
#config ⇒ Object
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_env ⇒ Object
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 |
#params ⇒ Object
29 30 31 |
# File 'lib/trackets/client.rb', line 29 def params @params ||= Params.new(env) end |
#payload ⇒ Object
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., 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 |
#send ⇒ Object
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_env ⇒ Object
33 34 35 |
# File 'lib/trackets/client.rb', line 33 def whitelisted_env env.reject { |k,v| !Trackets.configuration.whitelisted_env.include?(k) } end |