railswatch_gem 0.1.0 → 0.1.1
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/lib/railswatch_gem/client.rb +21 -8
- data/lib/railswatch_gem/version.rb +1 -1
- metadata +3 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: cb0eec72b0b4b1904079261950d3780b713f068f25dc2347c1d606369b86b083
|
|
4
|
+
data.tar.gz: f390ff3575ed2c6b6df73fc0dbb2ee64f176169d51a7cdb733e4d7cc0f591036
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 549bd28842b55b51cb78112d5c03e971abce96cb5d15983defa211f7814f984ef869b1575dc022b93c9c554ceec4e02907671b48de001bf691bdaa38dd4f3401
|
|
7
|
+
data.tar.gz: 3b7d77f1529eb2a8b35f745426867ea2c8e202e75f5044bf2ea126690be17963862709099665beafc3b0ce546cffb3ae8ce2e7e098320406e87f90f8b64e5e92
|
|
@@ -31,6 +31,8 @@ module RailswatchGem
|
|
|
31
31
|
def record(event)
|
|
32
32
|
return unless @running
|
|
33
33
|
|
|
34
|
+
ensure_worker_running
|
|
35
|
+
|
|
34
36
|
normalized = normalize_event(event)
|
|
35
37
|
|
|
36
38
|
# Non-blocking push. If queue is full, we drop the event to protect the app.
|
|
@@ -39,7 +41,7 @@ module RailswatchGem
|
|
|
39
41
|
rescue ThreadError
|
|
40
42
|
# Queue is full. Log warning periodically or increment a metric.
|
|
41
43
|
# Avoid logging every failure to prevent disk fill-up.
|
|
42
|
-
log_error("
|
|
44
|
+
log_error("Buffer full. Dropping event.")
|
|
43
45
|
end
|
|
44
46
|
end
|
|
45
47
|
|
|
@@ -50,9 +52,21 @@ module RailswatchGem
|
|
|
50
52
|
|
|
51
53
|
private
|
|
52
54
|
|
|
55
|
+
def ensure_worker_running
|
|
56
|
+
# If the thread is dead (killed by fork) or nil, restart it.
|
|
57
|
+
# This is crucial for pre-forking web servers like Puma or Unicorn.
|
|
58
|
+
if @worker_thread.nil? || !@worker_thread.alive?
|
|
59
|
+
# Avoid log spam if multiple threads hit this at once
|
|
60
|
+
@logger.info("[Railswatch] Restarting worker thread (PID changed or thread died)") unless @worker_thread&.alive?
|
|
61
|
+
start_worker_thread
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
53
65
|
def normalize_event(event)
|
|
54
66
|
event = event.dup
|
|
55
|
-
|
|
67
|
+
# FIX: Use iso8601(6) to ensure microseconds are sent to the server.
|
|
68
|
+
# Without (6), events in the same second look simultaneous (+0ms).
|
|
69
|
+
event[:timestamp] ||= Time.now.utc.iso8601(6)
|
|
56
70
|
event[:event_type] ||= "custom"
|
|
57
71
|
event
|
|
58
72
|
end
|
|
@@ -61,8 +75,6 @@ module RailswatchGem
|
|
|
61
75
|
@worker_thread = Thread.new do
|
|
62
76
|
while @running
|
|
63
77
|
# Wait for events or timeout (interval)
|
|
64
|
-
# We use a simple sleep loop here for simplicity,
|
|
65
|
-
# but a ConditionVariable could be used for smarter waking.
|
|
66
78
|
current_batch = []
|
|
67
79
|
|
|
68
80
|
# Drain queue up to batch size
|
|
@@ -112,9 +124,10 @@ module RailswatchGem
|
|
|
112
124
|
|
|
113
125
|
def send_batch(events)
|
|
114
126
|
# Using Net::HTTP.start with a block handles opening/closing cleanly.
|
|
115
|
-
# For higher performance, keep the connection open in an instance variable,
|
|
116
|
-
# but handle timeouts and reconnection logic.
|
|
117
127
|
Net::HTTP.start(@ingest_uri.host, @ingest_uri.port, use_ssl: @ingest_uri.scheme == "https") do |http|
|
|
128
|
+
http.open_timeout = 5
|
|
129
|
+
http.read_timeout = 5
|
|
130
|
+
|
|
118
131
|
request = Net::HTTP::Post.new(@ingest_uri.request_uri)
|
|
119
132
|
request["Content-Type"] = "application/json"
|
|
120
133
|
request["Environment-Token"] = @env_token
|
|
@@ -123,11 +136,11 @@ module RailswatchGem
|
|
|
123
136
|
response = http.request(request)
|
|
124
137
|
|
|
125
138
|
unless response.is_a?(Net::HTTPSuccess) || response.code.to_i == 202
|
|
126
|
-
log_error("
|
|
139
|
+
log_error("Ingest failed: #{response.code} #{response.body}")
|
|
127
140
|
end
|
|
128
141
|
end
|
|
129
142
|
rescue => e
|
|
130
|
-
log_error("
|
|
143
|
+
log_error("Transmission failed: #{e.class} - #{e.message}")
|
|
131
144
|
end
|
|
132
145
|
|
|
133
146
|
def default_logger
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: railswatch_gem
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Tyler Hammett
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: exe
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies: []
|
|
13
12
|
description: Railswatch Gem
|
|
14
13
|
email:
|
|
@@ -50,7 +49,6 @@ metadata:
|
|
|
50
49
|
homepage_uri: https://github.com/railswatch/railswatch_gem
|
|
51
50
|
source_code_uri: https://github.com/railswatch/railswatch_gem
|
|
52
51
|
changelog_uri: https://github.com/railswatch/railswatch_gem/blob/main/CHANGELOG.md
|
|
53
|
-
post_install_message:
|
|
54
52
|
rdoc_options: []
|
|
55
53
|
require_paths:
|
|
56
54
|
- lib
|
|
@@ -65,8 +63,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
65
63
|
- !ruby/object:Gem::Version
|
|
66
64
|
version: '0'
|
|
67
65
|
requirements: []
|
|
68
|
-
rubygems_version:
|
|
69
|
-
signing_key:
|
|
66
|
+
rubygems_version: 4.0.1
|
|
70
67
|
specification_version: 4
|
|
71
68
|
summary: Railswatch Gem
|
|
72
69
|
test_files: []
|