Skip to content

Commit 585d0cc

Browse files
authored
Merge pull request #4 from logtail/th/more-precise-request-durations
More precise request durations (v0.1.6)
2 parents 5dab69a + 8d46584 commit 585d0cc

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

lib/logtail-rack/http_events.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,14 @@ def call(env)
136136
end
137137

138138
elsif collapse_into_single_event?
139-
start = Time.now
140-
139+
request_start = Time.now
141140
status, headers, body = @app.call(env)
141+
request_end = Time.now
142142

143143
Config.instance.logger.info do
144144
http_context = CurrentContext.fetch(:http)
145145
content_length = safe_to_i(headers[CONTENT_LENGTH_KEY])
146-
duration_ms = (Time.now - start) * 1000.0
146+
duration_ms = (request_end - request_start) * 1000.0
147147

148148
http_response = HTTPResponse.new(
149149
content_length: content_length,
@@ -174,8 +174,6 @@ def call(env)
174174

175175
[status, headers, body]
176176
else
177-
start = Time.now
178-
179177
Config.instance.logger.info do
180178
event_body = capture_request_body? ? request.body_content : nil
181179
http_request = HTTPRequest.new(
@@ -213,12 +211,14 @@ def call(env)
213211
}
214212
end
215213

214+
request_start = Time.now
216215
status, headers, body = @app.call(env)
216+
request_end = Time.now
217217

218218
Config.instance.logger.info do
219219
event_body = capture_response_body? ? body : nil
220220
content_length = safe_to_i(headers[CONTENT_LENGTH_KEY])
221-
duration_ms = (Time.now - start) * 1000.0
221+
duration_ms = (request_end - request_start) * 1000.0
222222

223223
http_response = HTTPResponse.new(
224224
body: event_body,

lib/logtail-rack/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module Logtail
22
module Integrations
33
module Rack
4-
VERSION = "0.1.5"
4+
VERSION = "0.1.6"
55
end
66
end
77
end

0 commit comments

Comments
 (0)