logtail-rack 0.1.1 → 0.1.5

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: 0a300b8b1a0f76372588d891e8276f146dd26ba6dca23a1c84dc56f91d60a80d
4
- data.tar.gz: 659ccf160bb42b6ab59a09346e87278cdfb3fca73a74e1271934fed3011c1a60
3
+ metadata.gz: 16509c0d376658470e6f30a21f35dc6bba83213dbf000d38557280f3535c2d62
4
+ data.tar.gz: a666f568f5d25ae865ccfffb411813723eb7f0097393dc71abec06822b6e8e8a
5
5
  SHA512:
6
- metadata.gz: a394a028579fa0f400690ce6fc3b79d307f023db9d8a056e0d1febf0f02a320d413368bd02a2c998087b132003ffec15d1f9efe0e9dbea40a29a0474753dd492
7
- data.tar.gz: cf5a7093d2934706e1333fcff32c6996675a8b73a44ba042a533a662e9f5764b1a2e966a3f88c24f24d9afaf9990f546447b52d9928159e3a15e6cf269f17aab
6
+ metadata.gz: 200ed7c0ebac2fb76803ac8811c0d4f72dbd9c1ff02e59706d52955018b3509829fee9168da4667b244baa7f3f1aad8bf2168f4c5ce8f8c2cc94120826b7d982
7
+ data.tar.gz: 952d5d52989861145c2b0f621f7046d7936c265c74872094d202dc28b4d2b542f090e7e7c29c4bf6ad70d212fea11d00fa2636bf22b392a3769faaeab29ef4ba
@@ -11,10 +11,10 @@ module Logtail
11
11
  def call(env)
12
12
  request = Util::Request.new(env)
13
13
  context = Contexts::HTTP.new(
14
- host: request.host,
15
- method: request.request_method,
14
+ host: request.host.force_encoding('UTF-8'),
15
+ method: request.request_method.force_encoding('UTF-8'),
16
16
  path: request.path,
17
- remote_addr: request.ip,
17
+ remote_addr: request.ip.force_encoding('UTF-8'),
18
18
  request_id: request.request_id
19
19
  )
20
20
 
@@ -142,7 +142,7 @@ module Logtail
142
142
 
143
143
  Config.instance.logger.info do
144
144
  http_context = CurrentContext.fetch(:http)
145
- content_length = headers[CONTENT_LENGTH_KEY]
145
+ content_length = safe_to_i(headers[CONTENT_LENGTH_KEY])
146
146
  duration_ms = (Time.now - start) * 1000.0
147
147
 
148
148
  http_response = HTTPResponse.new(
@@ -180,15 +180,15 @@ module Logtail
180
180
  event_body = capture_request_body? ? request.body_content : nil
181
181
  http_request = HTTPRequest.new(
182
182
  body: event_body,
183
- content_length: request.content_length,
183
+ content_length: safe_to_i(request.content_length),
184
184
  headers: request.headers,
185
- host: request.host,
185
+ host: force_encoding(request.host),
186
186
  method: request.request_method,
187
187
  path: request.path,
188
188
  port: request.port,
189
- query_string: request.query_string,
189
+ query_string: force_encoding(request.query_string),
190
190
  request_id: request.request_id,
191
- scheme: request.scheme,
191
+ scheme: force_encoding(request.scheme),
192
192
  body_limit: self.class.http_body_limit,
193
193
  headers_to_sanitize: self.class.http_header_filters,
194
194
  )
@@ -217,7 +217,7 @@ module Logtail
217
217
 
218
218
  Config.instance.logger.info do
219
219
  event_body = capture_response_body? ? body : nil
220
- content_length = headers[CONTENT_LENGTH_KEY]
220
+ content_length = safe_to_i(headers[CONTENT_LENGTH_KEY])
221
221
  duration_ms = (Time.now - start) * 1000.0
222
222
 
223
223
  http_response = HTTPResponse.new(
@@ -271,6 +271,18 @@ module Logtail
271
271
  false
272
272
  end
273
273
  end
274
+
275
+ def safe_to_i(val)
276
+ val.nil? ? nil : val.to_i
277
+ end
278
+
279
+ def force_encoding(value)
280
+ if value.respond_to?(:force_encoding)
281
+ value.dup.force_encoding('UTF-8')
282
+ else
283
+ value
284
+ end
285
+ end
274
286
  end
275
287
  end
276
288
  end
@@ -1,3 +1,5 @@
1
+ require "logtail-rack/util/encoding"
2
+
1
3
  module Logtail
2
4
  module Integrations
3
5
  module Rack
@@ -24,7 +26,7 @@ module Logtail
24
26
  @service_name = attributes[:service_name]
25
27
 
26
28
  if @headers
27
- @headers_json = @headers.to_json
29
+ @headers_json = Util::Encoding.force_utf8_encoding(@headers).to_json
28
30
  end
29
31
  end
30
32
 
@@ -1,3 +1,5 @@
1
+ require "logtail-rack/util/encoding"
2
+
1
3
  module Logtail
2
4
  module Integrations
3
5
  module Rack
@@ -19,7 +21,7 @@ module Logtail
19
21
  @duration_ms = attributes[:duration_ms]
20
22
 
21
23
  if @headers
22
- @headers_json = @headers.to_json
24
+ @headers_json = Util::Encoding.force_utf8_encoding(@headers).to_json
23
25
  end
24
26
  end
25
27
 
@@ -0,0 +1,15 @@
1
+ module Logtail
2
+ module Util
3
+ class Encoding
4
+ def self.force_utf8_encoding(data)
5
+ if data.respond_to?(:force_encoding)
6
+ data.dup.force_encoding('UTF-8')
7
+ elsif data.respond_to?(:transform_values)
8
+ data.transform_values { |val| Logtail::Util::Encoding.force_utf8_encoding(val) }
9
+ else
10
+ data
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -1,7 +1,7 @@
1
1
  module Logtail
2
2
  module Integrations
3
3
  module Rack
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.5"
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logtail-rack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Logtail
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-03-26 00:00:00.000000000 Z
11
+ date: 2021-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logtail
@@ -110,6 +110,7 @@ files:
110
110
  - lib/logtail-rack/middleware.rb
111
111
  - lib/logtail-rack/session_context.rb
112
112
  - lib/logtail-rack/user_context.rb
113
+ - lib/logtail-rack/util/encoding.rb
113
114
  - lib/logtail-rack/util/request.rb
114
115
  - lib/logtail-rack/version.rb
115
116
  - logtail-ruby-rack.gemspec