Module: Bugwatch
- Defined in:
- lib/bugwatch.rb,
lib/bugwatch/railtie.rb,
lib/bugwatch/version.rb,
lib/bugwatch/middleware.rb,
lib/bugwatch/notification.rb,
lib/bugwatch/user_context.rb,
lib/bugwatch/configuration.rb,
lib/bugwatch/error_builder.rb,
lib/bugwatch/report_builder.rb,
lib/bugwatch/feedback_helper.rb,
lib/bugwatch/feedback_sender.rb,
lib/bugwatch/error_subscriber.rb,
lib/bugwatch/backtrace_cleaner.rb,
lib/bugwatch/active_job_handler.rb,
lib/bugwatch/transaction_buffer.rb,
lib/bugwatch/transaction_sender.rb,
lib/bugwatch/breadcrumb_collector.rb
Defined Under Namespace
Modules: BreadcrumbCollector, ControllerMethods, FeedbackHelper, UserContext
Classes: ActiveJobHandler, BacktraceCleaner, Configuration, ErrorBuilder, ErrorSubscriber, FeedbackSender, Middleware, Notification, Railtie, ReportBuilder, TransactionBuffer, TransactionSender
Constant Summary
collapse
- VERSION =
"0.5.0"
Class Method Summary
collapse
-
.check_in(slug) ⇒ Object
-
.configuration ⇒ Object
-
.configure {|configuration| ... } ⇒ Object
-
.leave_breadcrumb(message, type: "manual", metadata: {}) ⇒ Object
-
.notify(exception, context: {}) ⇒ Object
-
.report(title, category: "other", severity: "warning", tags: {}) ⇒ Object
-
.send_feedback(message, email: nil, name: nil, url: nil, issue_id: nil, metadata: {}) ⇒ Object
-
.set_user(id: nil, email: nil, name: nil, **custom) ⇒ Object
-
.track_deploy(version:, environment: nil, description: nil, deployed_by: nil) ⇒ Object
-
.transaction_buffer ⇒ Object
Class Method Details
.check_in(slug) ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/bugwatch.rb', line 65
def check_in(slug)
return unless configuration.api_key
return unless configuration.endpoint
Thread.new do
uri = URI.parse("#{configuration.endpoint.chomp("/")}/api/v1/monitors/#{slug}/check_in")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = uri.scheme == "https"
http.open_timeout = 3
http.read_timeout = 3
http.write_timeout = 3
request = Net::HTTP::Post.new(uri.path)
request["X-Api-Key"] = configuration.api_key
request["X-BugWatch-Ruby"] = Bugwatch::VERSION
http.request(request)
rescue StandardError
end
end
|
.configuration ⇒ Object
23
24
25
|
# File 'lib/bugwatch.rb', line 23
def configuration
@configuration ||= Configuration.new
end
|
27
28
29
|
# File 'lib/bugwatch.rb', line 27
def configure
yield configuration
end
|
.leave_breadcrumb(message, type: "manual", metadata: {}) ⇒ Object
61
62
63
|
# File 'lib/bugwatch.rb', line 61
def leave_breadcrumb(message, type: "manual", metadata: {})
BreadcrumbCollector.add(message, type: type, metadata: metadata)
end
|
.notify(exception, context: {}) ⇒ Object
31
32
33
34
35
36
37
38
|
# File 'lib/bugwatch.rb', line 31
def notify(exception, context: {})
return if configuration.ignore?(exception)
return unless configuration.notify_for_release_stage?
payload = ErrorBuilder.new(exception).build
payload.merge!(context)
Notification.new(payload).deliver
end
|
.report(title, category: "other", severity: "warning", tags: {}) ⇒ Object
40
41
42
43
44
45
46
|
# File 'lib/bugwatch.rb', line 40
def report(title, category: "other", severity: "warning", tags: {})
return unless configuration.notify_for_release_stage?
return if title.to_s.strip.empty?
payload = ReportBuilder.new(title, category: category, severity: severity, tags: tags).build
Notification.new(payload).deliver
end
|
.send_feedback(message, email: nil, name: nil, url: nil, issue_id: nil, metadata: {}) ⇒ Object
48
49
50
51
52
53
54
55
|
# File 'lib/bugwatch.rb', line 48
def send_feedback(message, email: nil, name: nil, url: nil, issue_id: nil, metadata: {})
return if message.to_s.strip.empty?
FeedbackSender.new(
message: message, email: email, name: name,
url: url, issue_id: issue_id, metadata: metadata
).deliver
end
|
.set_user(id: nil, email: nil, name: nil, **custom) ⇒ Object
57
58
59
|
# File 'lib/bugwatch.rb', line 57
def set_user(id: nil, email: nil, name: nil, **custom)
UserContext.set(id: id, email: email, name: name, **custom)
end
|
.track_deploy(version:, environment: nil, description: nil, deployed_by: nil) ⇒ Object
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
# File 'lib/bugwatch.rb', line 88
def track_deploy(version:, environment: nil, description: nil, deployed_by: nil)
return unless configuration.api_key
return unless configuration.endpoint
env = environment || configuration.release_stage
Thread.new do
uri = URI.parse("#{configuration.endpoint.chomp("/")}/api/v1/deploys")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = uri.scheme == "https"
http.open_timeout = 3
http.read_timeout = 3
http.write_timeout = 3
request = Net::HTTP::Post.new(uri.path)
request["Content-Type"] = "application/json"
request["X-Api-Key"] = configuration.api_key
request["X-BugWatch-Ruby"] = Bugwatch::VERSION
payload = { version: version, environment: env, deployed_at: Time.now.iso8601 }
payload[:description] = description if description
payload[:deployed_by] = deployed_by if deployed_by
request.body = JSON.generate(payload)
http.request(request)
rescue StandardError
end
end
|
.transaction_buffer ⇒ Object
120
121
122
|
# File 'lib/bugwatch.rb', line 120
def transaction_buffer
@transaction_buffer ||= TransactionBuffer.new(config: configuration)
end
|