sentry-ruby 0.1.1 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.craft.yml +1 -0
- data/CHANGELOG.md +25 -0
- data/Gemfile +5 -0
- data/README.md +197 -21
- data/Rakefile +3 -1
- data/lib/{sentry.rb → sentry-ruby.rb} +29 -3
- data/lib/sentry/benchmarks/benchmark_transport.rb +14 -0
- data/lib/sentry/breadcrumb.rb +7 -7
- data/lib/sentry/breadcrumb/sentry_logger.rb +10 -26
- data/lib/sentry/breadcrumb_buffer.rb +2 -5
- data/lib/sentry/client.rb +32 -37
- data/lib/sentry/configuration.rb +77 -91
- data/lib/sentry/dsn.rb +6 -3
- data/lib/sentry/event.rb +42 -40
- data/lib/sentry/hub.rb +13 -2
- data/lib/sentry/interfaces/request.rb +1 -10
- data/lib/sentry/rack.rb +1 -0
- data/lib/sentry/rack/tracing.rb +39 -0
- data/lib/sentry/scope.rb +26 -4
- data/lib/sentry/span.rb +155 -0
- data/lib/sentry/transaction.rb +113 -0
- data/lib/sentry/transaction_event.rb +29 -0
- data/lib/sentry/transport.rb +11 -24
- data/lib/sentry/transport/configuration.rb +1 -8
- data/lib/sentry/transport/http_transport.rb +5 -2
- data/lib/sentry/transport/state.rb +2 -2
- data/lib/sentry/utils/request_id.rb +16 -0
- data/lib/sentry/version.rb +1 -1
- metadata +9 -6
- data/lib/sentry/event/options.rb +0 -31
- data/lib/sentry/ruby.rb +0 -1
- data/lib/sentry/utils/deep_merge.rb +0 -22
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Sentry
|
4
|
+
class TransactionEvent < Event
|
5
|
+
ATTRIBUTES = %i(
|
6
|
+
event_id level timestamp start_timestamp
|
7
|
+
release environment server_name modules
|
8
|
+
user tags contexts extra
|
9
|
+
transaction platform sdk type
|
10
|
+
)
|
11
|
+
|
12
|
+
attr_accessor(*ATTRIBUTES)
|
13
|
+
attr_accessor :spans
|
14
|
+
|
15
|
+
def start_timestamp=(time)
|
16
|
+
@start_timestamp = time.is_a?(Time) ? time.to_f : time
|
17
|
+
end
|
18
|
+
|
19
|
+
def type
|
20
|
+
"transaction"
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_hash
|
24
|
+
data = super
|
25
|
+
data[:spans] = @spans.map(&:to_hash) if @spans
|
26
|
+
data
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/sentry/transport.rb
CHANGED
@@ -26,31 +26,17 @@ module Sentry
|
|
26
26
|
|
27
27
|
return nil unless encoded_data
|
28
28
|
|
29
|
-
|
30
|
-
if configuration.async?
|
31
|
-
begin
|
32
|
-
# We have to convert to a JSON-like hash, because background job
|
33
|
-
# processors (esp ActiveJob) may not like weird types in the event hash
|
34
|
-
configuration.async.call(event.to_json_compatible)
|
35
|
-
rescue => e
|
36
|
-
configuration.logger.error(LOGGER_PROGNAME) { "async event sending failed: #{e.message}" }
|
37
|
-
send_data(encoded_data, content_type: content_type)
|
38
|
-
end
|
39
|
-
else
|
40
|
-
send_data(encoded_data, content_type: content_type)
|
41
|
-
end
|
42
|
-
|
43
|
-
state.success
|
44
|
-
rescue => e
|
45
|
-
failed_for_exception(e, event)
|
46
|
-
return
|
47
|
-
end
|
29
|
+
send_data(encoded_data, content_type: content_type)
|
48
30
|
|
31
|
+
state.success
|
49
32
|
event
|
33
|
+
rescue => e
|
34
|
+
failed_for_exception(e, event)
|
35
|
+
nil
|
50
36
|
end
|
51
37
|
|
52
38
|
def generate_auth_header
|
53
|
-
now =
|
39
|
+
now = Sentry.utc_now.to_i
|
54
40
|
fields = {
|
55
41
|
'sentry_version' => PROTOCOL_VERSION,
|
56
42
|
'sentry_client' => USER_AGENT,
|
@@ -63,11 +49,12 @@ module Sentry
|
|
63
49
|
|
64
50
|
def encode(event_hash)
|
65
51
|
event_id = event_hash[:event_id] || event_hash['event_id']
|
52
|
+
event_type = event_hash[:type] || event_hash['type']
|
66
53
|
|
67
54
|
envelope = <<~ENVELOPE
|
68
|
-
{"event_id":"#{event_id}","dsn":"#{configuration.dsn.to_s}","sdk":#{Sentry.sdk_meta.to_json},"sent_at":"#{
|
69
|
-
{"type":"
|
70
|
-
#{event_hash
|
55
|
+
{"event_id":"#{event_id}","dsn":"#{configuration.dsn.to_s}","sdk":#{Sentry.sdk_meta.to_json},"sent_at":"#{Sentry.utc_now.iso8601}"}
|
56
|
+
{"type":"#{event_type}","content_type":"application/json"}
|
57
|
+
#{JSON.generate(event_hash)}
|
71
58
|
ENVELOPE
|
72
59
|
|
73
60
|
[CONTENT_TYPE, envelope]
|
@@ -101,7 +88,7 @@ module Sentry
|
|
101
88
|
end
|
102
89
|
|
103
90
|
def log_not_sending(event)
|
104
|
-
configuration.logger.warn(LOGGER_PROGNAME) { "Failed to submit event: #{Event.get_log_message(event.to_hash)}" }
|
91
|
+
configuration.logger.warn(LOGGER_PROGNAME) { "Failed to submit event. Unreported Event: #{Event.get_log_message(event.to_hash)}" }
|
105
92
|
end
|
106
93
|
end
|
107
94
|
end
|
@@ -1,19 +1,12 @@
|
|
1
1
|
module Sentry
|
2
2
|
class Transport
|
3
3
|
class Configuration
|
4
|
-
attr_accessor :timeout, :open_timeout, :proxy, :ssl, :ssl_ca_file, :ssl_verification, :
|
4
|
+
attr_accessor :timeout, :open_timeout, :proxy, :ssl, :ssl_ca_file, :ssl_verification, :http_adapter, :faraday_builder, :transport_class
|
5
5
|
|
6
6
|
def initialize
|
7
7
|
@ssl_verification = true
|
8
8
|
@open_timeout = 1
|
9
9
|
@timeout = 2
|
10
|
-
@encoding = 'gzip'
|
11
|
-
end
|
12
|
-
|
13
|
-
def encoding=(encoding)
|
14
|
-
raise(Error, 'Unsupported encoding') unless %w(gzip json).include? encoding
|
15
|
-
|
16
|
-
@encoding = encoding
|
17
10
|
end
|
18
11
|
|
19
12
|
def transport_class=(klass)
|
@@ -23,9 +23,12 @@ module Sentry
|
|
23
23
|
end
|
24
24
|
rescue Faraday::Error => e
|
25
25
|
error_info = e.message
|
26
|
-
|
27
|
-
|
26
|
+
|
27
|
+
if e.response
|
28
|
+
error_info += "\nbody: #{e.response[:body]}"
|
29
|
+
error_info += " Error in headers is: #{e.response[:headers]['x-sentry-error']}" if e.response[:headers]['x-sentry-error']
|
28
30
|
end
|
31
|
+
|
29
32
|
raise Sentry::Error, error_info
|
30
33
|
end
|
31
34
|
|
@@ -9,7 +9,7 @@ module Sentry
|
|
9
9
|
return true if @status == :online
|
10
10
|
|
11
11
|
interval = @retry_after || [@retry_number, 6].min**2
|
12
|
-
return true if
|
12
|
+
return true if Sentry.utc_now - @last_check >= interval
|
13
13
|
|
14
14
|
false
|
15
15
|
end
|
@@ -17,7 +17,7 @@ module Sentry
|
|
17
17
|
def failure(retry_after = nil)
|
18
18
|
@status = :error
|
19
19
|
@retry_number += 1
|
20
|
-
@last_check =
|
20
|
+
@last_check = Sentry.utc_now
|
21
21
|
@retry_after = retry_after
|
22
22
|
end
|
23
23
|
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Sentry
|
2
|
+
module Utils
|
3
|
+
module RequestId
|
4
|
+
REQUEST_ID_HEADERS = %w(action_dispatch.request_id HTTP_X_REQUEST_ID).freeze
|
5
|
+
|
6
|
+
# Request ID based on ActionDispatch::RequestId
|
7
|
+
def self.read_from(env_hash)
|
8
|
+
REQUEST_ID_HEADERS.each do |key|
|
9
|
+
request_id = env_hash[key]
|
10
|
+
return request_id if request_id
|
11
|
+
end
|
12
|
+
nil
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/sentry/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sentry-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 4.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sentry Team
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-12-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -44,8 +44,9 @@ files:
|
|
44
44
|
- Rakefile
|
45
45
|
- bin/console
|
46
46
|
- bin/setup
|
47
|
-
- lib/sentry.rb
|
47
|
+
- lib/sentry-ruby.rb
|
48
48
|
- lib/sentry/backtrace.rb
|
49
|
+
- lib/sentry/benchmarks/benchmark_transport.rb
|
49
50
|
- lib/sentry/breadcrumb.rb
|
50
51
|
- lib/sentry/breadcrumb/sentry_logger.rb
|
51
52
|
- lib/sentry/breadcrumb_buffer.rb
|
@@ -55,7 +56,6 @@ files:
|
|
55
56
|
- lib/sentry/core_ext/object/duplicable.rb
|
56
57
|
- lib/sentry/dsn.rb
|
57
58
|
- lib/sentry/event.rb
|
58
|
-
- lib/sentry/event/options.rb
|
59
59
|
- lib/sentry/hub.rb
|
60
60
|
- lib/sentry/interface.rb
|
61
61
|
- lib/sentry/interfaces/exception.rb
|
@@ -66,16 +66,19 @@ files:
|
|
66
66
|
- lib/sentry/logger.rb
|
67
67
|
- lib/sentry/rack.rb
|
68
68
|
- lib/sentry/rack/capture_exception.rb
|
69
|
-
- lib/sentry/
|
69
|
+
- lib/sentry/rack/tracing.rb
|
70
70
|
- lib/sentry/scope.rb
|
71
|
+
- lib/sentry/span.rb
|
72
|
+
- lib/sentry/transaction.rb
|
73
|
+
- lib/sentry/transaction_event.rb
|
71
74
|
- lib/sentry/transport.rb
|
72
75
|
- lib/sentry/transport/configuration.rb
|
73
76
|
- lib/sentry/transport/dummy_transport.rb
|
74
77
|
- lib/sentry/transport/http_transport.rb
|
75
78
|
- lib/sentry/transport/state.rb
|
76
|
-
- lib/sentry/utils/deep_merge.rb
|
77
79
|
- lib/sentry/utils/exception_cause_chain.rb
|
78
80
|
- lib/sentry/utils/real_ip.rb
|
81
|
+
- lib/sentry/utils/request_id.rb
|
79
82
|
- lib/sentry/version.rb
|
80
83
|
- sentry-ruby.gemspec
|
81
84
|
homepage: https://github.com/getsentry/raven-ruby
|
data/lib/sentry/event/options.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
module Sentry
|
2
|
-
class Event
|
3
|
-
class Options
|
4
|
-
attr_reader :message,
|
5
|
-
:user, :extra, :tags, :contexts,
|
6
|
-
:backtrace, :level, :fingerprint,
|
7
|
-
:server_name, :release, :environment
|
8
|
-
|
9
|
-
def initialize(
|
10
|
-
message: "",
|
11
|
-
user: {}, extra: {}, tags: {}, contexts: {},
|
12
|
-
backtrace: [], level: :error, fingerprint: [],
|
13
|
-
# nilable attributes because we'll fallback to the configuration's values
|
14
|
-
server_name: nil, release: nil, environment: nil
|
15
|
-
)
|
16
|
-
@message = message || ""
|
17
|
-
@user = user || {}
|
18
|
-
@extra = extra || {}
|
19
|
-
@tags = tags || {}
|
20
|
-
@contexts = contexts || {}
|
21
|
-
@backtrace = backtrace || []
|
22
|
-
@fingerprint = fingerprint || []
|
23
|
-
@level = level || :error
|
24
|
-
@server_name = server_name
|
25
|
-
@environment = environment
|
26
|
-
@release = release
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
data/lib/sentry/ruby.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require "sentry"
|
@@ -1,22 +0,0 @@
|
|
1
|
-
module Sentry
|
2
|
-
module Utils
|
3
|
-
# ported from ActiveSupport
|
4
|
-
module DeepMergeHash
|
5
|
-
def self.deep_merge(hash, other_hash, &block)
|
6
|
-
deep_merge!(hash, other_hash, &block)
|
7
|
-
end
|
8
|
-
|
9
|
-
def self.deep_merge!(hash, other_hash, &block)
|
10
|
-
hash.merge!(other_hash) do |key, this_val, other_val|
|
11
|
-
if this_val.is_a?(Hash) && other_val.is_a?(Hash)
|
12
|
-
deep_merge(this_val, other_val, &block)
|
13
|
-
elsif block_given?
|
14
|
-
block.call(key, this_val, other_val)
|
15
|
-
else
|
16
|
-
other_val
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|