pliny 0.25.1 → 0.26.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pliny/helpers/serialize.rb +9 -2
- data/lib/pliny/middleware/canonical_log_line.rb +4 -0
- data/lib/pliny/version.rb +1 -1
- data/lib/template/Gemfile +2 -2
- data/lib/template/lib/routes.rb +1 -0
- data/spec/helpers/serialize_spec.rb +12 -0
- metadata +17 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fc435bb8dd0c08d30696e53650d96a8ed0c38cb9
|
4
|
+
data.tar.gz: 01707d0efaf29bc8e2133887d936d58a10a4a388
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 593f3a3e15d3f1094a78ad0fad317e86500f596dd8d7577bfe406b4a3cc1b0a813efab88630dd4ebb30e6168a30d4cf202a06df77663b24c8114c960e8884218
|
7
|
+
data.tar.gz: 6300a8c749f94601fc7bec51baeffc83aa1687b51c458984c39484a0ab910a2fece3d61fc2518f6a08943efbe141b083047cca050bdde8d0080bf136b741c49d
|
@@ -5,14 +5,21 @@ module Pliny::Helpers
|
|
5
5
|
end
|
6
6
|
|
7
7
|
def serialize(data, structure = :default)
|
8
|
-
|
8
|
+
serializer_class = self.class.serializer_class
|
9
|
+
|
10
|
+
if serializer_class.nil?
|
9
11
|
raise <<-eos.strip
|
10
12
|
No serializer has been specified for this endpoint. Please specify one with
|
11
13
|
`serializer Serializers::ModelName` in the endpoint.
|
12
14
|
eos
|
13
15
|
end
|
14
16
|
|
15
|
-
|
17
|
+
env['pliny.serializer_arity'] = data.respond_to?(:size) ? data.size : 1
|
18
|
+
|
19
|
+
start = Time.now
|
20
|
+
serializer_class.new(structure).serialize(data).tap do
|
21
|
+
env['pliny.serializer_timing'] = (Time.now - start).to_f
|
22
|
+
end
|
16
23
|
end
|
17
24
|
|
18
25
|
module ClassMethods
|
@@ -48,12 +48,14 @@ module Pliny::Middleware
|
|
48
48
|
|
49
49
|
log_field :response_length, Integer
|
50
50
|
log_field :response_status, Integer
|
51
|
+
log_field :serializer_arity, Integer
|
51
52
|
|
52
53
|
#
|
53
54
|
# timing
|
54
55
|
#
|
55
56
|
|
56
57
|
log_field :timing_total_elapsed, Float
|
58
|
+
log_field :timing_serializer, Float
|
57
59
|
end
|
58
60
|
|
59
61
|
def initialize(app, emitter:)
|
@@ -103,12 +105,14 @@ module Pliny::Middleware
|
|
103
105
|
line.response_length = length.to_i
|
104
106
|
end
|
105
107
|
line.response_status = status
|
108
|
+
line.serializer_arity = env["pliny.serializer_arity"]
|
106
109
|
|
107
110
|
#
|
108
111
|
# timing
|
109
112
|
#
|
110
113
|
|
111
114
|
line.timing_total_elapsed = (Time.now - start).to_f
|
115
|
+
line.timing_serializer = env["pliny.serializer_timing"]
|
112
116
|
|
113
117
|
@emitter.call(line.to_h)
|
114
118
|
rescue => e
|
data/lib/pliny/version.rb
CHANGED
data/lib/template/Gemfile
CHANGED
@@ -4,7 +4,7 @@ ruby "2.4.0"
|
|
4
4
|
gem "multi_json"
|
5
5
|
gem "oj"
|
6
6
|
gem "pg"
|
7
|
-
gem "pliny", "~> 0.
|
7
|
+
gem "pliny", "~> 0.26"
|
8
8
|
gem "pry"
|
9
9
|
gem "puma", "~> 3"
|
10
10
|
gem "rack-ssl"
|
@@ -14,7 +14,7 @@ gem "rollbar"
|
|
14
14
|
gem "sequel", "~> 4.34"
|
15
15
|
gem "sequel-paranoid"
|
16
16
|
gem "sequel_pg", "~> 1.6", require: "sequel"
|
17
|
-
gem "sinatra", "
|
17
|
+
gem "sinatra", [">= 1.4", "< 3.0"], require: "sinatra/base"
|
18
18
|
gem "sinatra-contrib", require: ["sinatra/namespace", "sinatra/reloader"]
|
19
19
|
gem "sinatra-router"
|
20
20
|
gem "sucker_punch"
|
data/lib/template/lib/routes.rb
CHANGED
@@ -4,6 +4,7 @@ Routes = Rack::Builder.new do
|
|
4
4
|
use Pliny::Middleware::RequestID
|
5
5
|
use Pliny::Middleware::RequestStore::Seed, store: Pliny::RequestStore
|
6
6
|
use Pliny::Middleware::Metrics
|
7
|
+
use Pliny::Middleware::Instruments
|
7
8
|
use Pliny::Middleware::CanonicalLogLine,
|
8
9
|
emitter: -> (data) {
|
9
10
|
Pliny.log_with_default_context({ canonical_log_line: true }.merge(data))
|
@@ -36,6 +36,10 @@ describe Pliny::Helpers::Serialize do
|
|
36
36
|
get "/" do
|
37
37
|
MultiJson.encode(serialize([]))
|
38
38
|
end
|
39
|
+
|
40
|
+
get "/env" do
|
41
|
+
MultiJson.encode(serialize(env))
|
42
|
+
end
|
39
43
|
end
|
40
44
|
end
|
41
45
|
|
@@ -44,5 +48,13 @@ describe Pliny::Helpers::Serialize do
|
|
44
48
|
assert_equal 200, last_response.status
|
45
49
|
assert_equal MultiJson.encode([]), last_response.body
|
46
50
|
end
|
51
|
+
|
52
|
+
it "emits information for canonical log lines" do
|
53
|
+
get "/env"
|
54
|
+
assert_equal 200, last_response.status
|
55
|
+
body = MultiJson.decode(last_response.body)
|
56
|
+
assert body["pliny.serializer_arity"] > 1
|
57
|
+
assert body["pliny.serializer_timing"] > 0
|
58
|
+
end
|
47
59
|
end
|
48
60
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pliny
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.26.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandur Leach
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-
|
12
|
+
date: 2017-09-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -75,22 +75,22 @@ dependencies:
|
|
75
75
|
name: sinatra
|
76
76
|
requirement: !ruby/object:Gem::Requirement
|
77
77
|
requirements:
|
78
|
-
- - "
|
78
|
+
- - ">="
|
79
79
|
- !ruby/object:Gem::Version
|
80
80
|
version: '1.4'
|
81
|
-
- - "
|
81
|
+
- - "<"
|
82
82
|
- !ruby/object:Gem::Version
|
83
|
-
version:
|
83
|
+
version: '3.0'
|
84
84
|
type: :runtime
|
85
85
|
prerelease: false
|
86
86
|
version_requirements: !ruby/object:Gem::Requirement
|
87
87
|
requirements:
|
88
|
-
- - "
|
88
|
+
- - ">="
|
89
89
|
- !ruby/object:Gem::Version
|
90
90
|
version: '1.4'
|
91
|
-
- - "
|
91
|
+
- - "<"
|
92
92
|
- !ruby/object:Gem::Version
|
93
|
-
version:
|
93
|
+
version: '3.0'
|
94
94
|
- !ruby/object:Gem::Dependency
|
95
95
|
name: http_accept
|
96
96
|
requirement: !ruby/object:Gem::Requirement
|
@@ -120,7 +120,7 @@ dependencies:
|
|
120
120
|
version: '0.2'
|
121
121
|
- - ">="
|
122
122
|
- !ruby/object:Gem::Version
|
123
|
-
version: 0.2.
|
123
|
+
version: 0.2.4
|
124
124
|
type: :runtime
|
125
125
|
prerelease: false
|
126
126
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -130,7 +130,7 @@ dependencies:
|
|
130
130
|
version: '0.2'
|
131
131
|
- - ">="
|
132
132
|
- !ruby/object:Gem::Version
|
133
|
-
version: 0.2.
|
133
|
+
version: 0.2.4
|
134
134
|
- !ruby/object:Gem::Dependency
|
135
135
|
name: thor
|
136
136
|
requirement: !ruby/object:Gem::Requirement
|
@@ -215,22 +215,22 @@ dependencies:
|
|
215
215
|
name: sinatra-contrib
|
216
216
|
requirement: !ruby/object:Gem::Requirement
|
217
217
|
requirements:
|
218
|
-
- - "
|
218
|
+
- - ">="
|
219
219
|
- !ruby/object:Gem::Version
|
220
220
|
version: '1.4'
|
221
|
-
- - "
|
221
|
+
- - "<"
|
222
222
|
- !ruby/object:Gem::Version
|
223
|
-
version:
|
223
|
+
version: '3.0'
|
224
224
|
type: :development
|
225
225
|
prerelease: false
|
226
226
|
version_requirements: !ruby/object:Gem::Requirement
|
227
227
|
requirements:
|
228
|
-
- - "
|
228
|
+
- - ">="
|
229
229
|
- !ruby/object:Gem::Version
|
230
230
|
version: '1.4'
|
231
|
-
- - "
|
231
|
+
- - "<"
|
232
232
|
- !ruby/object:Gem::Version
|
233
|
-
version:
|
233
|
+
version: '3.0'
|
234
234
|
- !ruby/object:Gem::Dependency
|
235
235
|
name: timecop
|
236
236
|
requirement: !ruby/object:Gem::Requirement
|
@@ -528,7 +528,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
528
528
|
version: '0'
|
529
529
|
requirements: []
|
530
530
|
rubyforge_project:
|
531
|
-
rubygems_version: 2.
|
531
|
+
rubygems_version: 2.6.11
|
532
532
|
signing_key:
|
533
533
|
specification_version: 4
|
534
534
|
summary: Basic tooling to support API apps in Sinatra
|