fluent-plugin-sentry-ruby 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c10659e6a83b7691d81bdf9d252b33962de42dd7f02d6da2bd9955a61fd9da42
4
- data.tar.gz: cb745d8e5cccf5727276e31f637bef435389c2e0fadaffc02fb37454e0fcbd92
3
+ metadata.gz: 3e0ef4f3d924384893aa2981c125f9feae2b7a1948ad5381ce17305b818a13d7
4
+ data.tar.gz: bddee414a0b307de71af2fa1a9c051e28d45ccd7ae74721ea0c11a64d2109a36
5
5
  SHA512:
6
- metadata.gz: 40f20d188ced7ce12c1ff33935811b16dcdb568962c62feb2a87cd7e7dd49beedc168e214a6bde8bb12e6f1a62f93852e3fb06528c928cfbb41eab1ab4890313
7
- data.tar.gz: 647aa7aff7b869ffae8a83bf5eed5f1dc7765848b534220db9bfe0af946ae6ec74f0b1277f2a0157c291f419e14a4fdeb5cbf27d77513755c5d49046df89526c
6
+ metadata.gz: 5c7ce3468c3c7a47f4bcc3d80bd2e1ea159dfe33d82088e5f8f077921889aed18d81373907756d1c84b23212a19e76934f9fb4c20806db2bd6ece0b7f85c2be7
7
+ data.tar.gz: ff94f27723a8c9df77dd1bf7f861f305496dc44063019d90907a65eca3d0da02e8751c1c7b2b653e119291cdd3001eb490268ee0e2d06c4810d871d37157487b
data/README.md CHANGED
@@ -28,24 +28,22 @@ $ bundle
28
28
 
29
29
  ## Configuration
30
30
 
31
- You can generate configuration template:
32
-
33
- ```
34
- $ fluent-plugin-config-format output sentry
35
- ```
36
-
37
31
  ## Fluent::Plugin::SentryOutput
38
32
 
39
33
  ### dsn (string) (required)
40
34
 
35
+
36
+
41
37
  ### title (string) (optional)
42
38
 
43
39
 
44
- Default value: `test log`.
40
+
41
+ Default value: `test`.
45
42
 
46
43
  ### level (enum) (optional)
47
44
 
48
45
 
46
+
49
47
  Available values: fatal, error, warning, info, debug
50
48
 
51
49
  Default value: `info`.
@@ -53,23 +51,41 @@ Default value: `info`.
53
51
  ### environment (string) (optional)
54
52
 
55
53
 
54
+
56
55
  Default value: `local`.
57
56
 
57
+ ### type (enum) (optional)
58
+
59
+
60
+
61
+ Available values: event, exception
62
+
63
+ Default value: `event`.
64
+
58
65
  ### user_keys (array) (optional)
59
66
 
60
67
 
68
+
61
69
  Default value: `[]`.
62
70
 
63
71
  ### tag_keys (array) (optional)
64
72
 
65
73
 
74
+
66
75
  Default value: `[]`.
67
76
 
68
77
  ### keys (array) (optional)
69
78
 
70
79
 
80
+
71
81
  Default value: `[]`.
72
82
 
83
+ ### lang (string) (optional)
84
+
85
+
86
+
87
+ Default value: `php`.
88
+
73
89
 
74
90
  ## Copyright
75
91
 
@@ -3,7 +3,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
 
4
4
  Gem::Specification.new do |spec|
5
5
  spec.name = "fluent-plugin-sentry-ruby"
6
- spec.version = "0.1.0"
6
+ spec.version = "0.2.0"
7
7
  spec.authors = ["buffalo"]
8
8
  spec.email = ["buffalobigboy@gmail.com"]
9
9
 
@@ -1,23 +1,26 @@
1
1
  require "fluent/plugin/output"
2
+ require "sentry-ruby"
2
3
 
3
4
  module Fluent
4
5
  module Plugin
5
6
  class SentryOutput < Fluent::Plugin::Output
6
7
  Fluent::Plugin.register_output("sentry", self)
7
8
 
8
- config_param :dsn, :string, :secret => true
9
- config_param :title, :string, :default => 'test log'
9
+ config_param :dsn, :string
10
+ config_param :title, :string, :default => 'test'
10
11
  config_param :level, :enum, list: [:fatal, :error, :warning, :info, :debug], :default => 'info'
11
12
  config_param :environment, :string, :default => 'local'
12
-
13
+ config_param :type, :enum, list: [ :event, :exception], :default => :event
14
+ # for event
13
15
  config_param :user_keys, :array, :default => [], value_type: :string
14
16
  config_param :tag_keys, :array, :default => [], value_type: :string
15
17
  config_param :keys, :array, :default => [], value_type: :string
18
+ # for exception
19
+ config_param :lang, :string, :default => 'php'
16
20
 
17
21
 
18
22
  def initialize
19
23
  require 'time'
20
- require "sentry-ruby"
21
24
 
22
25
  super
23
26
  end
@@ -27,7 +30,6 @@ module Fluent
27
30
 
28
31
  config = Sentry::Configuration.new
29
32
  config.dsn = @dsn
30
- config.environment = @environment
31
33
  config.send_modules = false
32
34
  config.transport.timeout = 5
33
35
 
@@ -39,15 +41,29 @@ module Fluent
39
41
  begin
40
42
  event = Sentry::Event.new(configuration: @client.configuration)
41
43
 
42
- event.message = @title
43
- event.level = record['level'] || @level
44
+ event.message = record['message'] || @title
45
+ event.level = (record['level'] || @level).downcase
46
+ event.environment = record['env'] || @environment
44
47
 
45
- event.user = record.select{ |key| @user_keys.include?(key) }
46
- event.extra = @keys.length() > 0 ? record.select{ |key| @keys.include?(key) } : record
47
- event.contexts = {'data' => { origin_data: record }}
48
- event.tags = event.tags.merge({ :platform => tag })
49
- .merge({ :timestamp => Time.at(time).strftime('%Y-%m-%d %H:%M:%S') })
50
- .merge(record.select{ |key| (@tag_keys + @user_keys).include?(key) })
48
+ if @type === :event
49
+ event.user = record.select{ |key| @user_keys.include?(key) }
50
+ event.extra = @keys.length() > 0 ? record.select{ |key| @keys.include?(key) } : record
51
+ event.contexts = {'data' => { origin_data: record }}
52
+ event.tags = event.tags.merge({ :platform => tag })
53
+ .merge({ :timestamp => Time.at(time).strftime('%Y-%m-%d %H:%M:%S') })
54
+ .merge(record.select{ |key| (@tag_keys + @user_keys).include?(key) })
55
+ elsif @type === :exception
56
+ event = event.to_hash
57
+ event['exception'] = Sentry::CustomExceptionInterface.new(
58
+ type: 'FatalThrowableError',
59
+ message: record['message'],
60
+ stacktrace: Sentry::StacktraceInterface.new(frames: [Sentry::CustomStacktraceFrame.new(
61
+ filename: 'index' + '.' + @lang,
62
+ context_line: record['message'],
63
+ post_context: record['stack']
64
+ )])
65
+ ).to_hash
66
+ end
51
67
 
52
68
  @client.send_event(event)
53
69
  rescue => e
@@ -66,3 +82,44 @@ module Fluent
66
82
  end
67
83
  end
68
84
  end
85
+
86
+ module Sentry
87
+ class CustomExceptionInterface < Sentry::Interface
88
+ attr_reader :type
89
+ attr_reader :message
90
+
91
+ SKIP_INSPECTION_ATTRIBUTES = [:@stacktrace]
92
+
93
+ def initialize(type:, message:, stacktrace: nil)
94
+ @type = type
95
+ @value = message
96
+ @stacktrace = stacktrace
97
+ end
98
+
99
+ def to_hash
100
+ data = super
101
+ data[:stacktrace] = data[:stacktrace].to_hash if data[:stacktrace]
102
+ data
103
+ end
104
+ end
105
+
106
+ class CustomStacktraceFrame < Sentry::Interface
107
+ attr_accessor :filename, :pre_context, :context_line, :post_context, :lineno
108
+
109
+ def initialize(filename:, context_line:, pre_context: '', post_context: '', lineno: 1)
110
+ @filename = filename
111
+ @context_line = context_line
112
+ @pre_context = pre_context.split("\n")
113
+ @post_context = post_context.split("\n")
114
+ @lineno = lineno
115
+ end
116
+
117
+ def to_hash(*args)
118
+ data = super(*args)
119
+ data.delete(:pre_context) unless pre_context && !pre_context.empty?
120
+ data.delete(:post_context) unless post_context && !post_context.empty?
121
+ data.delete(:context_line) unless context_line && !context_line.empty?
122
+ data
123
+ end
124
+ end
125
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-sentry-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - buffalo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-15 00:00:00.000000000 Z
11
+ date: 2021-12-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler