vigiles 0.1.0.pre.beta9 → 0.1.0.pre.beta10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cceedc075f3779ec0c77cc04a35058734cd2d2396ea67b95c6b1117763caa719
|
4
|
+
data.tar.gz: 3ea39ba08de23e8b51b66bc0e4b4cc38ca52e467ccdf671d49cdb52e7ff98453
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a884ac729b71b8351aae48ce0515d2a803f6358f03d03cc3efbbdb5304c2d811de6401eea203329fbea433c9d3896d77fc2f25bb0947226a689c1e466f64b8fd
|
7
|
+
data.tar.gz: 8a2b120ce179764649389ce270a45015e8e67379f70cb40035cef4f58cf321c6e81a376b62482842825599d7c101fec4ee69aa60aa9889146f6ed2f1daa15297
|
@@ -48,7 +48,7 @@ module Vigiles
|
|
48
48
|
preferred_headers = Vigiles.spec.request_headers
|
49
49
|
available_headers = request.original_headers
|
50
50
|
recorded_headers = (available_headers if preferred_headers.empty?)
|
51
|
-
recorded_headers ||= preferred_headers.to_h {
|
51
|
+
recorded_headers ||= preferred_headers.to_h { [_1, available_headers[_1]] }
|
52
52
|
unfucked_headers = recorded_headers.transform_keys { best_effort_unfuck_http_header _1 }
|
53
53
|
|
54
54
|
Request.new(
|
@@ -2,15 +2,25 @@
|
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
require "logger"
|
5
|
+
|
5
6
|
module Vigiles
|
6
7
|
module Middleware
|
7
8
|
class RecordConversation
|
8
|
-
sig {
|
9
|
-
|
10
|
-
|
9
|
+
sig { returns(Vigiles::Options) }
|
10
|
+
attr_reader :options
|
11
|
+
|
12
|
+
delegate \
|
13
|
+
:capture_exception,
|
14
|
+
:logger,
|
15
|
+
to: :options
|
16
|
+
|
17
|
+
sig { params(app: T.untyped, options: Vigiles::Options).void }
|
18
|
+
def initialize(app, options=Vigiles::Options.make_default_options)
|
19
|
+
@app = app
|
20
|
+
@options = options
|
11
21
|
end
|
12
22
|
|
13
|
-
sig { params(env: T.untyped).returns(T.untyped) }
|
23
|
+
sig { params(env: T::Hash[T.untyped, T.untyped]).returns(T.untyped) }
|
14
24
|
def call(env)
|
15
25
|
req = ActionDispatch::Request.new(env)
|
16
26
|
record_conversation(req) do
|
@@ -20,11 +30,29 @@ module Vigiles
|
|
20
30
|
|
21
31
|
sig { params(req: ActionDispatch::Request, blk: T.proc.returns(T.untyped)).returns(T.untyped) }
|
22
32
|
private def record_conversation(req, &blk)
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
33
|
+
rack_response = blk.call
|
34
|
+
begin
|
35
|
+
res = Rack::Response[*rack_response]
|
36
|
+
convo = Vigiles.maybe_record_conversation(req:, res:)
|
37
|
+
logger.info \
|
38
|
+
"[vigiles] conversation recorder: " \
|
39
|
+
"conversation=#{convo.nil? ? "not_recorded" : convo.id} " \
|
40
|
+
"request=#{req.request_id}"
|
41
|
+
rescue => e
|
42
|
+
capture_exception.call(e)
|
43
|
+
logger.warn \
|
44
|
+
"[vigiles] conversation recorder error: " \
|
45
|
+
"error_message=#{e.message} " \
|
46
|
+
"error_class=#{e.class}"
|
47
|
+
ensure
|
48
|
+
# no matter what happens we shouldn't prevent the rack
|
49
|
+
# response from being returned. at this point, the only
|
50
|
+
# thing that could throw execution into this branch is
|
51
|
+
# an exception when the `capture_exception` proc is
|
52
|
+
# invoked.
|
53
|
+
rack_response
|
54
|
+
end
|
55
|
+
rack_response
|
28
56
|
end
|
29
57
|
end
|
30
58
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# typed: strict
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "logger"
|
5
|
+
|
6
|
+
module Vigiles
|
7
|
+
class Options < T::Struct
|
8
|
+
const :capture_exception, T.proc.params(a0: StandardError).void
|
9
|
+
const :logger, ::Logger
|
10
|
+
|
11
|
+
sig { returns(Options) }
|
12
|
+
def self.make_default_options
|
13
|
+
Options.new(
|
14
|
+
logger: T.unsafe(Rails).logger, # you should be using this within rails.
|
15
|
+
capture_exception: ->(e) { e } # a no-op exception capturer.
|
16
|
+
)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/vigiles/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vigiles
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.0.pre.
|
4
|
+
version: 0.1.0.pre.beta10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yaw Boakye
|
@@ -225,6 +225,7 @@ files:
|
|
225
225
|
- lib/vigiles/conversation_recorders/application_json.rb
|
226
226
|
- lib/vigiles/conversation_recorders/unknown.rb
|
227
227
|
- lib/vigiles/middleware/record_conversation.rb
|
228
|
+
- lib/vigiles/options.rb
|
228
229
|
- lib/vigiles/spec.rb
|
229
230
|
- lib/vigiles/types.rb
|
230
231
|
- lib/vigiles/utilities/uri.rb
|