logjam_agent 0.3.4 → 0.3.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/logjam_agent/middleware.rb +13 -5
- data/lib/logjam_agent/request.rb +13 -2
- data/lib/logjam_agent/version.rb +1 -1
- metadata +3 -3
@@ -6,18 +6,26 @@ module LogjamAgent
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def call(env)
|
9
|
-
start_request(env)
|
10
|
-
@app.call(env)
|
9
|
+
request = start_request(env)
|
10
|
+
result = @app.call(env)
|
11
|
+
result[1] ||= {}
|
12
|
+
result
|
13
|
+
rescue Exception
|
14
|
+
result = [500, {'Content-Type' => 'text/html'}, ["<html><body><h1>500 Internal Server Error</h1>"]]
|
11
15
|
ensure
|
16
|
+
headers = result[1]
|
17
|
+
headers["X-Logjam-Request-Id"] = request.id
|
18
|
+
headers["X-Logjam-Caller-Id"] = request.fields[:caller_id]
|
12
19
|
finish_request(env)
|
13
20
|
end
|
14
21
|
|
15
22
|
private
|
16
23
|
|
17
24
|
def start_request(env)
|
18
|
-
app_name
|
19
|
-
env_name
|
20
|
-
|
25
|
+
app_name = env["logjam_agent.application_name"] || LogjamAgent.application_name
|
26
|
+
env_name = env["logjam_agent.environment_name"] || LogjamAgent.environment_name
|
27
|
+
caller_id = env["HTTP_X_LOGJAM_CALLER_ID"] || ""
|
28
|
+
Rails.logger.start_request(app_name, env_name, :caller_id => caller_id)
|
21
29
|
end
|
22
30
|
|
23
31
|
def finish_request(env)
|
data/lib/logjam_agent/request.rb
CHANGED
@@ -2,13 +2,24 @@ require "json"
|
|
2
2
|
|
3
3
|
module LogjamAgent
|
4
4
|
class Request
|
5
|
-
attr_reader :fields
|
5
|
+
attr_reader :caller_id, :fields
|
6
6
|
|
7
7
|
def initialize(app, env, logger, initial_fields)
|
8
8
|
@logger = logger
|
9
|
+
@app = app
|
10
|
+
@env = env
|
9
11
|
@forwarder = Forwarders.get(app, env)
|
10
12
|
@lines = []
|
11
|
-
@
|
13
|
+
@id = UUID4R::uuid(1).gsub('-','')
|
14
|
+
@fields = initial_fields.merge(:request_id => @id, :host => LogjamAgent.hostname, :process_id => Process.pid, :lines => @lines)
|
15
|
+
end
|
16
|
+
|
17
|
+
def id
|
18
|
+
"#{@app}-#{@env}-#{@id}"
|
19
|
+
end
|
20
|
+
|
21
|
+
def caller_id
|
22
|
+
@fields[:caller_id]
|
12
23
|
end
|
13
24
|
|
14
25
|
def add_line(severity, timestamp, message)
|
data/lib/logjam_agent/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logjam_agent
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
9
|
+
- 5
|
10
|
+
version: 0.3.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Stefan Kaes
|