fluent-plugin-sentry-ruby 0.1.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.devcontainer/Dockerfile +17 -0
- data/.devcontainer/base.Dockerfile +43 -0
- data/.devcontainer/devcontainer.json +34 -0
- data/.gitignore +4 -0
- data/README.md +23 -7
- data/fluent-plugin-sentry.gemspec +1 -1
- data/lib/fluent/plugin/out_sentry.rb +77 -13
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a476705dd3b8036afc4961481663fffe13a9711229acfc3a559e207dc7f94608
|
4
|
+
data.tar.gz: 691650a62ff27d233442c424dddafbb5148c336b725152038d0a8805ccd3bf0e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 84767a4153614507883833972e573e113112b536a32d4dc2251cfc1826c7670b029ae9c69b3b53d2bd4b9941209a0820b4b76dac99d8e21e3fa20f437db6482d
|
7
|
+
data.tar.gz: 4ec9fffa7b595bd4adea296c80650e9ff21211aa6e1432da29a4e3ae6548134256b64706b2eab7501759effc63b7a16c841ea93c294fb2071c443f162bec5e03
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# [Choice] Ruby version (use -bullseye variants on local arm64/Apple Silicon): 3, 3.0, 2, 2.7, 2.6, 3-bullseye, 3.0-bullseye, 2-bullseye, 2.7-bullseye, 2.6-bullseye, 3-buster, 3.0-buster, 2-buster, 2.7-buster, 2.6-buster
|
2
|
+
ARG VARIANT=2-bullseye
|
3
|
+
FROM mcr.microsoft.com/vscode/devcontainers/ruby:0-${VARIANT}
|
4
|
+
|
5
|
+
# [Choice] Node.js version: none, lts/*, 16, 14, 12, 10
|
6
|
+
ARG NODE_VERSION="none"
|
7
|
+
RUN if [ "${NODE_VERSION}" != "none" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi
|
8
|
+
|
9
|
+
# [Optional] Uncomment this section to install additional OS packages.
|
10
|
+
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
|
11
|
+
# && apt-get -y install --no-install-recommends <your-package-list-here>
|
12
|
+
|
13
|
+
# [Optional] Uncomment this line to install additional gems.
|
14
|
+
# RUN gem install <your-gem-names-here>
|
15
|
+
|
16
|
+
# [Optional] Uncomment this line to install global node packages.
|
17
|
+
# RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g <your-package-here>" 2>&1
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# [Choice] Ruby version (use -bullseye variants on local arm64/Apple Silicon): 3, 3.0, 2, 2.7, 2.6, 3-bullseye, 3.0-bullseye, 2-bullseye, 2.7-bullseye, 2.6-bullseye, 3-buster, 3.0-buster, 2-buster, 2.7-buster, 2.6-buster
|
2
|
+
ARG VARIANT=2-bullseye
|
3
|
+
FROM ruby:${VARIANT}
|
4
|
+
|
5
|
+
# Copy library scripts to execute
|
6
|
+
COPY library-scripts/*.sh library-scripts/*.env /tmp/library-scripts/
|
7
|
+
|
8
|
+
# [Option] Install zsh
|
9
|
+
ARG INSTALL_ZSH="true"
|
10
|
+
# [Option] Upgrade OS packages to their latest versions
|
11
|
+
ARG UPGRADE_PACKAGES="true"
|
12
|
+
# Install needed packages and setup non-root user. Use a separate RUN statement to add your own dependencies.
|
13
|
+
ARG USERNAME=vscode
|
14
|
+
ARG USER_UID=1000
|
15
|
+
ARG USER_GID=$USER_UID
|
16
|
+
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
|
17
|
+
# Remove imagemagick due to https://security-tracker.debian.org/tracker/CVE-2019-10131
|
18
|
+
&& apt-get purge -y imagemagick imagemagick-6-common \
|
19
|
+
# Install common packages, non-root user, rvm, core build tools
|
20
|
+
&& bash /tmp/library-scripts/common-debian.sh "${INSTALL_ZSH}" "${USERNAME}" "${USER_UID}" "${USER_GID}" "${UPGRADE_PACKAGES}" "true" "true" \
|
21
|
+
&& bash /tmp/library-scripts/ruby-debian.sh "none" "${USERNAME}" "true" "true" \
|
22
|
+
&& apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/*
|
23
|
+
|
24
|
+
# [Choice] Node.js version: none, lts/*, 16, 14, 12, 10
|
25
|
+
ARG NODE_VERSION="none"
|
26
|
+
ENV NVM_DIR=/usr/local/share/nvm
|
27
|
+
ENV NVM_SYMLINK_CURRENT=true \
|
28
|
+
PATH=${NVM_DIR}/current/bin:${PATH}
|
29
|
+
RUN bash /tmp/library-scripts/node-debian.sh "${NVM_DIR}" "${NODE_VERSION}" "${USERNAME}" \
|
30
|
+
&& apt-get clean -y && rm -rf /var/lib/apt/lists/*
|
31
|
+
|
32
|
+
# Remove library scripts for final image
|
33
|
+
RUN rm -rf /tmp/library-scripts
|
34
|
+
|
35
|
+
# [Optional] Uncomment this section to install additional OS packages.
|
36
|
+
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
|
37
|
+
# && apt-get -y install --no-install-recommends <your-package-list-here>
|
38
|
+
|
39
|
+
# [Optional] Uncomment this line to install additional gems.
|
40
|
+
# RUN gem install <your-gem-names-here>
|
41
|
+
|
42
|
+
# [Optional] Uncomment this line to install global node packages.
|
43
|
+
# RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g <your-package-here>" 2>&1
|
@@ -0,0 +1,34 @@
|
|
1
|
+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
|
2
|
+
// https://github.com/microsoft/vscode-dev-containers/tree/v0.209.6/containers/ruby
|
3
|
+
{
|
4
|
+
"name": "Ruby",
|
5
|
+
"build": {
|
6
|
+
"dockerfile": "Dockerfile",
|
7
|
+
"args": {
|
8
|
+
// Update 'VARIANT' to pick a Ruby version: 3, 3.0, 2, 2.7, 2.6
|
9
|
+
// Append -bullseye or -buster to pin to an OS version.
|
10
|
+
// Use -bullseye variants on local on arm64/Apple Silicon.
|
11
|
+
"VARIANT": "3-bullseye",
|
12
|
+
// Options
|
13
|
+
"NODE_VERSION": "lts/*"
|
14
|
+
}
|
15
|
+
},
|
16
|
+
|
17
|
+
// Set *default* container specific settings.json values on container create.
|
18
|
+
"settings": {},
|
19
|
+
|
20
|
+
// Add the IDs of extensions you want installed when the container is created.
|
21
|
+
"extensions": [
|
22
|
+
"rebornix.Ruby"
|
23
|
+
],
|
24
|
+
|
25
|
+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
|
26
|
+
// "forwardPorts": [],
|
27
|
+
|
28
|
+
// Use 'postCreateCommand' to run commands after the container is created.
|
29
|
+
// "postCreateCommand": "ruby --version",
|
30
|
+
|
31
|
+
// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
|
32
|
+
"remoteUser": "vscode"
|
33
|
+
|
34
|
+
}
|
data/.gitignore
ADDED
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
|
-
|
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
|
|
@@ -1,23 +1,30 @@
|
|
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
|
9
|
-
config_param :title, :string, :default => 'test
|
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 :e_message, :string, :default => 'message'
|
20
|
+
config_param :e_describe, :string, :default => 'describe'
|
21
|
+
config_param :e_filename, :string, :default => 'filename'
|
22
|
+
config_param :e_stack, :string, :default => 'stack'
|
23
|
+
config_param :e_line, :string, :default => 'line'
|
16
24
|
|
17
25
|
|
18
26
|
def initialize
|
19
27
|
require 'time'
|
20
|
-
require "sentry-ruby"
|
21
28
|
|
22
29
|
super
|
23
30
|
end
|
@@ -27,7 +34,6 @@ module Fluent
|
|
27
34
|
|
28
35
|
config = Sentry::Configuration.new
|
29
36
|
config.dsn = @dsn
|
30
|
-
config.environment = @environment
|
31
37
|
config.send_modules = false
|
32
38
|
config.transport.timeout = 5
|
33
39
|
|
@@ -39,15 +45,32 @@ module Fluent
|
|
39
45
|
begin
|
40
46
|
event = Sentry::Event.new(configuration: @client.configuration)
|
41
47
|
|
42
|
-
event.
|
43
|
-
event.
|
48
|
+
event.level = (record['level'] || @level).downcase
|
49
|
+
event.environment = record['env'] || @environment
|
44
50
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
.
|
50
|
-
.merge(
|
51
|
+
if @type === :event
|
52
|
+
event.message = record['message'] || @title
|
53
|
+
event.user = record.select{ |key| @user_keys.include?(key) }
|
54
|
+
event.extra = @keys.length() > 0 ? record.select{ |key| @keys.include?(key) } : record
|
55
|
+
event.contexts = {'data' => { origin_data: record }}
|
56
|
+
event.tags = event.tags.merge({ :log_tag => tag })
|
57
|
+
.merge({ :timestamp => Time.at(time).strftime('%Y-%m-%d %H:%M:%S') })
|
58
|
+
.merge(record.select{ |key| (@tag_keys + @user_keys).include?(key) })
|
59
|
+
elsif @type === :exception
|
60
|
+
event = event.to_hash
|
61
|
+
event['exception'] = Sentry::CustomExceptionInterface.new(
|
62
|
+
type: record['message'] || @title,
|
63
|
+
message: (record[@e_describe] + (record[@e_line] ? (' on line:' + record[@e_line]) : '')) || '',
|
64
|
+
stacktrace: Sentry::StacktraceInterface.new(frames: [Sentry::CustomStacktraceFrame.new(
|
65
|
+
filename: record[@e_filename] || '',
|
66
|
+
context_line: (record[@e_describe] + (record[@e_line] ? (' on line:' + record[@e_line]) : '')) || '',
|
67
|
+
post_context: record[@e_stack] || (record[@e_describe] || ''),
|
68
|
+
)])
|
69
|
+
).to_hash
|
70
|
+
event['tags'] = { :log_tag => tag }
|
71
|
+
.merge({ :timestamp => Time.at(time).strftime('%d-%b-%Y %H:%M:%S %Z') })
|
72
|
+
.merge(record.select{ |key| (@tag_keys + @user_keys).include?(key) })
|
73
|
+
end
|
51
74
|
|
52
75
|
@client.send_event(event)
|
53
76
|
rescue => e
|
@@ -66,3 +89,44 @@ module Fluent
|
|
66
89
|
end
|
67
90
|
end
|
68
91
|
end
|
92
|
+
|
93
|
+
module Sentry
|
94
|
+
class CustomExceptionInterface < Sentry::Interface
|
95
|
+
attr_reader :type
|
96
|
+
attr_reader :message
|
97
|
+
|
98
|
+
SKIP_INSPECTION_ATTRIBUTES = [:@stacktrace]
|
99
|
+
|
100
|
+
def initialize(type:, message:, stacktrace: nil)
|
101
|
+
@type = type
|
102
|
+
@value = message
|
103
|
+
@stacktrace = stacktrace
|
104
|
+
end
|
105
|
+
|
106
|
+
def to_hash
|
107
|
+
data = super
|
108
|
+
data[:stacktrace] = data[:stacktrace].to_hash if data[:stacktrace]
|
109
|
+
data
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
class CustomStacktraceFrame < Sentry::Interface
|
114
|
+
attr_accessor :filename, :pre_context, :context_line, :post_context, :lineno
|
115
|
+
|
116
|
+
def initialize(filename:, context_line:, pre_context: '', post_context: '', lineno: 1)
|
117
|
+
@filename = filename
|
118
|
+
@context_line = context_line
|
119
|
+
@pre_context = pre_context.split("\n")
|
120
|
+
@post_context = post_context.split("\n")
|
121
|
+
@lineno = lineno
|
122
|
+
end
|
123
|
+
|
124
|
+
def to_hash(*args)
|
125
|
+
data = super(*args)
|
126
|
+
data.delete(:pre_context) unless pre_context && !pre_context.empty?
|
127
|
+
data.delete(:post_context) unless post_context && !post_context.empty?
|
128
|
+
data.delete(:context_line) unless context_line && !context_line.empty?
|
129
|
+
data
|
130
|
+
end
|
131
|
+
end
|
132
|
+
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
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- buffalo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-01-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -93,6 +93,10 @@ executables: []
|
|
93
93
|
extensions: []
|
94
94
|
extra_rdoc_files: []
|
95
95
|
files:
|
96
|
+
- ".devcontainer/Dockerfile"
|
97
|
+
- ".devcontainer/base.Dockerfile"
|
98
|
+
- ".devcontainer/devcontainer.json"
|
99
|
+
- ".gitignore"
|
96
100
|
- Gemfile
|
97
101
|
- LICENSE
|
98
102
|
- README.md
|