visionary-sdk 1.0.1 → 1.1.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/CHANGELOG.md +12 -0
- data/README.md +56 -4
- data/lib/visionary/agent.rb +7 -2
- data/lib/visionary/config.rb +8 -1
- data/lib/visionary/context.rb +33 -3
- data/lib/visionary/logs/logger.rb +274 -0
- data/lib/visionary/logs/pipeline.rb +193 -0
- data/lib/visionary/logs.rb +307 -0
- data/lib/visionary/middleware.rb +5 -1
- data/lib/visionary/schema/mysql/logs.sql +31 -0
- data/lib/visionary/schema/postgres/logs.sql +31 -0
- data/lib/visionary/schema/sqlite/logs.sql +31 -0
- data/lib/visionary/schema.rb +10 -2
- data/lib/visionary/version.rb +1 -1
- data/lib/visionary/writer.rb +10 -2
- data/lib/visionary.rb +35 -2
- metadata +8 -2
data/lib/visionary/writer.rb
CHANGED
|
@@ -15,7 +15,9 @@ module Visionary
|
|
|
15
15
|
# releases rows, and CPU profiles. Queue items are [:request, Entry],
|
|
16
16
|
# [:span, row], [:error, row], [:release, row] or [:profile, row].
|
|
17
17
|
class Writer
|
|
18
|
-
INSERTS = {
|
|
18
|
+
INSERTS = {
|
|
19
|
+
request: "api_logs", span: "spans", error: "errors", release: "releases", profile: "profiles", log: "app_logs"
|
|
20
|
+
}.freeze
|
|
19
21
|
|
|
20
22
|
def initialize(cfg, store, schemas, logger)
|
|
21
23
|
@cfg = cfg
|
|
@@ -35,7 +37,7 @@ module Visionary
|
|
|
35
37
|
|
|
36
38
|
def start
|
|
37
39
|
@thread = Thread.new { run }
|
|
38
|
-
@thread.name =
|
|
40
|
+
@thread.name = thread_name if @thread.respond_to?(:name=)
|
|
39
41
|
self
|
|
40
42
|
end
|
|
41
43
|
|
|
@@ -62,6 +64,11 @@ module Visionary
|
|
|
62
64
|
|
|
63
65
|
private
|
|
64
66
|
|
|
67
|
+
def thread_name = "visionary-writer"
|
|
68
|
+
|
|
69
|
+
# Runs on the writer thread before each wait for rows; see LogWriter.
|
|
70
|
+
def tick; end
|
|
71
|
+
|
|
65
72
|
def reset
|
|
66
73
|
@queue = BoundedQueue.new(@queue_size)
|
|
67
74
|
@thread = nil
|
|
@@ -73,6 +80,7 @@ module Visionary
|
|
|
73
80
|
next_flush = mono + @flush_interval
|
|
74
81
|
batch = []
|
|
75
82
|
loop do
|
|
83
|
+
tick
|
|
76
84
|
items = @queue.take(@batch_size - batch.size, next_flush)
|
|
77
85
|
batch.concat(items)
|
|
78
86
|
closed = @queue.closed? && @queue.size.zero?
|
data/lib/visionary.rb
CHANGED
|
@@ -9,6 +9,7 @@ require_relative "visionary/redactor"
|
|
|
9
9
|
require_relative "visionary/context"
|
|
10
10
|
require_relative "visionary/queue"
|
|
11
11
|
require_relative "visionary/writer"
|
|
12
|
+
require_relative "visionary/logs"
|
|
12
13
|
require_relative "visionary/retention"
|
|
13
14
|
require_relative "visionary/system/sources"
|
|
14
15
|
require_relative "visionary/system/cgroup"
|
|
@@ -23,7 +24,8 @@ require_relative "visionary/fork"
|
|
|
23
24
|
|
|
24
25
|
# Visionary collects what the Visionary server analyses, straight from a Ruby
|
|
25
26
|
# service: one api_logs row per HTTP request, spans for database and outbound
|
|
26
|
-
# HTTP calls, errors, deploy markers
|
|
27
|
+
# HTTP calls, errors, deploy markers, periodic system_metrics samples and the
|
|
28
|
+
# app's own log lines (app_logs).
|
|
27
29
|
#
|
|
28
30
|
# # config.ru (Sinatra, Roda, Hanami, any Rack app)
|
|
29
31
|
# require "visionary"
|
|
@@ -61,7 +63,7 @@ module Visionary
|
|
|
61
63
|
Agent.new(config).start
|
|
62
64
|
rescue StandardError => e
|
|
63
65
|
warn("visionary: start failed (#{e.class}: #{e.message}); collection is off")
|
|
64
|
-
Agent.new(Config.new.tap { |c| c.log_requests = c.system_metrics = c.spans = c.errors = false })
|
|
66
|
+
Agent.new(Config.new.tap { |c| c.log_requests = c.system_metrics = c.spans = c.errors = c.logs = false })
|
|
65
67
|
end
|
|
66
68
|
at_exit { agent.close }
|
|
67
69
|
@agent = agent
|
|
@@ -71,6 +73,36 @@ module Visionary
|
|
|
71
73
|
# The running agent, started on first use.
|
|
72
74
|
def agent = @agent || start
|
|
73
75
|
|
|
76
|
+
# The agent if it has started, without starting it.
|
|
77
|
+
def running_agent = @agent
|
|
78
|
+
|
|
79
|
+
# A Logger that copies lines to app_logs and forwards every call to inner (any ::Logger)
|
|
80
|
+
# unchanged.
|
|
81
|
+
#
|
|
82
|
+
# logger = Visionary.logger(Logger.new($stdout))
|
|
83
|
+
# logger.debug { "cart: #{cart.inspect}" } # kept when the request fails
|
|
84
|
+
def logger(inner = nil)
|
|
85
|
+
Logs::Logger.new(inner)
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
# Copies Rails.logger to app_logs without changing what Rails prints. Call it once, in an
|
|
89
|
+
# initializer; nil when Rails.logger is not set.
|
|
90
|
+
def capture_rails_logger
|
|
91
|
+
return @rails_capture if @rails_capture
|
|
92
|
+
rails = defined?(::Rails) && ::Rails.respond_to?(:logger) ? ::Rails.logger : nil
|
|
93
|
+
return nil unless rails
|
|
94
|
+
|
|
95
|
+
capture = Logs::Logger.new(nil, tags_from: rails)
|
|
96
|
+
if rails.respond_to?(:broadcast_to)
|
|
97
|
+
rails.broadcast_to(capture)
|
|
98
|
+
elsif defined?(::ActiveSupport::Logger) && ::ActiveSupport::Logger.respond_to?(:broadcast)
|
|
99
|
+
rails.extend(::ActiveSupport::Logger.broadcast(capture))
|
|
100
|
+
else
|
|
101
|
+
return nil
|
|
102
|
+
end
|
|
103
|
+
@rails_capture = capture
|
|
104
|
+
end
|
|
105
|
+
|
|
74
106
|
# The agent's span and error recorder, or nil when collection is off.
|
|
75
107
|
def telemetry = @agent&.telemetry
|
|
76
108
|
|
|
@@ -160,6 +192,7 @@ module Visionary
|
|
|
160
192
|
# rescue PaymentError => e
|
|
161
193
|
# Visionary.capture_exception(e)
|
|
162
194
|
def capture_exception(exception = $!)
|
|
195
|
+
RequestContext.current&.failed!
|
|
163
196
|
telemetry&.exception(exception, handled: true)
|
|
164
197
|
nil
|
|
165
198
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: visionary-sdk
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0
|
|
4
|
+
version: 1.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- styropyr0
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-10-
|
|
11
|
+
date: 2026-10-28 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: |
|
|
14
14
|
The Ruby collector for Visionary. A Rack middleware (with a Railtie for Rails)
|
|
@@ -29,6 +29,9 @@ files:
|
|
|
29
29
|
- lib/visionary/config.rb
|
|
30
30
|
- lib/visionary/context.rb
|
|
31
31
|
- lib/visionary/fork.rb
|
|
32
|
+
- lib/visionary/logs.rb
|
|
33
|
+
- lib/visionary/logs/logger.rb
|
|
34
|
+
- lib/visionary/logs/pipeline.rb
|
|
32
35
|
- lib/visionary/middleware.rb
|
|
33
36
|
- lib/visionary/profiler.rb
|
|
34
37
|
- lib/visionary/queue.rb
|
|
@@ -36,12 +39,15 @@ files:
|
|
|
36
39
|
- lib/visionary/redactor.rb
|
|
37
40
|
- lib/visionary/retention.rb
|
|
38
41
|
- lib/visionary/schema.rb
|
|
42
|
+
- lib/visionary/schema/mysql/logs.sql
|
|
39
43
|
- lib/visionary/schema/mysql/requests.sql
|
|
40
44
|
- lib/visionary/schema/mysql/system.sql
|
|
41
45
|
- lib/visionary/schema/mysql/telemetry.sql
|
|
46
|
+
- lib/visionary/schema/postgres/logs.sql
|
|
42
47
|
- lib/visionary/schema/postgres/requests.sql
|
|
43
48
|
- lib/visionary/schema/postgres/system.sql
|
|
44
49
|
- lib/visionary/schema/postgres/telemetry.sql
|
|
50
|
+
- lib/visionary/schema/sqlite/logs.sql
|
|
45
51
|
- lib/visionary/schema/sqlite/requests.sql
|
|
46
52
|
- lib/visionary/schema/sqlite/system.sql
|
|
47
53
|
- lib/visionary/schema/sqlite/telemetry.sql
|