timber-rack 1.0.0 → 1.0.1

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: 842b8f0648df453c036c272d6a4c6acb14b5871f93d510e5c0ff13d695099558
4
- data.tar.gz: ac7015817b3f3cd58e2fbb2ae06439af33ad958c44beb9fa6bed381a68b44f9d
3
+ metadata.gz: e9b77ec2fe77256fca4523cff6c8920899d470ecc6f79416a8ae0d898a53218a
4
+ data.tar.gz: 7cbc3e59167ec9bc87802519d0ae78ff27e4d1a52eb783d80b4c88ee973d6296
5
5
  SHA512:
6
- metadata.gz: f90f921a1ef9f09dccdd32d3ab0d00439b35726de39713d1d69fad28be6dde80c9815d088111beae17d3cc1b0c71d1752fa80c4475036a18401fa0bf705f8a2f
7
- data.tar.gz: ef5185ce6ce4e908c2521effd3a3a4790ec949e11fcfa1eb03d8ce863e216fd770f8308e1e226862c8cb2515235ed0333c972832d246f0d3985935d72e7402b3
6
+ metadata.gz: 2ff4000fb69f6245488044fa6e021a9ee1b44ab3fbca1a6cd5d4875f977cbdeb75315500f2f44d035d02a70220ef43bfc10dd42cc140144eb1b7e46eb72e422c
7
+ data.tar.gz: 63867ce360ac7055cdc609c769a7140933b584107c03b6dffee36332fa753e02799f6a8d73a3f00dd927e60a9f4114cd44dd51ec0f18ad8e58b0a16caa499b1b
data/Gemfile CHANGED
@@ -1,7 +1,3 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- # TODO: REMOVE ME
4
- gem 'timber', git: 'https://github.com/timberio/timber-ruby.git', branch: '3.0'
5
-
6
- # Specify your gem's dependencies in timber-ruby-rack.gemspec
7
3
  gemspec
data/README.md CHANGED
@@ -3,7 +3,6 @@
3
3
  [![ISC License](https://img.shields.io/badge/license-ISC-ff69b4.svg)](LICENSE.md)
4
4
  [![Yard Docs](http://img.shields.io/badge/yard-docs-blue.svg)](http://www.rubydoc.info/github/timberio/timber-ruby-rack)
5
5
  [![Build Status](https://travis-ci.org/timberio/timber-ruby-rack.svg?branch=master)](https://travis-ci.org/timberio/timber-ruby-rack)
6
- [![Code Climate](https://codeclimate.com/github/timberio/timber-ruby-rack/badges/gpa.svg)](https://codeclimate.com/github/timberio/timber-ruby-rack)
7
6
 
8
7
  This library integrates the [`timber` Ruby library](https://github.com/timberio/timber-ruby) with the [Rack](https://github.com/rack/rack) framework,
9
8
  turning your Rack logs into rich structured events.
@@ -17,9 +17,9 @@ module Timber
17
17
  remote_addr: request.ip,
18
18
  request_id: request.request_id
19
19
  )
20
- CurrentContext.with(context) do
21
- @app.call(env)
22
- end
20
+
21
+ CurrentContext.add(context.to_hash)
22
+ @app.call(env)
23
23
  end
24
24
  end
25
25
  end
@@ -141,8 +141,7 @@ module Timber
141
141
  status, headers, body = @app.call(env)
142
142
 
143
143
  Config.instance.logger.info do
144
- http_context_key = Contexts::HTTP.keyspace
145
- http_context = CurrentContext.fetch(http_context_key)
144
+ http_context = CurrentContext.fetch(:http)
146
145
  content_length = headers[CONTENT_LENGTH_KEY]
147
146
  duration_ms = (Time.now - start) * 1000.0
148
147
 
@@ -1,5 +1,3 @@
1
- require "timber/util"
2
-
3
1
  module Timber
4
2
  module Integrations
5
3
  module Rack
@@ -9,37 +7,25 @@ module Timber
9
7
  # @note This event should be installed automatically through integrations,
10
8
  # such as the {Integrations::ActionController::LogSubscriber} integration.
11
9
  class HTTPRequest
12
- BODY_MAX_BYTES = 8192.freeze
13
- HEADERS_JSON_MAX_BYTES = 8192.freeze
14
- HEADERS_TO_SANITIZE = ['authorization', 'x-amz-security-token'].freeze
15
- HOST_MAX_BYTES = 256.freeze
16
- METHOD_MAX_BYTES = 20.freeze
17
- PATH_MAX_BYTES = 2048.freeze
18
- QUERY_STRING_MAX_BYTES = 2048.freeze
19
- REQUEST_ID_MAX_BYTES = 256.freeze
20
- SCHEME_MAX_BYTES = 20.freeze
21
- SERVICE_NAME_MAX_BYTES = 256.freeze
22
-
23
10
  attr_reader :body, :content_length, :headers, :headers_json, :host, :method, :path, :port,
24
11
  :query_string, :request_id, :scheme, :service_name
25
12
 
26
13
  def initialize(attributes)
27
- normalizer = Util::AttributeNormalizer.new(attributes)
28
- body_limit = attributes.delete(:body_limit) || BODY_MAX_BYTES
29
- headers_to_sanitize = HEADERS_TO_SANITIZE + (attributes.delete(:headers_to_sanitize) || [])
14
+ @body = attributes[:body]
15
+ @content_length = attributes[:content_length]
16
+ @headers = attributes[:headers]
17
+ @host = attributes[:host]
18
+ @method = attributes[:method]
19
+ @path = attributes[:path]
20
+ @port = attributes[:port]
21
+ @query_string = attributes[:query_string]
22
+ @scheme = attributes[:scheme]
23
+ @request_id = attributes[:request_id]
24
+ @service_name = attributes[:service_name]
30
25
 
31
- @body = normalizer.fetch(:body, :string, :limit => body_limit)
32
- @content_length = normalizer.fetch(:content_length, :integer)
33
- @headers= normalizer.fetch(:headers, :hash, :sanitize => headers_to_sanitize)
34
- @headers_json = @headers.to_json.byteslice(0, HEADERS_JSON_MAX_BYTES)
35
- @host = normalizer.fetch(:host, :string, :limit => HOST_MAX_BYTES)
36
- @method = normalizer.fetch!(:method, :string, :upcase => true, :limit => METHOD_MAX_BYTES)
37
- @path = normalizer.fetch(:path, :string, :limit => PATH_MAX_BYTES)
38
- @port = normalizer.fetch(:port, :integer)
39
- @query_string = normalizer.fetch(:query_string, :string, :limit => QUERY_STRING_MAX_BYTES)
40
- @scheme = normalizer.fetch(:scheme, :string, :limit => SCHEME_MAX_BYTES)
41
- @request_id = normalizer.fetch(:request_id, :string, :limit => REQUEST_ID_MAX_BYTES)
42
- @service_name = normalizer.fetch(:service_name, :string, :limit => SERVICE_NAME_MAX_BYTES)
26
+ if @headers
27
+ @headers_json = @headers.to_json
28
+ end
43
29
  end
44
30
 
45
31
  def message
@@ -1,5 +1,3 @@
1
- require "timber/util"
2
-
3
1
  module Timber
4
2
  module Integrations
5
3
  module Rack
@@ -7,29 +5,22 @@ module Timber
7
5
  # to clients.
8
6
 
9
7
  class HTTPResponse
10
- BODY_MAX_BYTES = 8192.freeze
11
- HEADERS_JSON_MAX_BYTES = 256.freeze
12
- HEADERS_TO_SANITIZE = ['authorization', 'x-amz-security-token'].freeze
13
- REQUEST_ID_MAX_BYTES = 256.freeze
14
- SERVICE_NAME_MAX_BYTES = 256.freeze
15
-
16
8
  attr_reader :body, :content_length, :headers, :headers_json, :http_context, :request_id, :service_name,
17
9
  :status, :duration_ms
18
10
 
19
11
  def initialize(attributes)
20
- normalizer = Util::AttributeNormalizer.new(attributes)
21
- body_limit = attributes.delete(:body_limit) || BODY_MAX_BYTES
22
- headers_to_sanitize = HEADERS_TO_SANITIZE + (attributes.delete(:headers_to_sanitize) || [])
23
-
24
- @body = normalizer.fetch(:body, :string, :limit => body_limit)
25
- @content_length = normalizer.fetch(:content_length, :integer)
26
- @headers = normalizer.fetch(:headers, :hash, :sanitize => headers_to_sanitize)
27
- @headers_json = @headers.to_json.byteslice(0, HEADERS_JSON_MAX_BYTES)
12
+ @body = attributes[:body]
13
+ @content_length = attributes[:content_length]
14
+ @headers = attributes[:headers]
28
15
  @http_context = attributes[:http_context]
29
- @request_id = normalizer.fetch(:request_id, :string, :limit => REQUEST_ID_MAX_BYTES)
30
- @service_name = normalizer.fetch(:service_name, :string, :limit => SERVICE_NAME_MAX_BYTES)
31
- @status = normalizer.fetch!(:status, :integer)
32
- @duration_ms = normalizer.fetch!(:duration_ms, :float, :precision => 6)
16
+ @request_id = attributes[:request_id]
17
+ @service_name = attributes[:service_name]
18
+ @status = attributes[:status]
19
+ @duration_ms = attributes[:duration_ms]
20
+
21
+ if @headers
22
+ @headers_json = @headers.to_json
23
+ end
33
24
  end
34
25
 
35
26
  # Returns the human readable log message for this event.
@@ -67,13 +67,10 @@ module Timber
67
67
  def call(env)
68
68
  user_hash = get_user_hash(env)
69
69
  if user_hash
70
- context = Contexts::User.new(user_hash)
71
- CurrentContext.with(context) do
72
- @app.call(env)
73
- end
74
- else
75
- @app.call(env)
70
+ CurrentContext.add({user: user_hash})
76
71
  end
72
+
73
+ @app.call(env)
77
74
  end
78
75
 
79
76
  private
@@ -1,7 +1,7 @@
1
1
  module Timber
2
2
  module Integrations
3
3
  module Rack
4
- VERSION = "1.0.0"
4
+ VERSION = "1.0.1"
5
5
  end
6
6
  end
7
7
  end
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["Timber Technologies, Inc."]
10
10
  spec.email = ["hi@timber.io"]
11
11
 
12
- spec.summary = %q{Timber for Ruby is a drop in replacement for your Ruby logger that unobtrusively augments your logs with rich metadata and context making them easier to search, use, and read.}
12
+ spec.summary = %q{Timber integration for Rack}
13
13
  spec.homepage = "https://docs.timber.io/languages/ruby/"
14
14
  spec.license = "ISC"
15
15
 
@@ -33,7 +33,7 @@ Gem::Specification.new do |spec|
33
33
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
34
34
  spec.require_paths = ["lib"]
35
35
 
36
- # spec.add_dependency "timber", "3.0.0.alpha.0"
36
+ spec.add_dependency "timber", "~> 3.0"
37
37
  spec.add_runtime_dependency "rack", ">= 1.2", "< 3.0"
38
38
 
39
39
  spec.add_development_dependency "bundler", ">= 0.0"
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: timber-rack
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Timber Technologies, Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-03-08 00:00:00.000000000 Z
11
+ date: 2019-03-27 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: timber
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: rack
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -123,10 +137,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
123
137
  - !ruby/object:Gem::Version
124
138
  version: '0'
125
139
  requirements: []
126
- rubygems_version: 3.0.3
140
+ rubygems_version: 3.0.1
127
141
  signing_key:
128
142
  specification_version: 4
129
- summary: Timber for Ruby is a drop in replacement for your Ruby logger that unobtrusively
130
- augments your logs with rich metadata and context making them easier to search,
131
- use, and read.
143
+ summary: Timber integration for Rack
132
144
  test_files: []