delayed-plugins-raven 1.0.4 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -1
- data/lib/delayed-plugins-raven.rb +46 -6
- data/lib/delayed-plugins-raven/configuration.rb +16 -0
- data/lib/delayed-plugins-raven/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 901fd0dbeed8792f6e15e350f7a662c56bc77129
|
4
|
+
data.tar.gz: 67f17fb30f7ab2b19b7ceb03cfefb5b2284eeff2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3b26fa53e09b79990b83f08fbbbabbcd36b3d144adfcd1b6ca57cfb129674aa2318cfa861aa4fa9eca176ba606e2c6f40e852a1803f50505f6e31b9ecbe46f54
|
7
|
+
data.tar.gz: a2ae99f7f86b61d0415622dd9415cd8a4c10169bfa09616bb6df3f4a58e6607d5b9c08cd3e3964b690e69a398c641f9901528a575ba9ea5f88816e1858771732
|
data/README.md
CHANGED
@@ -26,10 +26,19 @@ In a Rails project, this can be done in `config/initializers`.
|
|
26
26
|
To configure `Delayed::Plugins::Raven` independently from the default Raven configuration, add an initializer to `config/initializers`:
|
27
27
|
|
28
28
|
require 'delayed-plugins-raven'
|
29
|
-
Delayed::Plugins::Raven.
|
29
|
+
Delayed::Plugins::Raven.configure_raven do |config|
|
30
30
|
config.dsn = ENV["SENTRY_DSN"]
|
31
31
|
config.excluded_exceptions = []
|
32
32
|
...
|
33
33
|
end
|
34
34
|
|
35
35
|
If this configuration is omitted, `Raven.capture_exception` will be invoked with the default Raven configuration.
|
36
|
+
|
37
|
+
Some other aspects of this plugin can be configured with `Delayed::Plugins::Raven.configure_plugin`:
|
38
|
+
|
39
|
+
Delayed::Plugins::Raven.configure_plugin do |config|
|
40
|
+
config.excluded_attributes = ["created_at", "updated_at", "last_error"]
|
41
|
+
config.trimmed_attributes = { "last_error" => 20, "handler" => 10 }
|
42
|
+
end
|
43
|
+
|
44
|
+
See `Delayed::Plugins::Raven::Configuration` for default value of the above configurations.
|
@@ -3,6 +3,7 @@ require 'delayed/performable_method'
|
|
3
3
|
require 'delayed/plugin'
|
4
4
|
|
5
5
|
require 'delayed-plugins-raven/version'
|
6
|
+
require 'delayed-plugins-raven/configuration'
|
6
7
|
|
7
8
|
module Delayed::Plugins::Raven
|
8
9
|
class Plugin < ::Delayed::Plugin
|
@@ -10,8 +11,8 @@ module Delayed::Plugins::Raven
|
|
10
11
|
def error(job, error)
|
11
12
|
begin
|
12
13
|
::Raven.capture_exception(error, {
|
13
|
-
configuration: ::Delayed::Plugins::Raven.
|
14
|
-
extra: { delayed_job: job
|
14
|
+
configuration: ::Delayed::Plugins::Raven.raven_configuration,
|
15
|
+
extra: { delayed_job: get_job_json(job) }
|
15
16
|
})
|
16
17
|
rescue Exception => e
|
17
18
|
Rails.logger.error "Raven logging failed: #{e.class.name}: #{e.message}"
|
@@ -19,6 +20,33 @@ module Delayed::Plugins::Raven
|
|
19
20
|
end
|
20
21
|
super if defined?(super)
|
21
22
|
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def get_job_json(job)
|
27
|
+
json = job.as_json["job"]
|
28
|
+
|
29
|
+
if (excluded_attributes = plugin_config.excluded_attributes).present?
|
30
|
+
excluded_attributes.each { |attribute| json.delete(attribute) }
|
31
|
+
end
|
32
|
+
|
33
|
+
if (limits = plugin_config.trimmed_attributes).present?
|
34
|
+
limits.each do |attribute, limit|
|
35
|
+
json[attribute] = trim_lines(json[attribute], limit) if limit > 0
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
json
|
40
|
+
end
|
41
|
+
|
42
|
+
def trim_lines(string, limit)
|
43
|
+
return string unless limit
|
44
|
+
string.lines.to_a.map(&:strip).slice(0, limit).join("\n") if string.present?
|
45
|
+
end
|
46
|
+
|
47
|
+
def plugin_config
|
48
|
+
::Delayed::Plugins::Raven.plugin_configuration ||= ::Delayed::Plugins::Raven::Configuration.new
|
49
|
+
end
|
22
50
|
end
|
23
51
|
|
24
52
|
callbacks do |lifecycle|
|
@@ -31,11 +59,23 @@ module Delayed::Plugins::Raven
|
|
31
59
|
end
|
32
60
|
|
33
61
|
class << self
|
34
|
-
attr_accessor :
|
62
|
+
attr_accessor :raven_configuration
|
63
|
+
attr_accessor :plugin_configuration
|
64
|
+
|
65
|
+
# Note: Deprecated; Use Delayed::Plugins::Raven.configure_raven instead.
|
66
|
+
def configure(&block)
|
67
|
+
configure_raven(&block)
|
68
|
+
end
|
69
|
+
|
70
|
+
def configure_raven(&block)
|
71
|
+
@raven_configuration = ::Raven::Configuration.new
|
72
|
+
block.call(@raven_configuration) if block
|
73
|
+
self
|
74
|
+
end
|
35
75
|
|
36
|
-
def
|
37
|
-
@
|
38
|
-
|
76
|
+
def configure_plugin(&block)
|
77
|
+
@plugin_configuration = Delayed::Plugins::Raven::Configuration.new
|
78
|
+
block.call(@plugin_configuration) if block
|
39
79
|
self
|
40
80
|
end
|
41
81
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Delayed::Plugins::Raven
|
2
|
+
class Configuration
|
3
|
+
|
4
|
+
# Exclude certain attributes from being serialized into Raven's `extra` field
|
5
|
+
attr_accessor :excluded_attributes
|
6
|
+
|
7
|
+
# Trim specificed attributes to a certain number of lines. Values <= 0 means unlimited.
|
8
|
+
attr_accessor :trimmed_attributes
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
self.excluded_attributes = ["last_error"]
|
12
|
+
self.trimmed_attributes = { "handler" => -1, "last_error" => 10 }
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: delayed-plugins-raven
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Qiushi He
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2014-02-
|
13
|
+
date: 2014-02-22 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: sentry-raven
|
@@ -83,6 +83,7 @@ files:
|
|
83
83
|
- Rakefile
|
84
84
|
- delayed-plugins-raven.gemspec
|
85
85
|
- lib/delayed-plugins-raven.rb
|
86
|
+
- lib/delayed-plugins-raven/configuration.rb
|
86
87
|
- lib/delayed-plugins-raven/version.rb
|
87
88
|
- resources/looking-for-maintainer.png
|
88
89
|
- spec/lib/delayed-plugins-raven/plugin_spec.rb
|