logjam_agent 0.35.1 → 0.37.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3f6c65ee6f965cad2efa823e0c7bbdc2445bcc03b5eb5b925a80a3cf5750440b
4
- data.tar.gz: cfc487c0f873c6eeb63e90c2680c31394eb112231a9a8f17273864bf26f1f5a3
3
+ metadata.gz: b0980fb837410c08361600e378f44a6bacf83a36ecd95fa3090348f4dc0ca5d9
4
+ data.tar.gz: 8f191a84d982672fee5a7b00bfc8faf9d37c98f6573ecd2c72911fc00584986e
5
5
  SHA512:
6
- metadata.gz: 9465b7e6caf9e029b6d68112829a5720f2ee3d3ffc31b53cf3331b24497a9c46f971f3cd30b683feba7022bb56066797fb18b8fc35bd2f542510fd2a9d844eb3
7
- data.tar.gz: f5217174aaf9331df102b3a367d6e1d755cc2a689c8e778c7b676d8469e9ba32159b3c06d8d4dccdad956811f55ec86e50e6af935be698ad9f7bb0179b22aff6
6
+ metadata.gz: 9f7c46d32b4c7dd42279a9e20a4b834baad1082201234fb8ccd26466846d04572139d1542abe5c637bba39cc722177952fa67a639bc05d6f8c379d19867fbece
7
+ data.tar.gz: 2f56ac4b0f6e6b0a9e7c11e5b7b6314343726f8fa9c164181f2c5dd7b262e207ef5b6739d90f5afb38fb6857c87168a07457c25a371d094d66b86541af961735
data/README.md CHANGED
@@ -62,6 +62,12 @@ module LogjamAgent
62
62
  # to debug asset request handling.
63
63
  self.ignore_asset_requests = Rails.env.development?
64
64
 
65
+ # Configure a list of URL patterns for which no data should be sent
66
+ # to logjam and nothing should be sent to the log device. Please not
67
+ # that the log lines will still show up in dev mode on the console.
68
+ # Defaults to the empty list.
69
+ # self.ignored_request_urls = [%r{/_system/}]
70
+
65
71
  # Disable ActiveSupport::Notifications (and thereby logging) of ActionView
66
72
  # render events. Defaults to false.
67
73
  # self.ignore_render_events = Rails.env.production?
@@ -57,6 +57,7 @@ module LogjamAgent
57
57
  end
58
58
  end
59
59
  log_to_log_device = LogjamAgent.log_to_log_device?(severity, message)
60
+ log_to_log_device = false if request && request.ignored?
60
61
  attributes = formatter.render_attributes
61
62
  message = "[#{attributes}] #{message}" if attributes
62
63
  time = Time.now
@@ -11,6 +11,7 @@ module LogjamAgent
11
11
  @hostname = LogjamAgent.hostname
12
12
  @asset_prefix = Rails.application.config.assets.prefix rescue "---"
13
13
  @ignore_asset_requests = LogjamAgent.ignore_asset_requests
14
+ @ignored_request_urls = LogjamAgent.ignored_request_urls
14
15
  end
15
16
 
16
17
  def call(env)
@@ -88,6 +89,12 @@ module LogjamAgent
88
89
  false
89
90
  end
90
91
 
92
+ def ignored_request_url?(path)
93
+ @ignored_request_urls.any?{|url_pattern| path =~ url_pattern}
94
+ rescue
95
+ false
96
+ end
97
+
91
98
  def before_dispatch(request, env, start_time, wait_time_ms)
92
99
  logger.formatter.reset_attributes if logger.formatter.respond_to?(:reset_attributes)
93
100
  TimeBandits.reset
@@ -96,7 +103,11 @@ module LogjamAgent
96
103
  path = request.filtered_path
97
104
 
98
105
  logjam_request = LogjamAgent.request
99
- logjam_request.ignore! if ignored_asset_request?(path)
106
+ logjam_request.ignore!(:asset) if ignored_asset_request?(path)
107
+ logjam_request.ignore!(:url) if ignored_request_url?(path)
108
+
109
+ logjam_request.log_info[:path] = path
110
+ logjam_request.log_info[:method] = request.method
100
111
 
101
112
  logjam_request.start_time = start_time
102
113
  logjam_fields = logjam_request.fields
@@ -111,7 +122,9 @@ module LogjamAgent
111
122
  logjam_fields.merge!(:ip => ip, :host => @hostname)
112
123
  logjam_fields.merge!(extract_request_info(request))
113
124
 
114
- info "Started #{request.request_method} \"#{path}\" for #{ip} at #{start_time.to_default_s}" unless logjam_request.ignored?
125
+ LogjamAgent.logjam_only do
126
+ info "Started #{request.request_method} \"#{path}\" for #{ip} at #{start_time.to_default_s}" unless logjam_request.ignored?(:asset)
127
+ end
115
128
  if spoofed
116
129
  error spoofed
117
130
  raise spoofed
@@ -138,9 +151,20 @@ module LogjamAgent
138
151
  warn LogjamAgent::NegativeWaitTime.new("#{wait_time_ms} ms")
139
152
  end
140
153
 
141
- message = "Completed #{status} #{::Rack::Utils::HTTP_STATUS_CODES[status]} in %.1fms" % run_time_ms
142
- message << " (#{additions.join(' | ')})" unless additions.blank?
143
- info message unless logjam_request.ignored?
154
+ http_status = "#{status} #{::Rack::Utils::HTTP_STATUS_CODES[status]}"
155
+ LogjamAgent.logjam_only do
156
+ message = "Completed #{http_status} in %.1fms" % run_time_ms
157
+ message << " (#{additions.join(' | ')})" unless additions.blank?
158
+ info message unless logjam_request.ignored?(:asset)
159
+ end
160
+ if LogjamAgent.selective_logging_enabled
161
+ LogjamAgent.logdevice_only do
162
+ logjam_request.log_info[:status] = status
163
+ logjam_request.log_info[:duration] = run_time_ms
164
+ # logjam_request.log_info[:metrics] = TimeBandits.metrics.reject{|k,v| v.zero?}
165
+ info "Completed #{http_status} #{logjam_request.log_info.to_json}"
166
+ end
167
+ end
144
168
 
145
169
  ActiveSupport::LogSubscriber.flush_all!
146
170
  request_info = { :total_time => run_time_ms, :code => status }
@@ -16,10 +16,18 @@ module ActionController #:nodoc:
16
16
  full_name = "#{controller}##{action}"
17
17
  action_name = LogjamAgent.action_name_proc.call(full_name)
18
18
 
19
- LogjamAgent.request.fields[:action] = action_name
19
+ request = LogjamAgent.request
20
+ request.fields[:action] = action_name
20
21
 
21
- info "Processing by #{full_name} as #{format}"
22
- info " Parameters: #{params.inspect}" unless params.empty?
22
+ request.log_info[:action] = action
23
+ request.log_info[:controller] = controller
24
+ request.log_info[:format] = format
25
+ # request.log_info[:params] = params
26
+
27
+ LogjamAgent.logjam_only do
28
+ info "Processing by #{full_name} as #{format}"
29
+ info " Parameters: #{params.inspect}" unless params.empty?
30
+ end
23
31
  end
24
32
  end
25
33
 
@@ -6,7 +6,7 @@ end
6
6
 
7
7
  module LogjamAgent
8
8
  class Request
9
- attr_reader :fields, :uuid, :start_time
9
+ attr_reader :fields, :uuid, :start_time, :log_info
10
10
  attr_accessor :log_device_ignored_lines
11
11
 
12
12
  def initialize(app, env, initial_fields)
@@ -39,6 +39,7 @@ module LogjamAgent
39
39
  @max_bytes_all_lines = LogjamAgent.max_bytes_all_lines
40
40
  @max_line_length = LogjamAgent.max_line_length
41
41
  @lines_dropped = false
42
+ @log_info = {}
42
43
  end
43
44
 
44
45
  def start_time=(start_time)
@@ -47,12 +48,12 @@ module LogjamAgent
47
48
  @fields[:started_ms] = start_time.tv_sec * 1000 + start_time.tv_usec / 1000
48
49
  end
49
50
 
50
- def ignore!
51
- @ignored = true
51
+ def ignore!(reason = nil)
52
+ @ignored = reason || :unknown
52
53
  end
53
54
 
54
- def ignored?
55
- @ignored
55
+ def ignored?(reason = nil)
56
+ reason ? @ignored == reason : @ignored
56
57
  end
57
58
 
58
59
  def id
@@ -1,3 +1,3 @@
1
1
  module LogjamAgent
2
- VERSION = "0.35.1"
2
+ VERSION = "0.37.0"
3
3
  end
data/lib/logjam_agent.rb CHANGED
@@ -133,6 +133,9 @@ module LogjamAgent
133
133
  mattr_accessor :exception_matcher
134
134
  self.exception_matcher = nil
135
135
 
136
+ mattr_accessor :ignored_request_urls
137
+ self.ignored_request_urls = []
138
+
136
139
  mattr_accessor :ignore_asset_requests
137
140
  self.ignore_asset_requests = false
138
141
 
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.35.1
4
+ version: 0.37.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefan Kaes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-10-17 00:00:00.000000000 Z
11
+ date: 2022-10-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake