dogcatcher 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.editorconfig +5 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +10 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +124 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/dogcatcher.gemspec +29 -0
- data/lib/dogcatcher.rb +40 -0
- data/lib/dogcatcher/config.rb +86 -0
- data/lib/dogcatcher/ext/rake/task.rb +16 -0
- data/lib/dogcatcher/markdown.rb +30 -0
- data/lib/dogcatcher/notice.rb +69 -0
- data/lib/dogcatcher/notifier.rb +38 -0
- data/lib/dogcatcher/version.rb +3 -0
- data/support/screenshot_event.png +0 -0
- metadata +149 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ZjlkMTYzOTMyYWM3MTA5M2Q0NWIxMDQ4M2M5MWQxZjdlNzg2OWFkNw==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MzM5MDM2MDY1YzdiNGYwZGJjOGUyZGFkNTkzNmVhZTQ5MGFlODE3OQ==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ZmQ3OWVhMzM2YWRlZTJkZTA5M2QxY2YzMzk2MGRiNzg1MDFlZDBlYzA5ZmY0
|
10
|
+
NGEwOGNkZWE0ZDBlZGJlNzZkZjZhNjkzMzQwNDg2MTg5YzZmNWY3ZGU1YjFj
|
11
|
+
YTg2OWM5NmM3MzVlY2JjMDQyZmRjYTBhNGQwNGQxMjdiODFmY2Q=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ZmYwYzE2OWI0YWZjZTVkZjUyYmI0YzQyMjA3ZDNlYmE2ZGE1NzBiZTU3YTNl
|
14
|
+
MzQ1MTUwNDk5YjJiNzIwNDUyMjkwMTI3ZmZjNjBhMzExN2UyZjA3NGRlYzk3
|
15
|
+
MGI2NDg4NGQ5MDdjNGJlODM5MjZhOWZhODMxZjkzMzVjMzFjNGU=
|
data/.editorconfig
ADDED
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 2.1.6
|
4
|
+
before_install: gem install bundler -v 1.10.6
|
5
|
+
deploy:
|
6
|
+
provider: rubygems
|
7
|
+
api_key:
|
8
|
+
secure: fXyp78ETH+ot0NlPTqdayyVUN4Wt+VGCKZOk2XvwI2WSE26OmGkMRGhkp8mH9zUq2tvMN0XvNW/+7XVUJ0Qep8KfqafR73VWhCoM4FEC1j1xlIg3oTwug+TxrYaQVisM9sgqTiwJ/suIxKpp7Br77F4mAnKhHs+lUTR9qzW/CK9QAM7rbKuBGTtwBSfv0J+oYG1a24yCl2OqXCfS1JRJ11CQnvoUcOlCHZ1Lx4NTsjPuy/J/R3qhECa11qgi6e6S0szf1OEHhSTQBjJ/rTIEZAiYbWC55g20s5uMwwocc3iy6BaqM8kh8VjWzgoWH7yIzsmyPXDfgCq95/oOx/cuA3Kp7a3rt+wRNAZbbkeHWfbrJ9iEb0s3en6855t6QaKK8kgntTkcO0n2oCrAaU1CijG42koS4J+GqvY0zq9Kqm+BbBBNRIslIIBZvexvHrleSjF/uF5hR71gNeIT5aoSUV+4t+rc+OgeEjCpv0UEf9BJ3uvRPUYC83FY1ygUm8PwMt1hhcSgkWQQLZcP8MLYda7zWM+WJpm60WJoCnNuqiVQ8lc0U9iNU7Dr4a+bPkqZScH29QvdlBrqeTTwLNrki8/dDGdSmb5GH7d7V//Iw0XnNXs9/FQQJ2qMqCREHh3fGs1eJGAXq61MqNpZ7Bg96SF4n56aAKVKBPdd35krWPM=
|
9
|
+
on:
|
10
|
+
tags: true
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Ben Vidulich
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
# Dogcatcher
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/zl4bv/dogcatcher.svg)](https://travis-ci.org/zl4bv/dogcatcher)
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/dogcatcher.svg)](https://badge.fury.io/rb/dogcatcher)
|
5
|
+
|
6
|
+
![screenshot_event](support/screenshot_event.png)
|
7
|
+
|
8
|
+
Dogcatcher is a tool to track exceptions in Ruby applications and send them to Datadog
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
gem 'dogcatcher'
|
16
|
+
```
|
17
|
+
|
18
|
+
And then execute:
|
19
|
+
|
20
|
+
$ bundle
|
21
|
+
|
22
|
+
Or install it yourself as:
|
23
|
+
|
24
|
+
$ gem install dogcatcher
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
|
28
|
+
### Basic example
|
29
|
+
|
30
|
+
This is an example that you can use anywhere within your Ruby project. By
|
31
|
+
default the exception will be sent to statsd running on the local host.
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
require 'dogcatcher'
|
35
|
+
|
36
|
+
begin
|
37
|
+
fail ArgumentError, 'Example error'
|
38
|
+
rescue ArgumentError => exception
|
39
|
+
Dogcatcher.notify(exception)
|
40
|
+
end
|
41
|
+
```
|
42
|
+
|
43
|
+
### Example within Rake
|
44
|
+
|
45
|
+
When dogcatcher has been required in a Rakefile, the all exceptions raised in
|
46
|
+
any Rake task will automatically be collected.
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
require 'dogcatcher'
|
50
|
+
|
51
|
+
task :example_task do
|
52
|
+
fail ArgumentError, 'Example error'
|
53
|
+
end
|
54
|
+
```
|
55
|
+
|
56
|
+
## Configuration
|
57
|
+
|
58
|
+
By default Dogcatcher will send events to statsd running on the local host. By
|
59
|
+
specifying a Datadog API key, Dogcatcher will switch to sending events to the
|
60
|
+
Datadog API instead.
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
Dogcatcher.configure do |c|
|
64
|
+
c.api_key = '<datadog API key goes here>'
|
65
|
+
end
|
66
|
+
```
|
67
|
+
|
68
|
+
Since the default approach is to send events to one or the other, options are
|
69
|
+
available to explicitly control where the events are sent.
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
Dogcatcher.configure do |c|
|
73
|
+
c.use_dogapi = true
|
74
|
+
c.use_statsd = true
|
75
|
+
end
|
76
|
+
```
|
77
|
+
|
78
|
+
The host and port that statsd events are sent to can be configured like so.
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
Dogcatcher.configure do |c|
|
82
|
+
c.statsd_host = '127.0.0.1'
|
83
|
+
c.statsd_port = 8125
|
84
|
+
end
|
85
|
+
```
|
86
|
+
|
87
|
+
An optional program name can be specified to help distinguish between multiple
|
88
|
+
applications. This will appear in the event title.
|
89
|
+
|
90
|
+
```ruby
|
91
|
+
Dogcatcher.configure do |c|
|
92
|
+
c.program = 'Example program'
|
93
|
+
end
|
94
|
+
```
|
95
|
+
|
96
|
+
By default, Dogcatcher will add tags for each gem and its version found in the
|
97
|
+
backtrace. This can be disabled if required.
|
98
|
+
|
99
|
+
```ruby
|
100
|
+
Dogcatcher.configure do |c|
|
101
|
+
c.gem_tags = false
|
102
|
+
end
|
103
|
+
```
|
104
|
+
|
105
|
+
The backtrace can be cleaned by adding filters or silencers. The filters
|
106
|
+
shown below were used to generate the screenshot shown above.
|
107
|
+
|
108
|
+
```ruby
|
109
|
+
Dogcatcher.configure do |c|
|
110
|
+
c.add_filter { |line| line.gsub(Dir.pwd, '.') }
|
111
|
+
c.add_filter { |line| line.gsub(%r{^.*/gem/ruby/[0-9.]+/gems/([A-Za-z0-9\-_]+)-([0-9.]+(\.[a-z]+(\.[0-9]+)?)?)/}, '\1 (\2) ') }
|
112
|
+
c.add_filter { |line| line.gsub(%r{.*/gem/ruby/[0-9.]+(/bin/)}, '<gem path>\1') }
|
113
|
+
c.add_filter { |line| line.gsub(%r{.*(/lib/ruby/[0-9.]+)}, '<interpreter path>\1') }
|
114
|
+
c.add_silencer { |line| false }
|
115
|
+
end
|
116
|
+
```
|
117
|
+
|
118
|
+
## Contributing
|
119
|
+
|
120
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/zl4bv/dogcatcher.
|
121
|
+
|
122
|
+
## License
|
123
|
+
|
124
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'dogcatcher'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require 'pry'
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require 'irb'
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/dogcatcher.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'dogcatcher/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'dogcatcher'
|
8
|
+
spec.version = Dogcatcher::VERSION
|
9
|
+
spec.authors = ['Ben Vidulich']
|
10
|
+
spec.email = ['ben@vidulich.co.nz']
|
11
|
+
|
12
|
+
spec.summary = %q{Dogcatcher is a tool to catch exceptions in Ruby applications and send them to Datadog}
|
13
|
+
spec.description = %q{Dogcatcher is a tool to catch exceptions in Ruby applications and send them to Datadog}
|
14
|
+
spec.homepage = 'https://github.com/zl4bv/dogcatcher'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = 'exe'
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
|
22
|
+
spec.add_development_dependency 'bundler', '~> 1.10'
|
23
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
24
|
+
spec.add_development_dependency 'rspec'
|
25
|
+
|
26
|
+
spec.add_runtime_dependency 'activesupport', '~> 4'
|
27
|
+
spec.add_runtime_dependency 'dogapi', '~> 1.22'
|
28
|
+
spec.add_runtime_dependency 'dogstatsd-ruby', '~> 1.6'
|
29
|
+
end
|
data/lib/dogcatcher.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'active_support/backtrace_cleaner'
|
2
|
+
require 'dogapi'
|
3
|
+
require 'statsd'
|
4
|
+
|
5
|
+
require 'dogcatcher/ext/rake/task'
|
6
|
+
require 'dogcatcher/config'
|
7
|
+
require 'dogcatcher/markdown'
|
8
|
+
require 'dogcatcher/notice'
|
9
|
+
require 'dogcatcher/notifier'
|
10
|
+
require 'dogcatcher/version'
|
11
|
+
|
12
|
+
module Dogcatcher
|
13
|
+
class << self
|
14
|
+
# Returns a config instance
|
15
|
+
#
|
16
|
+
# @return [Dogcatcher::Config]
|
17
|
+
def config
|
18
|
+
@config ||= Config.new
|
19
|
+
end
|
20
|
+
|
21
|
+
# Used to configure Dogcatcher
|
22
|
+
#
|
23
|
+
# @yieldparam [Dogcatcher::Config]
|
24
|
+
def configure
|
25
|
+
yield config
|
26
|
+
end
|
27
|
+
|
28
|
+
# @param [Exception] exception
|
29
|
+
# @return [Dogcatcher::Notice]
|
30
|
+
def build_notice(exception)
|
31
|
+
Notice.new(config, exception)
|
32
|
+
end
|
33
|
+
|
34
|
+
# @param [Dogcatcher::Notice] notice
|
35
|
+
def notify(notice)
|
36
|
+
@notifier ||= Notifier.new(config)
|
37
|
+
@notifier.notify(notice)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
module Dogcatcher
|
2
|
+
# Configuration for Dogcatcher
|
3
|
+
class Config
|
4
|
+
# Optional program name that will be included in the event information.
|
5
|
+
attr_accessor :program
|
6
|
+
|
7
|
+
# Datadog API key.
|
8
|
+
#
|
9
|
+
# This must be configured in order to sent events to the Datadog API.
|
10
|
+
attr_accessor :api_key
|
11
|
+
|
12
|
+
# The host and port where statsd events will be sent.
|
13
|
+
#
|
14
|
+
# By default the host is +127.0.0.1+ and the port is +8125+.
|
15
|
+
attr_accessor :statsd_host
|
16
|
+
attr_accessor :statsd_port
|
17
|
+
|
18
|
+
# When each is set to +true+ then exceptions will be sent via the
|
19
|
+
# corresponding method. Both can be enabled/disabled at the same time.
|
20
|
+
#
|
21
|
+
# By default these are unset; dogapi will be used if an API key is provided
|
22
|
+
# else statsd will be used.
|
23
|
+
attr_accessor :use_dogapi
|
24
|
+
attr_accessor :use_statsd
|
25
|
+
|
26
|
+
# When enabled it will add tags for each +gem_name:version+ found in the
|
27
|
+
# backtrace.
|
28
|
+
#
|
29
|
+
# Enabled by default.
|
30
|
+
attr_accessor :gem_tags
|
31
|
+
|
32
|
+
# Used to clean the backtrace.
|
33
|
+
#
|
34
|
+
# By default it does no cleaning.
|
35
|
+
attr_accessor :backtrace_cleaner
|
36
|
+
|
37
|
+
def initialize
|
38
|
+
@statsd_host = '127.0.0.1'
|
39
|
+
@statsd_port = 8125
|
40
|
+
@gem_tags = true
|
41
|
+
@backtrace_cleaner = ActiveSupport::BacktraceCleaner.new
|
42
|
+
end
|
43
|
+
|
44
|
+
# Adds a backtrace filter. The given line in the backtrace will be replaced
|
45
|
+
# with the line returned by the given block.
|
46
|
+
#
|
47
|
+
# @yieldparam [String] line in the backtrace
|
48
|
+
# @yieldreturn [String] filtered line in the backtrace
|
49
|
+
def add_filter
|
50
|
+
backtrace_cleaner.add_filter { |line| yield line }
|
51
|
+
end
|
52
|
+
|
53
|
+
# Adds a backtrace silencer. Excludes the given line from the backtrace if
|
54
|
+
# the given block returns +true+.
|
55
|
+
#
|
56
|
+
# @yieldparam [String] line in the backtrace
|
57
|
+
# @yieldreturn [Boolean] true if the line should be excluded
|
58
|
+
def add_silencer
|
59
|
+
backtrace_cleaner.add_silencer { |line| yield line }
|
60
|
+
end
|
61
|
+
|
62
|
+
# Whether to send events to the Datadog API.
|
63
|
+
#
|
64
|
+
# If {#use_dogapi} is +nil+ (the default), then this will return +true+ if
|
65
|
+
# a Datadog API key is set.
|
66
|
+
#
|
67
|
+
# @return [Boolean] true if events should be sent to the Datadog API
|
68
|
+
def use_dogapi?
|
69
|
+
return !@api_key.nil? if @use_dogapi.nil?
|
70
|
+
|
71
|
+
@use_dogapi
|
72
|
+
end
|
73
|
+
|
74
|
+
# Whether to send events to a statsd collector.
|
75
|
+
#
|
76
|
+
# If {#use_dogapi} is +nil+ (the default), then this will return +false+ if
|
77
|
+
# a Datadog API key is set.
|
78
|
+
#
|
79
|
+
# @return [Boolean] true if events should be sent to a statsd collector
|
80
|
+
def use_statsd?
|
81
|
+
return @api_key.nil? if @use_statsd.nil?
|
82
|
+
|
83
|
+
@use_statsd
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Rake
|
2
|
+
class Task
|
3
|
+
# We want to use the original execute method later
|
4
|
+
alias original_execute execute
|
5
|
+
|
6
|
+
def execute(args = nil)
|
7
|
+
original_execute(args)
|
8
|
+
rescue Exception => ex
|
9
|
+
notice = Dogcatcher.build_notice(ex)
|
10
|
+
notice.notifier = 'rake'
|
11
|
+
notice.action = name
|
12
|
+
Dogcatcher.notify(notice)
|
13
|
+
raise ex
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Dogcatcher
|
2
|
+
# Produces a string formatted as Markdown.
|
3
|
+
class Markdown
|
4
|
+
def initialize
|
5
|
+
@result = []
|
6
|
+
end
|
7
|
+
|
8
|
+
# Adds a bullet point to the result string.
|
9
|
+
#
|
10
|
+
# @param [String] str text to include next to the bullet point
|
11
|
+
def bullet(str)
|
12
|
+
@result << ['* ', str, "\n"]
|
13
|
+
end
|
14
|
+
|
15
|
+
# Adds a code block to the result string.
|
16
|
+
#
|
17
|
+
# @param [String] str text to include in the code block
|
18
|
+
# @param [String] language of the code block
|
19
|
+
def code_block(str, language = nil)
|
20
|
+
@result << ['```', language, "\n", str, "\n```\n"]
|
21
|
+
end
|
22
|
+
|
23
|
+
# Gets the result string formatted in Markdown.
|
24
|
+
#
|
25
|
+
# @return [String]
|
26
|
+
def result
|
27
|
+
['%%%', "\n", *@result, "\n", '%%%'].join('')
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module Dogcatcher
|
2
|
+
class Notice
|
3
|
+
# Name of the source that caught the exception
|
4
|
+
attr_accessor :notifier
|
5
|
+
|
6
|
+
# Name of the action that caused the exception
|
7
|
+
attr_accessor :action
|
8
|
+
|
9
|
+
# Additional information about the exception
|
10
|
+
attr_accessor :metadata
|
11
|
+
|
12
|
+
# The exception itself
|
13
|
+
attr_reader :exception
|
14
|
+
|
15
|
+
# @param [Dogcatcher::Config] config
|
16
|
+
# @param [Exception] exception
|
17
|
+
def initialize(config, exception)
|
18
|
+
@config = config
|
19
|
+
@exception = exception
|
20
|
+
@metadata = {}
|
21
|
+
end
|
22
|
+
|
23
|
+
# Markdown-formatted message containing the backtrace and metadata.
|
24
|
+
#
|
25
|
+
# @return [String]
|
26
|
+
def message
|
27
|
+
backtrace = @config.backtrace_cleaner.clean(exception.backtrace)
|
28
|
+
markdown = Markdown.new
|
29
|
+
metadata.each { |key, value| markdown.bullet("#{key}: #{value}") }
|
30
|
+
markdown.code_block(backtrace.join("\n"))
|
31
|
+
markdown.result
|
32
|
+
end
|
33
|
+
|
34
|
+
# Tags containing information about the event. If gem version tags are
|
35
|
+
# enabled then they will be included in the output.
|
36
|
+
#
|
37
|
+
# @return [Array<String>]
|
38
|
+
def tags
|
39
|
+
arr = []
|
40
|
+
arr << "notifier:#{notifier}"
|
41
|
+
arr << "action:#{action}"
|
42
|
+
arr << "exception_class:#{exception.class}"
|
43
|
+
arr << gem_tags if @config.gem_tags
|
44
|
+
arr.flatten
|
45
|
+
end
|
46
|
+
|
47
|
+
# Title of the event/notice.
|
48
|
+
#
|
49
|
+
# Includes the program name if a program name is configured.
|
50
|
+
#
|
51
|
+
# @return [String]
|
52
|
+
def title
|
53
|
+
program = "#{@config.program} - " if @config.program
|
54
|
+
"#{program}#{exception.class}:#{exception.message}"
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
# Searches for gem versions in the backtrace and derives tags from them.
|
60
|
+
#
|
61
|
+
# @return [Array<String>]
|
62
|
+
def gem_tags
|
63
|
+
exception.backtrace.map do |line|
|
64
|
+
match = line.scan(%r{gems/([A-Za-z\-_]+)-([0-9.]+(\.[a-z]+(\.[0-9]+)?)?)/})
|
65
|
+
match.empty? ? nil : match.flatten.compact.join(':')
|
66
|
+
end.compact
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Dogcatcher
|
2
|
+
# Sends events/notices to the Datadog API and/or a statsd collector.
|
3
|
+
class Notifier
|
4
|
+
# @param [Dogcatcher::Config] config
|
5
|
+
def initialize(config)
|
6
|
+
@config = config
|
7
|
+
end
|
8
|
+
|
9
|
+
# Sends events/notices to the Datadog API and/or a statsd collector.
|
10
|
+
#
|
11
|
+
# @param [Dogcatcher::Notice]
|
12
|
+
def notify(notice)
|
13
|
+
notify_dogapi(notice) if @config.use_dogapi?
|
14
|
+
notify_statsd(notice) if @config.use_statsd?
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
# @param [Dogcatcher::Notice]
|
20
|
+
def notify_dogapi(notice)
|
21
|
+
event = Dogapi::Event.new(notice.message,
|
22
|
+
msg_title: notice.title,
|
23
|
+
tags: notice.tags,
|
24
|
+
alert_type: 'error')
|
25
|
+
|
26
|
+
Dogapi::Client.new(@config.api_key).emit_event(event)
|
27
|
+
end
|
28
|
+
|
29
|
+
# @param [Dogcatcher::Notice]
|
30
|
+
def notify_statsd(notice)
|
31
|
+
client = Statsd.new(@config.statsd_host, @config.statsd_port)
|
32
|
+
client.event(notice.title,
|
33
|
+
notice.message,
|
34
|
+
tags: notice.tags,
|
35
|
+
alert_type: 'error')
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
Binary file
|
metadata
ADDED
@@ -0,0 +1,149 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dogcatcher
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ben Vidulich
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-04-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: activesupport
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '4'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '4'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: dogapi
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.22'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.22'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: dogstatsd-ruby
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.6'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ~>
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.6'
|
97
|
+
description: Dogcatcher is a tool to catch exceptions in Ruby applications and send
|
98
|
+
them to Datadog
|
99
|
+
email:
|
100
|
+
- ben@vidulich.co.nz
|
101
|
+
executables: []
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- .editorconfig
|
106
|
+
- .gitignore
|
107
|
+
- .rspec
|
108
|
+
- .travis.yml
|
109
|
+
- Gemfile
|
110
|
+
- LICENSE.txt
|
111
|
+
- README.md
|
112
|
+
- Rakefile
|
113
|
+
- bin/console
|
114
|
+
- bin/setup
|
115
|
+
- dogcatcher.gemspec
|
116
|
+
- lib/dogcatcher.rb
|
117
|
+
- lib/dogcatcher/config.rb
|
118
|
+
- lib/dogcatcher/ext/rake/task.rb
|
119
|
+
- lib/dogcatcher/markdown.rb
|
120
|
+
- lib/dogcatcher/notice.rb
|
121
|
+
- lib/dogcatcher/notifier.rb
|
122
|
+
- lib/dogcatcher/version.rb
|
123
|
+
- support/screenshot_event.png
|
124
|
+
homepage: https://github.com/zl4bv/dogcatcher
|
125
|
+
licenses:
|
126
|
+
- MIT
|
127
|
+
metadata: {}
|
128
|
+
post_install_message:
|
129
|
+
rdoc_options: []
|
130
|
+
require_paths:
|
131
|
+
- lib
|
132
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - ! '>='
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0'
|
137
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
138
|
+
requirements:
|
139
|
+
- - ! '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
requirements: []
|
143
|
+
rubyforge_project:
|
144
|
+
rubygems_version: 2.4.5
|
145
|
+
signing_key:
|
146
|
+
specification_version: 4
|
147
|
+
summary: Dogcatcher is a tool to catch exceptions in Ruby applications and send them
|
148
|
+
to Datadog
|
149
|
+
test_files: []
|