logjam_agent 0.4.5 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -23,9 +23,12 @@ module LogjamAgent
23
23
  Thread.current[:time_bandits_completed_info] = nil
24
24
 
25
25
  request = ActionDispatch::Request.new(env)
26
+
26
27
  path = request.filtered_path
27
28
 
28
- Rails.logger.request.fields.merge!(:started_at => start_time.iso8601, :ip => request.ip, :host => @hostname)
29
+ logjam_fields = Rails.logger.request.fields
30
+ logjam_fields.merge!(:started_at => start_time.iso8601, :ip => request.ip, :host => @hostname)
31
+ logjam_fields.merge!(extract_request_info(request))
29
32
 
30
33
  info "\n\nStarted #{request.request_method} \"#{path}\" for #{request.ip} at #{start_time.to_default_s}"
31
34
  end
@@ -34,7 +37,7 @@ module LogjamAgent
34
37
  status = result ? result.first : 500
35
38
  duration, additions, view_time, action = Thread.current[:time_bandits_completed_info]
36
39
 
37
- basic_request_info = {:total_time => run_time_ms, :code => status, :action => action, :view_time => view_time || 0.0}
40
+ request_info = {:total_time => run_time_ms, :code => status, :action => action, :view_time => view_time || 0.0}
38
41
 
39
42
  message = "Completed #{status} #{::Rack::Utils::HTTP_STATUS_CODES[status]} in %.1fms" % run_time_ms
40
43
  message << " (#{additions.join(' | ')})" unless additions.blank?
@@ -42,11 +45,69 @@ module LogjamAgent
42
45
 
43
46
  ActiveSupport::LogSubscriber.flush_all!
44
47
 
45
- Rails.logger.request.fields.merge!(basic_request_info)
48
+ Rails.logger.request.fields.merge!(request_info)
46
49
 
47
50
  env["time_bandits.metrics"] = TimeBandits.metrics
48
51
  end
49
52
 
53
+ HIDDEN_VARIABLES = /\A([a-z]|SERVER|PATH|GATEWAY|REQUEST|SCRIPT|REMOTE|QUERY|PASSENGER|DOCUMENT|SCGI|UNION_STATION)/o
54
+
55
+ TRANSLATED_VARIABLES = /\A(HTTP|CONTENT_LENGTH)/
56
+
57
+ TRANSLATED_KEYS = Hash.new do |h,k|
58
+ h[k] = k.sub(/\AHTTP_/,'').split('_').map(&:capitalize).join('-') if k =~ TRANSLATED_VARIABLES
59
+ end
60
+
61
+ REFERER = 'HTTP_REFERER'
62
+ CONTENT_LENGTH = 'CONTENT_LENGTH'
63
+
64
+ KV_RE = '[^&;=]+'
65
+ PAIR_RE = %r{(#{KV_RE})=(#{KV_RE})}
66
+
67
+ def extract_request_info(request)
68
+ request_info = {}
69
+ filter = request.send(:parameter_filter)
70
+
71
+ request_info[:method] = request.method
72
+ request_info[:url] = request.filtered_path
73
+ request_info[:headers] = extract_headers(request, filter)
74
+
75
+ unless request.query_string.empty?
76
+ query_params = filter.filter(request.query_parameters)
77
+ request_info[:query_parameters] = query_params unless query_params.empty?
78
+ end
79
+
80
+ unless request.content_length == 0
81
+ body_params = filter.filter(request.request_parameters)
82
+ request_info[:body_parameters] = body_params unless body_params.empty?
83
+ end
84
+
85
+ { :request_info => request_info }
86
+ rescue Exception
87
+ Rails.logger.error($!)
88
+ {}
89
+ end
90
+
91
+ def extract_headers(request, filter)
92
+ headers = request.filtered_env
93
+ headers.reject!{|k,v| k =~ HIDDEN_VARIABLES }
94
+ headers.delete(CONTENT_LENGTH) if request.content_length == 0
95
+
96
+ if referer = headers[REFERER]
97
+ headers[REFERER] = referer.gsub(PAIR_RE) do |_|
98
+ filter.filter([[$1, $2]]).first.join("=")
99
+ end
100
+ end
101
+
102
+ headers.keys.each do |k|
103
+ if t = TRANSLATED_KEYS[k]
104
+ headers[t] = headers.delete(k)
105
+ end
106
+ end
107
+
108
+ headers
109
+ end
110
+
50
111
  end
51
112
  end
52
113
  end
@@ -1,3 +1,3 @@
1
1
  module LogjamAgent
2
- VERSION = "0.4.5"
2
+ VERSION = "0.5.0"
3
3
  end
metadata CHANGED
@@ -1,103 +1,104 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: logjam_agent
3
- version: !ruby/object:Gem::Version
4
- version: 0.4.5
3
+ version: !ruby/object:Gem::Version
4
+ hash: 11
5
5
  prerelease:
6
+ segments:
7
+ - 0
8
+ - 5
9
+ - 0
10
+ version: 0.5.0
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - Stefan Kaes
9
14
  autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
- date: 2012-08-02 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
17
+
18
+ date: 2012-09-15 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
15
21
  name: rake
16
- requirement: !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
21
- version: '0'
22
- type: :development
23
22
  prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ! '>='
28
- - !ruby/object:Gem::Version
29
- version: '0'
30
- - !ruby/object:Gem::Dependency
31
- name: i18n
32
- requirement: !ruby/object:Gem::Requirement
23
+ requirement: &id001 !ruby/object:Gem::Requirement
33
24
  none: false
34
- requirements:
35
- - - ! '>='
36
- - !ruby/object:Gem::Version
37
- version: '0'
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
38
32
  type: :development
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: i18n
39
36
  prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
37
+ requirement: &id002 !ruby/object:Gem::Requirement
41
38
  none: false
42
- requirements:
43
- - - ! '>='
44
- - !ruby/object:Gem::Version
45
- version: '0'
46
- - !ruby/object:Gem::Dependency
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: 3
43
+ segments:
44
+ - 0
45
+ version: "0"
46
+ type: :development
47
+ version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
47
49
  name: activesupport
48
- requirement: !ruby/object:Gem::Requirement
49
- none: false
50
- requirements:
51
- - - ! '>='
52
- - !ruby/object:Gem::Version
53
- version: '0'
54
- type: :runtime
55
50
  prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
51
+ requirement: &id003 !ruby/object:Gem::Requirement
57
52
  none: false
58
- requirements:
59
- - - ! '>='
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- - !ruby/object:Gem::Dependency
63
- name: uuid4r
64
- requirement: !ruby/object:Gem::Requirement
65
- none: false
66
- requirements:
67
- - - ! '>='
68
- - !ruby/object:Gem::Version
69
- version: '0'
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ hash: 3
57
+ segments:
58
+ - 0
59
+ version: "0"
70
60
  type: :runtime
61
+ version_requirements: *id003
62
+ - !ruby/object:Gem::Dependency
63
+ name: uuid4r
71
64
  prerelease: false
72
- version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
- requirements:
75
- - - ! '>='
76
- - !ruby/object:Gem::Version
77
- version: '0'
78
- - !ruby/object:Gem::Dependency
79
- name: time_bandits
80
- requirement: !ruby/object:Gem::Requirement
65
+ requirement: &id004 !ruby/object:Gem::Requirement
81
66
  none: false
82
- requirements:
83
- - - ! '>='
84
- - !ruby/object:Gem::Version
85
- version: 0.2.2
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ hash: 3
71
+ segments:
72
+ - 0
73
+ version: "0"
86
74
  type: :runtime
75
+ version_requirements: *id004
76
+ - !ruby/object:Gem::Dependency
77
+ name: time_bandits
87
78
  prerelease: false
88
- version_requirements: !ruby/object:Gem::Requirement
79
+ requirement: &id005 !ruby/object:Gem::Requirement
89
80
  none: false
90
- requirements:
91
- - - ! '>='
92
- - !ruby/object:Gem::Version
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ hash: 19
85
+ segments:
86
+ - 0
87
+ - 2
88
+ - 2
93
89
  version: 0.2.2
90
+ type: :runtime
91
+ version_requirements: *id005
94
92
  description: Logjam logger and request information forwarding
95
- email:
93
+ email:
96
94
  - stefan.kaes@xing.com
97
95
  executables: []
96
+
98
97
  extensions: []
98
+
99
99
  extra_rdoc_files: []
100
- files:
100
+
101
+ files:
101
102
  - .gitignore
102
103
  - Gemfile
103
104
  - README.rdoc
@@ -115,28 +116,38 @@ files:
115
116
  - lib/logjam_agent/version.rb
116
117
  - logjam_agent.gemspec
117
118
  - rails/init.rb
118
- homepage: ''
119
+ homepage: ""
119
120
  licenses: []
121
+
120
122
  post_install_message:
121
123
  rdoc_options: []
122
- require_paths:
124
+
125
+ require_paths:
123
126
  - lib
124
- required_ruby_version: !ruby/object:Gem::Requirement
127
+ required_ruby_version: !ruby/object:Gem::Requirement
125
128
  none: false
126
- requirements:
127
- - - ! '>='
128
- - !ruby/object:Gem::Version
129
- version: '0'
130
- required_rubygems_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ hash: 3
133
+ segments:
134
+ - 0
135
+ version: "0"
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
137
  none: false
132
- requirements:
133
- - - ! '>='
134
- - !ruby/object:Gem::Version
135
- version: '0'
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ hash: 3
142
+ segments:
143
+ - 0
144
+ version: "0"
136
145
  requirements: []
146
+
137
147
  rubyforge_project: logjam_agent
138
148
  rubygems_version: 1.8.24
139
149
  signing_key:
140
150
  specification_version: 3
141
151
  summary: Logjam client library to be used with logjam
142
152
  test_files: []
153
+