logjam_agent 0.32.4 → 0.33.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -1
- data/lib/logjam_agent/middleware.rb +2 -0
- data/lib/logjam_agent/rack/logger.rb +23 -17
- data/lib/logjam_agent/request.rb +5 -0
- data/lib/logjam_agent/version.rb +1 -1
- data/lib/logjam_agent/zmq_forwarder.rb +6 -3
- data/test/request_test.rb +10 -0
- data/test/sinatra_test.rb +1 -0
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f7a947089e6779f029fce195520f09439948a72164dd4ee53671e129631406a9
|
4
|
+
data.tar.gz: 21daffea283fec4e44bd3d9fac3d6a47ea14c35ee1bf8b982e7a2c2c3fbd1341
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 40973d3ac9de2bf532f94b4b4aa1f5ede0aa166b9bd5182291cf21063908b06b37e281042497ff9961a8342f2d589148f685f25a8a78a516e9662fb0e2bae982
|
7
|
+
data.tar.gz: 8fb0c2d199b12967e4d9e099f73e651ff5273c433ea992495963da1a5379f01e93471239b2dc4e22c165536a0abf71e13a747a28f9118a4e1f12cd723cecf0f7
|
data/README.md
CHANGED
@@ -10,7 +10,8 @@ Has experimental support for Sinatra.
|
|
10
10
|
Currently only one mechanism is available for data transport:
|
11
11
|
ZeroMQ. Support for AMQP has been dropped.
|
12
12
|
|
13
|
-
|
13
|
+
|
14
|
+
![Build](https://github.com/skaes/logjam_agent/actions/workflows/run-tests.yml/badge.svg)
|
14
15
|
|
15
16
|
|
16
17
|
## Usage
|
@@ -50,9 +50,11 @@ module LogjamAgent
|
|
50
50
|
env_name = env["logjam_agent.environment_name"] || LogjamAgent.environment_name
|
51
51
|
caller_id = env["HTTP_X_LOGJAM_CALLER_ID"] || ""
|
52
52
|
caller_action = env["HTTP_X_LOGJAM_ACTION"] || ""
|
53
|
+
trace_id = env["HTTP_X_LOGJAM_TRACE_ID"] || ""
|
53
54
|
extra_fields = {}
|
54
55
|
extra_fields[:caller_id] = caller_id if caller_id.present?
|
55
56
|
extra_fields[:caller_action] = caller_action if caller_action.present?
|
57
|
+
extra_fields[:trace_id] = trace_id if trace_id.present?
|
56
58
|
LogjamAgent.start_request(app_name, env_name, extra_fields)
|
57
59
|
end
|
58
60
|
|
@@ -32,23 +32,16 @@ module LogjamAgent
|
|
32
32
|
|
33
33
|
def call_app(request, env)
|
34
34
|
start_time = Time.now
|
35
|
-
|
36
|
-
if
|
37
|
-
|
38
|
-
|
39
|
-
http_start_time = Time.at($1.to_f / 1_000_000.0)
|
40
|
-
elsif start_time_header =~ /\Ats=(\d+)(?:\.(\d+))?\z/
|
41
|
-
# HTTP_X_STARTTIME is seconds since the epoch (UTC) with a milliseconds resolution
|
42
|
-
http_start_time = Time.at($1.to_f + $2.to_f / 1000)
|
43
|
-
end
|
44
|
-
|
45
|
-
if http_start_time && (wait_time_ms = (start_time - http_start_time) * 1000) > 0
|
35
|
+
wait_time_ms = 0.0
|
36
|
+
if http_start_time = extract_http_start_time(env)
|
37
|
+
wait_time_ms = (start_time - http_start_time) * 1000
|
38
|
+
if wait_time_ms > 0
|
46
39
|
start_time = http_start_time
|
40
|
+
else
|
41
|
+
wait_time_ms = 0.0
|
47
42
|
end
|
48
|
-
else
|
49
|
-
wait_time_ms = 0.0
|
50
43
|
end
|
51
|
-
before_dispatch(request, env, start_time)
|
44
|
+
before_dispatch(request, env, start_time, wait_time_ms)
|
52
45
|
result = @app.call(env)
|
53
46
|
rescue ActionDispatch::RemoteIp::IpSpoofAttackError
|
54
47
|
result = [403, {}, ['Forbidden']]
|
@@ -57,6 +50,20 @@ module LogjamAgent
|
|
57
50
|
after_dispatch(env, result, run_time_ms, wait_time_ms)
|
58
51
|
end
|
59
52
|
|
53
|
+
def extract_http_start_time(env)
|
54
|
+
start_time_header = env['HTTP_X_STARTTIME']
|
55
|
+
if start_time_header
|
56
|
+
if start_time_header =~ /\At=(\d+)\z/
|
57
|
+
# HTTP_X_STARTTIME is microseconds since the epoch (UTC)
|
58
|
+
return Time.at($1.to_f / 1_000_000.0)
|
59
|
+
elsif start_time_header =~ /\Ats=(\d+)(?:\.(\d+))?\z/
|
60
|
+
# HTTP_X_STARTTIME is seconds since the epoch (UTC) with a milliseconds resolution
|
61
|
+
return Time.at($1.to_f + $2.to_f / 1000)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
return nil
|
65
|
+
end
|
66
|
+
|
60
67
|
def compute_tags(request)
|
61
68
|
@taggers.collect do |tag|
|
62
69
|
case tag
|
@@ -78,7 +85,7 @@ module LogjamAgent
|
|
78
85
|
false
|
79
86
|
end
|
80
87
|
|
81
|
-
def before_dispatch(request, env, start_time)
|
88
|
+
def before_dispatch(request, env, start_time, wait_time_ms)
|
82
89
|
logger.formatter.reset_attributes if logger.formatter.respond_to?(:reset_attributes)
|
83
90
|
TimeBandits.reset
|
84
91
|
Thread.current.thread_variable_set(:time_bandits_completed_info, nil)
|
@@ -90,6 +97,7 @@ module LogjamAgent
|
|
90
97
|
|
91
98
|
logjam_request.start_time = start_time
|
92
99
|
logjam_fields = logjam_request.fields
|
100
|
+
logjam_fields[:wait_time] = wait_time_ms if wait_time_ms > 0.0
|
93
101
|
spoofed = nil
|
94
102
|
ip = nil
|
95
103
|
begin
|
@@ -125,7 +133,6 @@ module LogjamAgent
|
|
125
133
|
|
126
134
|
if wait_time_ms < 0
|
127
135
|
warn LogjamAgent::NegativeWaitTime.new("#{wait_time_ms} ms")
|
128
|
-
wait_time_ms = 0.0
|
129
136
|
end
|
130
137
|
|
131
138
|
message = "Completed #{status} #{::Rack::Utils::HTTP_STATUS_CODES[status]} in %.1fms" % run_time_ms
|
@@ -135,7 +142,6 @@ module LogjamAgent
|
|
135
142
|
ActiveSupport::LogSubscriber.flush_all!
|
136
143
|
request_info = { :total_time => run_time_ms, :code => status }
|
137
144
|
request_info[:view_time] = view_time if view_time
|
138
|
-
request_info[:wait_time] = wait_time_ms if wait_time_ms > 0
|
139
145
|
logjam_request.fields.merge!(request_info)
|
140
146
|
|
141
147
|
env["time_bandits.metrics"] = TimeBandits.metrics
|
data/lib/logjam_agent/request.rb
CHANGED
@@ -17,6 +17,7 @@ module LogjamAgent
|
|
17
17
|
@uuid = LogjamAgent.generate_uuid
|
18
18
|
@fields = initial_fields.merge(:request_id => @uuid, :host => LogjamAgent.hostname,
|
19
19
|
:process_id => Process.pid, :lines => @lines)
|
20
|
+
@fields[:trace_id] ||= @uuid
|
20
21
|
unless (revision = LogjamAgent.application_revision).blank?
|
21
22
|
@fields[:revision] = revision
|
22
23
|
end
|
@@ -70,6 +71,10 @@ module LogjamAgent
|
|
70
71
|
@fields[:caller_action]
|
71
72
|
end
|
72
73
|
|
74
|
+
def trace_id
|
75
|
+
@fields[:trace_id]
|
76
|
+
end
|
77
|
+
|
73
78
|
def add_line(severity, timestamp, message)
|
74
79
|
@mutex.synchronize do
|
75
80
|
if @bytes_all_lines > @max_bytes_all_lines
|
data/lib/logjam_agent/version.rb
CHANGED
@@ -45,7 +45,8 @@ module LogjamAgent
|
|
45
45
|
begin
|
46
46
|
require 'ffi-rzmq'
|
47
47
|
context = ZMQ::Context.new(1)
|
48
|
-
|
48
|
+
pid = Process.pid
|
49
|
+
at_exit { context.terminate if Process.pid == pid }
|
49
50
|
context
|
50
51
|
end
|
51
52
|
end
|
@@ -59,7 +60,8 @@ module LogjamAgent
|
|
59
60
|
|
60
61
|
def ensure_ping_at_exit
|
61
62
|
return if @ping_ensured
|
62
|
-
|
63
|
+
pid = Process.pid
|
64
|
+
at_exit { (ping; reset) if Process.pid == pid }
|
63
65
|
@ping_ensured = true
|
64
66
|
end
|
65
67
|
|
@@ -99,7 +101,8 @@ module LogjamAgent
|
|
99
101
|
if LogjamAgent.ensure_ping_at_exit
|
100
102
|
ensure_ping_at_exit
|
101
103
|
else
|
102
|
-
|
104
|
+
pid = Process.pid
|
105
|
+
at_exit { reset if Process.pid == pid}
|
103
106
|
end
|
104
107
|
@socket.setsockopt(ZMQ::LINGER, @config[:linger])
|
105
108
|
@socket.setsockopt(ZMQ::SNDHWM, @config[:snd_hwm])
|
data/test/request_test.rb
CHANGED
@@ -44,6 +44,16 @@ module LogjamAgent
|
|
44
44
|
assert_equal TRUNCATED_LINE, lines(@request)[1][2]
|
45
45
|
end
|
46
46
|
|
47
|
+
def test_sets_trace_id_to_request_id_if_not_passed_in
|
48
|
+
assert_equal @request.uuid, @request.fields[:trace_id]
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_sets_trace_id_to_passed_in_field_value
|
52
|
+
trace_id = "murks"
|
53
|
+
request = Request.new("app", "env", {trace_id: trace_id})
|
54
|
+
assert_equal trace_id, request.fields[:trace_id]
|
55
|
+
end
|
56
|
+
|
47
57
|
private
|
48
58
|
|
49
59
|
def lines(request)
|
data/test/sinatra_test.rb
CHANGED
@@ -37,6 +37,7 @@ module LogjamAgent
|
|
37
37
|
assert_kind_of String, payload["started_at"]
|
38
38
|
assert_kind_of Integer, payload["started_ms"]
|
39
39
|
assert_kind_of String, payload["ip"]
|
40
|
+
assert_nil payload["wait_time"]
|
40
41
|
# assert_kind_of Float, payload["view_time"]
|
41
42
|
lines = payload["lines"]
|
42
43
|
assert_match(/Started GET.*password=\[FILTERED\]/, lines[0][2])
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logjam_agent
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.33.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stefan Kaes
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-07-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -275,16 +275,16 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
275
275
|
- !ruby/object:Gem::Version
|
276
276
|
version: '0'
|
277
277
|
requirements: []
|
278
|
-
rubygems_version: 3.
|
278
|
+
rubygems_version: 3.3.15
|
279
279
|
signing_key:
|
280
280
|
specification_version: 4
|
281
281
|
summary: Logjam client library to be used with logjam
|
282
282
|
test_files:
|
283
|
+
- test/request_test.rb
|
283
284
|
- test/sinatra_app.rb
|
284
|
-
- test/sinatra_classic_test.rb
|
285
285
|
- test/sinatra_classic_app.rb
|
286
|
-
- test/
|
287
|
-
- test/zmq_forwarder_test.rb
|
288
|
-
- test/util_test.rb
|
289
|
-
- test/test_helper.rb
|
286
|
+
- test/sinatra_classic_test.rb
|
290
287
|
- test/sinatra_test.rb
|
288
|
+
- test/test_helper.rb
|
289
|
+
- test/util_test.rb
|
290
|
+
- test/zmq_forwarder_test.rb
|