hawk-ruby 0.1.1 → 0.1.2

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.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +9 -1
  3. data/README.md +14 -13
  4. data/docs/api.md +25 -0
  5. data/docs/integrations.md +12 -20
  6. data/docs/releasing.md +3 -3
  7. data/lib/hawk/boundary.rb +1 -0
  8. data/lib/hawk/breadcrumbs/logger.rb +1 -0
  9. data/lib/hawk/breadcrumbs/net_http.rb +1 -0
  10. data/lib/hawk/breadcrumbs/rails.rb +1 -0
  11. data/lib/hawk/breadcrumbs.rb +1 -0
  12. data/lib/hawk/client.rb +96 -2
  13. data/lib/hawk/configuration.rb +197 -8
  14. data/lib/hawk/delayed_job.rb +2 -1
  15. data/lib/hawk/delivery.rb +1 -0
  16. data/lib/hawk/diagnostics.rb +8 -0
  17. data/lib/hawk/event.rb +1 -0
  18. data/lib/hawk/filter.rb +1 -0
  19. data/lib/hawk/filtered_fields.rb +1 -0
  20. data/lib/hawk/framework_filter.rb +1 -0
  21. data/lib/hawk/hook.rb +1 -0
  22. data/lib/hawk/integrations.rb +16 -0
  23. data/lib/hawk/job_context.rb +1 -0
  24. data/lib/hawk/json_value.rb +1 -0
  25. data/lib/hawk/process_hooks.rb +1 -0
  26. data/lib/hawk/rack/body.rb +1 -0
  27. data/lib/hawk/rack.rb +15 -1
  28. data/lib/hawk/rails/action_cable.rb +1 -0
  29. data/lib/hawk/rails/active_job.rb +1 -0
  30. data/lib/hawk/rails/error_subscriber.rb +1 -0
  31. data/lib/hawk/rails/integration.rb +1 -3
  32. data/lib/hawk/rails/payload_filter.rb +1 -0
  33. data/lib/hawk/rake.rb +2 -1
  34. data/lib/hawk/release.rb +1 -0
  35. data/lib/hawk/resque.rb +2 -1
  36. data/lib/hawk/scope.rb +25 -1
  37. data/lib/hawk/scope_store.rb +1 -0
  38. data/lib/hawk/sidekiq.rb +2 -1
  39. data/lib/hawk/source.rb +1 -0
  40. data/lib/hawk/token.rb +2 -0
  41. data/lib/hawk/transport.rb +1 -0
  42. data/lib/hawk/version.rb +3 -1
  43. data/lib/hawk-ruby.rb +3 -0
  44. data/lib/hawk.rb +51 -2
  45. data/sig/hawk/integrations.rbs +3 -0
  46. metadata +5 -1
data/lib/hawk.rb CHANGED
@@ -22,12 +22,34 @@ require_relative "hawk/transport"
22
22
  require_relative "hawk/delivery"
23
23
  require_relative "hawk/process_hooks"
24
24
 
25
- # The default client offers the same capture API as independent project clients.
25
+ # Error reporting through a process-wide default {Client}.
26
+ #
27
+ # Initialize before starting application workers. Scope data belongs to the
28
+ # current thread and fiber. Capture IDs confirm local acceptance, not delivery.
29
+ #
30
+ # @example Configure and report
31
+ # Hawk.init { |config| config.token = ENV.fetch("HAWK_TOKEN") }
32
+ # Hawk.capture_message("Checkout completed", context: { order_id: "42" })
33
+ # Hawk.flush(timeout: 5.0)
34
+ # @see Client For independent project clients.
26
35
  module Hawk
36
+ autoload :Rack, File.expand_path("hawk/rack", __dir__.to_s)
37
+
27
38
  class << self
39
+ # @return [Client, nil] default client, or nil before initialization or after close
28
40
  attr_reader :client
29
41
 
42
+ # Configures and replaces the default client, closing the previous client.
43
+ #
44
+ # A missing or empty token disables capture. Loaded Rails integrations can
45
+ # adjust configuration before validation. Initialize before concurrent use.
46
+ #
47
+ # @yield [configuration] configuration to customize
48
+ # @yieldparam configuration [Configuration]
49
+ # @return [Client] replacement client
50
+ # @raise [ConfigurationError] if configuration is invalid
30
51
  def init
52
+ Integrations.load
31
53
  configuration = Configuration.new
32
54
  yield configuration
33
55
  Rails.configure(configuration) if defined?(Hawk::Rails)
@@ -39,41 +61,67 @@ module Hawk
39
61
  replacement
40
62
  end
41
63
 
64
+ # (see Client#capture_exception)
65
+ # @note Returns nil when no default client exists.
42
66
  def capture_exception(exception, context: {}, user: nil, level: :error)
43
67
  @client&.capture_exception(exception, context: context, user: user, level: level)
44
68
  end
45
69
 
70
+ # (see Client#capture_message)
71
+ # @note Returns nil when no default client exists.
46
72
  def capture_message(message, context: {}, user: nil, level: :info)
47
73
  @client&.capture_message(message, context: context, user: user, level: level)
48
74
  end
49
75
 
76
+ # (see Client#set_context)
77
+ # @note Has no effect when no default client exists.
50
78
  def set_context(context)
51
79
  @client&.set_context(context)
52
80
  end
53
81
 
82
+ # (see Client#add_breadcrumb)
83
+ # @note Has no effect when no default client exists.
54
84
  def add_breadcrumb(entry)
55
85
  @client&.add_breadcrumb(entry)
56
86
  end
57
87
 
88
+ # (see Client#set_user)
89
+ # @note Has no effect when no default client exists.
58
90
  def set_user(user)
59
91
  @client&.set_user(user)
60
92
  end
61
93
 
94
+ # (see Client#with_scope)
95
+ # @note Without a default client, yields a temporary scope without storing it.
62
96
  def with_scope(&)
63
97
  client = @client
64
98
  client ? client.with_scope(&) : yield(Scope.new)
65
99
  end
66
100
 
101
+ # (see Client#capture)
102
+ # @note Without a default client, runs the block without reporting.
67
103
  def capture(&)
68
104
  client = @client
69
105
  client ? client.capture(&) : yield
70
106
  end
71
107
 
108
+ # Waits for pending delivery attempts on the default client.
109
+ #
110
+ # @param timeout [Numeric, nil] deadline in seconds; nil uses Configuration#flush_timeout
111
+ # @return [Boolean] true if attempts finished or no client exists;
112
+ # false on timeout or failure
113
+ # @note Success does not confirm receipt by Hawk.
72
114
  def flush(timeout: nil)
73
115
  client = @client
74
116
  client ? client.flush(timeout: timeout || client.configuration.flush_timeout) : true
75
117
  end
76
118
 
119
+ # Removes the default client and stops its delivery worker.
120
+ #
121
+ # @param timeout [Numeric, nil] deadline in seconds; nil uses Configuration#flush_timeout
122
+ # @return [Boolean] true if shutdown finished or no client exists;
123
+ # false on timeout or failure
124
+ # @note The default client is removed even when shutdown times out.
77
125
  def close(timeout: nil)
78
126
  previous = @client
79
127
  @client = nil
@@ -82,4 +130,5 @@ module Hawk
82
130
  end
83
131
  end
84
132
 
85
- require_relative "hawk/rails/integration" if defined?(Rails::Railtie)
133
+ require_relative "hawk/integrations"
134
+ Hawk::Integrations.load
@@ -0,0 +1,3 @@
1
+ module Hawk::Integrations
2
+ def self.load: () -> void
3
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hawk-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leonid Svyatov
@@ -119,11 +119,13 @@ files:
119
119
  - CHANGELOG.md
120
120
  - LICENSE
121
121
  - README.md
122
+ - docs/api.md
122
123
  - docs/configuration.md
123
124
  - docs/integrations.md
124
125
  - docs/public-api.md
125
126
  - docs/releasing.md
126
127
  - docs/verification.md
128
+ - lib/hawk-ruby.rb
127
129
  - lib/hawk.rb
128
130
  - lib/hawk/boundary.rb
129
131
  - lib/hawk/breadcrumbs.rb
@@ -140,6 +142,7 @@ files:
140
142
  - lib/hawk/filtered_fields.rb
141
143
  - lib/hawk/framework_filter.rb
142
144
  - lib/hawk/hook.rb
145
+ - lib/hawk/integrations.rb
143
146
  - lib/hawk/job_context.rb
144
147
  - lib/hawk/json_value.rb
145
148
  - lib/hawk/process_hooks.rb
@@ -177,6 +180,7 @@ files:
177
180
  - sig/hawk/filtered_fields.rbs
178
181
  - sig/hawk/framework_filter.rbs
179
182
  - sig/hawk/hook.rbs
183
+ - sig/hawk/integrations.rbs
180
184
  - sig/hawk/job_context.rbs
181
185
  - sig/hawk/json_value.rbs
182
186
  - sig/hawk/process_hooks.rbs