currentsh 0.2.0 → 0.3.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/lib/currentsh.rb +1 -0
- data/lib/currentsh/log_output.rb +32 -1
- data/lib/currentsh/process.rb +7 -0
- data/lib/currentsh/railtie.rb +11 -1
- data/lib/currentsh/sidekiq.rb +105 -0
- data/lib/currentsh/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c4f702d9774084c47f2c4cc5c03d8c30adb4a1f3
|
4
|
+
data.tar.gz: bd38902531b45780da0fa1b171e752be475418c9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5567fbc614ca388e8bb2378044a72a02cdd5c99e0c27c8183133e859378aabadac9266a82cb7fde71a5656ac549a78000e101e99da7cec8cf9d295b7a72a2850
|
7
|
+
data.tar.gz: 4520830c7bed4048a089cbb38c913fe10eacb3c7adf931119454a746b53d7b07afc9accea9fc09a7368ed43ce033a158e56ceb6e4121f9b9f33d628d9e440bc0
|
data/lib/currentsh.rb
CHANGED
data/lib/currentsh/log_output.rb
CHANGED
@@ -4,8 +4,39 @@ module Currentsh
|
|
4
4
|
@io = io
|
5
5
|
end
|
6
6
|
|
7
|
+
def format(data)
|
8
|
+
"@current: #{data.to_json}\n"
|
9
|
+
end
|
10
|
+
|
7
11
|
def <<(data)
|
8
|
-
@io
|
12
|
+
@io << format(data)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.with_context(msg)
|
16
|
+
Thread.current[:currrentsh_sidekiq_context] ||= []
|
17
|
+
Thread.current[:currrentsh_sidekiq_context] << msg
|
18
|
+
yield
|
19
|
+
ensure
|
20
|
+
Thread.current[:currrentsh_sidekiq_context].pop
|
21
|
+
end
|
22
|
+
|
23
|
+
def call(severity, time, program_name, message)
|
24
|
+
data = {
|
25
|
+
time: time,
|
26
|
+
process: ::Process.pid,
|
27
|
+
thread: Thread.current.object_id.to_s(36),
|
28
|
+
message: message
|
29
|
+
}
|
30
|
+
|
31
|
+
if ctx = context
|
32
|
+
data.merge! ctx
|
33
|
+
end
|
34
|
+
|
35
|
+
format data
|
36
|
+
end
|
37
|
+
|
38
|
+
def context
|
39
|
+
Thread.current[:currrentsh_sidekiq_context]
|
9
40
|
end
|
10
41
|
end
|
11
42
|
end
|
data/lib/currentsh/process.rb
CHANGED
@@ -5,9 +5,16 @@ module Currentsh
|
|
5
5
|
def initialize
|
6
6
|
@output = LogOutput.new
|
7
7
|
@trackers = []
|
8
|
+
@initializers = []
|
9
|
+
end
|
10
|
+
|
11
|
+
def add_initializer(&b)
|
12
|
+
@initializers << b
|
8
13
|
end
|
9
14
|
|
10
15
|
def track_rails!(app)
|
16
|
+
@initializers.each { |i| i.call }
|
17
|
+
|
11
18
|
@output << { :type => "boot", :application => app.class.name }
|
12
19
|
rails = RailsTracker.new(@output)
|
13
20
|
rails.register
|
data/lib/currentsh/railtie.rb
CHANGED
@@ -2,11 +2,21 @@ require 'rails/railtie'
|
|
2
2
|
|
3
3
|
module Currentsh
|
4
4
|
class Railtie < Rails::Railtie
|
5
|
+
DYNO_RUN = /^run\./
|
6
|
+
|
5
7
|
config.currentsh = ActiveSupport::OrderedOptions.new
|
6
8
|
config.currentsh.enabled = false
|
9
|
+
config.currentsh.heroku_detect = true
|
7
10
|
|
8
11
|
config.after_initialize do |app|
|
9
|
-
|
12
|
+
next unless app.config.currentsh.enabled
|
13
|
+
|
14
|
+
if config.currentsh.heroku_detect
|
15
|
+
# Disable logging in a heroku run session
|
16
|
+
next if dyno = ENV['DYNO'] and DYNO_RUN.match(dyno)
|
17
|
+
end
|
18
|
+
|
19
|
+
Currentsh::PROCESS.track_rails!(app)
|
10
20
|
end
|
11
21
|
end
|
12
22
|
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
module Currentsh
|
2
|
+
class Sidekiq
|
3
|
+
def call(worker, msg, queue)
|
4
|
+
klass = msg['wrapped'] || worker.class.to_s
|
5
|
+
|
6
|
+
jid = msg['jid']
|
7
|
+
context = {
|
8
|
+
:class => klass,
|
9
|
+
:jit => jid
|
10
|
+
}
|
11
|
+
|
12
|
+
if bid = msg['bid']
|
13
|
+
context[:bid] = bid
|
14
|
+
end
|
15
|
+
|
16
|
+
LogOutput.with_context(context) do
|
17
|
+
begin
|
18
|
+
ts = start context
|
19
|
+
|
20
|
+
yield
|
21
|
+
rescue StandardError => ex
|
22
|
+
case ex
|
23
|
+
when Interrupt, SystemExit, SignalException
|
24
|
+
raise ex
|
25
|
+
else
|
26
|
+
error context, ex, ts
|
27
|
+
raise ex
|
28
|
+
end
|
29
|
+
else
|
30
|
+
stop context, ts
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def start(context)
|
36
|
+
time = Time.now
|
37
|
+
|
38
|
+
data = {
|
39
|
+
time: time,
|
40
|
+
process: ::Process.pid,
|
41
|
+
thread: Thread.current.object_id.to_s(36),
|
42
|
+
event: "start",
|
43
|
+
}.merge!(context)
|
44
|
+
|
45
|
+
$stdout.puts "@current: #{JSON.generate(data)}"
|
46
|
+
|
47
|
+
time
|
48
|
+
end
|
49
|
+
|
50
|
+
def error(context, error, start)
|
51
|
+
data = {
|
52
|
+
time: Time.now,
|
53
|
+
process: ::Process.pid,
|
54
|
+
thread: Thread.current.object_id.to_s(36),
|
55
|
+
event: "error",
|
56
|
+
error: error.to_s,
|
57
|
+
elapse: (Time.now - start)
|
58
|
+
}.merge!(context)
|
59
|
+
|
60
|
+
$stdout.puts "@current: #{JSON.generate(data)}"
|
61
|
+
end
|
62
|
+
|
63
|
+
def stop(context, start)
|
64
|
+
data = {
|
65
|
+
time: Time.now,
|
66
|
+
process: ::Process.pid,
|
67
|
+
thread: Thread.current.object_id.to_s(36),
|
68
|
+
event: "stop",
|
69
|
+
elapse: (Time.now - start)
|
70
|
+
}.merge!(context)
|
71
|
+
|
72
|
+
$stdout.puts "@current: #{JSON.generate(data)}"
|
73
|
+
end
|
74
|
+
|
75
|
+
S = ::Sidekiq
|
76
|
+
|
77
|
+
def self.configure
|
78
|
+
S.configure_server do |config|
|
79
|
+
config.server_middleware do |chain|
|
80
|
+
chain.insert_before S::Middleware::Server::Logging, self
|
81
|
+
chain.remove S::Middleware::Server::Logging
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
oldlogger = S::Logging.logger
|
86
|
+
|
87
|
+
logger = Logger.new($stdout)
|
88
|
+
logger.level = Logger::INFO
|
89
|
+
logger.formatter = LogOutput.new
|
90
|
+
|
91
|
+
S::Logging.logger = logger
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
# If using Sidekiq with Rails (likely) then the Railtie will sort this out
|
97
|
+
|
98
|
+
if defined?(Rails)
|
99
|
+
Currentsh::PROCESS.add_initializer do
|
100
|
+
Currentsh::Sidekiq.configure
|
101
|
+
end
|
102
|
+
else
|
103
|
+
Currentsh::Sidekiq.configure
|
104
|
+
end
|
105
|
+
|
data/lib/currentsh/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: currentsh
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Evan Phoenix
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -57,6 +57,7 @@ files:
|
|
57
57
|
- lib/currentsh/process.rb
|
58
58
|
- lib/currentsh/rails.rb
|
59
59
|
- lib/currentsh/railtie.rb
|
60
|
+
- lib/currentsh/sidekiq.rb
|
60
61
|
- lib/currentsh/version.rb
|
61
62
|
homepage: http://github.com/vektra/currentsh
|
62
63
|
licenses: []
|