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.
@@ -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
@@ -26,31 +26,17 @@ module Sentry
26
26
 
27
27
  return nil unless encoded_data
28
28
 
29
- begin
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 = Time.now.to_i.to_s
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":"#{DateTime.now.rfc3339}"}
69
- {"type":"event","content_type":"application/json"}
70
- #{event_hash.to_json}
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, :encoding, :http_adapter, :faraday_builder, :transport_class
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
- if e.response && e.response[:headers]['x-sentry-error']
27
- error_info += " Error in headers is: #{e.response[:headers]['x-sentry-error']}"
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 Time.now - @last_check >= interval
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 = Time.now
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
@@ -1,3 +1,3 @@
1
1
  module Sentry
2
- VERSION = "0.1.1"
2
+ VERSION = "4.0.0"
3
3
  end
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.1.1
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-06 00:00:00.000000000 Z
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/ruby.rb
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
@@ -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
-
@@ -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