raven-transports-fluentd 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 74abfe6130c0a65632b0c4c221d8630723af48b4
4
+ data.tar.gz: d89228454d6c3f6cafd6b9225d355c7ba7aaed0b
5
+ SHA512:
6
+ metadata.gz: 31624c314062b2885fa92d5487c89aa2f5e28c7736fe529308950b8e9d2c8bb2458ad09e445e30a4dd467ffa065c994806cb11682f2884128856e637c4e245a3
7
+ data.tar.gz: 2e958f2afc297c6e0b18c0e085e0755c9207d8740c426a8bdb50526ceac03b9cfeac1964e37db8519e0573e24e840fae4b31d12c109a00bc92e5936ee685c60a
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in raven-transports-fluentd.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2014 Naoto Takai
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # Raven::Transports::Fluentd
2
+
3
+ Send error logs to [sentry](https://github.com/getsentry/sentry) via [fluentd](https://github.com/fluent/fluentd) .
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'raven-transports-fluentd'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install raven-transports-fluentd
20
+
21
+ ## Usage
22
+
23
+ config/initializers/raven.rb
24
+
25
+ ```ruby
26
+ require 'raven'
27
+ require 'raven/transports/fluentd'
28
+
29
+ Raven.configure do |config|
30
+ config.dsn = "fluentd://#{ENV['SENTRY_PUBLIC_KEY']}:#{ENV['SENTRY_SECRET_KEY']}@localhost:24224/2"
31
+ end
32
+ ```
33
+
34
+ ## Contributing
35
+
36
+ 1. Fork it ( https://github.com/cookpad/raven-transports-fluent/fork )
37
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
38
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
39
+ 4. Push to the branch (`git push origin my-new-feature`)
40
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,67 @@
1
+ require 'raven'
2
+ require 'hashie'
3
+ require 'uri'
4
+
5
+ module Fluent
6
+ class RavenOutput < BufferedOutput
7
+ Fluent::Plugin.register_output('raven', self)
8
+
9
+ config_param :server, :string
10
+ config_param :ssl_verification, :bool, default: false
11
+ config_param :timeout, :integer, default: 1
12
+ config_param :open_timeout, :integer, default: 1
13
+ config_param :raven_log_path, :string
14
+
15
+ def configure(conf)
16
+ super
17
+ uri = URI.parse(conf['server'])
18
+ project_id = uri.path.slice(/\d+/)
19
+
20
+ @base_configuration = Hashie::Mash.new(
21
+ server: conf['server'],
22
+ public_key: 'not_used',
23
+ secret_key: 'not_used',
24
+ ssl: uri.scheme == 'https' ? true : false,
25
+ ssl_verification: conf['ssl_verification'],
26
+ timeout: conf['timeout'],
27
+ open_timeout: conf['open_timeout'],
28
+ )
29
+
30
+ Raven.configure do |config|
31
+ config.logger = Logger.new(conf['raven_log_path'])
32
+ end
33
+ end
34
+
35
+ def start
36
+ super
37
+ end
38
+
39
+ def shutdown
40
+ super
41
+ end
42
+
43
+ def format(tag, time, record)
44
+ [tag, time, record].to_msgpack
45
+ end
46
+
47
+ def write(chunk)
48
+ chunk.msgpack_each do |tag, time, record|
49
+ auth_header = record['auth_header']
50
+ data = record['data']
51
+ options = Hash[record['options'].map { |key, value| [key.to_sym, value] }] if record['options']
52
+ project_id = record['project_id']
53
+ send_to_sentry(auth_header, data, project_id, options)
54
+ end
55
+ end
56
+
57
+ private
58
+
59
+ def send_to_sentry(auth_header, data, project_id, options)
60
+ transport = ::Raven::Transports::HTTP.new(@base_configuration.merge(
61
+ project_id: project_id,
62
+ ))
63
+ transport.send(auth_header, data, options)
64
+ end
65
+
66
+ end
67
+ end
@@ -0,0 +1,37 @@
1
+ require 'fluent-logger'
2
+
3
+ require 'raven/transports'
4
+ require 'raven/error'
5
+
6
+ require 'uri'
7
+
8
+ module Raven
9
+ module Transports
10
+ class Fluentd < Transport
11
+
12
+ def send(auth_header, data, options = {})
13
+ conn.post('error', auth_header: auth_header, data: data, options: options, project_id: configuration.project_id)
14
+ end
15
+
16
+ private
17
+
18
+ def conn
19
+ verify_configuration
20
+
21
+ @conn ||= begin
22
+ uri = URI.parse(self.configuration.server)
23
+
24
+ ::Fluent::Logger::FluentLogger.new('sentry', host: uri.host, port: uri.port)
25
+ end
26
+ end
27
+
28
+ def verify_configuration
29
+ super
30
+ end
31
+
32
+ end
33
+ end
34
+ end
35
+
36
+ # Extends Raven::Client to use Raven::Transports::Fluentd
37
+ require 'raven/transports/fluentd_ext'
@@ -0,0 +1,23 @@
1
+ module Raven
2
+ module Transports
3
+ module FluentdExt
4
+ def transport
5
+ @transport ||=
6
+ case self.configuration.scheme
7
+ when 'udp'
8
+ Transports::UDP.new self.configuration
9
+ when 'http', 'https'
10
+ Transports::HTTP.new self.configuration
11
+ when 'fluentd'
12
+ Transports::Fluentd.new self.configuration
13
+ else
14
+ raise Error.new("Unknown transport scheme '#{self.configuration.scheme}'")
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+
21
+ require 'raven/client'
22
+
23
+ Raven::Client.send(:prepend, Raven::Transports::FluentdExt)
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "raven-transports-fluentd"
7
+ spec.version = '0.1.0'
8
+ spec.authors = ["Naoto Takai", "Kohei Suzuki"]
9
+ spec.email = ["takai@cookpad.com", "kohei-suzuki@cookpad.com"]
10
+ spec.summary = %q{Send error logs to sentry via fluentd.}
11
+ spec.description = %q{Send error logs to sentry via fluentd.}
12
+ spec.homepage = "https://github.com/cookpad/raven-transports-fluentd"
13
+ spec.license = 'Apache License, Version 2.0'
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").select { |path| path !~ %r{\Atest/dummy} }
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler"
21
+ spec.add_development_dependency "rake"
22
+
23
+ spec.add_dependency "fluent-logger"
24
+ spec.add_dependency "hashie"
25
+ spec.add_dependency "sentry-raven", "~> 0.10.1"
26
+ end
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: raven-transports-fluentd
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Naoto Takai
8
+ - Kohei Suzuki
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-12-01 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - '>='
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - '>='
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: fluent-logger
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: hashie
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: sentry-raven
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ~>
75
+ - !ruby/object:Gem::Version
76
+ version: 0.10.1
77
+ type: :runtime
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ~>
82
+ - !ruby/object:Gem::Version
83
+ version: 0.10.1
84
+ description: Send error logs to sentry via fluentd.
85
+ email:
86
+ - takai@cookpad.com
87
+ - kohei-suzuki@cookpad.com
88
+ executables: []
89
+ extensions: []
90
+ extra_rdoc_files: []
91
+ files:
92
+ - .gitignore
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - lib/fluent/plugin/out_raven.rb
98
+ - lib/raven/transports/fluentd.rb
99
+ - lib/raven/transports/fluentd_ext.rb
100
+ - raven-transports-fluentd.gemspec
101
+ homepage: https://github.com/cookpad/raven-transports-fluentd
102
+ licenses:
103
+ - Apache License, Version 2.0
104
+ metadata: {}
105
+ post_install_message:
106
+ rdoc_options: []
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - '>='
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ requirements: []
120
+ rubyforge_project:
121
+ rubygems_version: 2.0.14
122
+ signing_key:
123
+ specification_version: 4
124
+ summary: Send error logs to sentry via fluentd.
125
+ test_files: []