jcw 0.2.2 → 0.3.0

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: 110c81162cbfa9b0c7320539340e3adc8f2ecb0dc76f3ebc398ab3ef9330db31
4
- data.tar.gz: 637bfb300fc81f4e07dce12983da6e4a342dbaa2445695241c7f3bd6fdd76f69
3
+ metadata.gz: c1f8f9b595186e86f086290543b8b4ea880a174dab1e1a94d11f8afd151479b8
4
+ data.tar.gz: 209f2ff14d28cd1a7ca7d586c17c53e8505ce170f23d81f5b5de42a4f6544f29
5
5
  SHA512:
6
- metadata.gz: 1cd01757ae92d40d4e0bd2ba687fc62d612a3ce7a6b3178d1a4038c56e7c2877ff219a8415fe0f4c099b0930b341eaff81efe2345ce6361384c46dfaa16829ab
7
- data.tar.gz: 696a1156f40a49295c53f638b2626e6269c445f30f73ad809bc725dc765673417de5c9869c39fe3cbbc58146a951ef14f4d11e7a00b6a36193358e3b73ec1c3c
6
+ metadata.gz: ad26e8445a04470d780aa4a4aed1f4aa50653b1db80b55cd24238fc95dde6c17d1e94e33924706c766885e957633f55ed47e50365f17cecff79b5ab3766299c9
7
+ data.tar.gz: d4b076df8cdcfdf35a0a31998ad7d248ce77c7dca6f6c3b6291e4d4b90b424b66c89678ac16188b1a3f5cca62a48428eec555bd6954f35c95ad228de68dcb980
@@ -41,7 +41,7 @@ jobs:
41
41
  strategy:
42
42
  fail-fast: false
43
43
  matrix:
44
- ruby: [2.6, 2.7, 2.7.4, 3.0.0, 3.0.1, 3.0.2]
44
+ ruby: [2.6, 2.7, 2.7.4, 3.0.0, 3.0.1, 3.0.2, 3.1.0]
45
45
  experimental: [false]
46
46
 
47
47
  steps:
data/.rubocop.yml CHANGED
@@ -11,6 +11,9 @@ RSpec/EmptyLineAfterHook:
11
11
  Naming/RescuedExceptionsVariableName:
12
12
  Enabled: false
13
13
 
14
+ Style/CaseEquality:
15
+ Enabled: false
16
+
14
17
  Style/HashConversion:
15
18
  Exclude:
16
19
  - spec/**/*_spec.rb
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- jcw (0.2.2)
4
+ jcw (0.3.0)
5
5
  activesupport (>= 5.0, < 7.0.0)
6
6
  gruf (~> 2.10)
7
7
  httprb-opentracing (~> 0.4.0)
@@ -10,20 +10,20 @@ PATH
10
10
  GEM
11
11
  remote: https://rubygems.org/
12
12
  specs:
13
- actionpack (6.1.4.4)
14
- actionview (= 6.1.4.4)
15
- activesupport (= 6.1.4.4)
13
+ actionpack (6.1.6.1)
14
+ actionview (= 6.1.6.1)
15
+ activesupport (= 6.1.6.1)
16
16
  rack (~> 2.0, >= 2.0.9)
17
17
  rack-test (>= 0.6.3)
18
18
  rails-dom-testing (~> 2.0)
19
19
  rails-html-sanitizer (~> 1.0, >= 1.2.0)
20
- actionview (6.1.4.4)
21
- activesupport (= 6.1.4.4)
20
+ actionview (6.1.6.1)
21
+ activesupport (= 6.1.6.1)
22
22
  builder (~> 3.1)
23
23
  erubi (~> 1.4)
24
24
  rails-dom-testing (~> 2.0)
25
25
  rails-html-sanitizer (~> 1.1, >= 1.2.0)
26
- activesupport (6.1.4.4)
26
+ activesupport (6.1.6.1)
27
27
  concurrent-ruby (~> 1.0, >= 1.0.2)
28
28
  i18n (>= 1.6, < 2)
29
29
  minitest (>= 5.1)
@@ -37,7 +37,7 @@ GEM
37
37
  bundler (>= 1.2.0, < 3)
38
38
  thor (~> 1.0)
39
39
  coderay (1.1.3)
40
- concurrent-ruby (1.1.9)
40
+ concurrent-ruby (1.1.10)
41
41
  crass (1.0.6)
42
42
  diff-lcs (1.4.4)
43
43
  docile (1.4.0)
@@ -49,22 +49,31 @@ GEM
49
49
  ffi-compiler (1.0.1)
50
50
  ffi (>= 1.0.0)
51
51
  rake
52
- google-protobuf (3.19.1)
53
- googleapis-common-protos-types (1.3.0)
52
+ google-protobuf (3.21.3)
53
+ google-protobuf (3.21.3-x86_64-darwin)
54
+ google-protobuf (3.21.3-x86_64-linux)
55
+ googleapis-common-protos-types (1.3.2)
54
56
  google-protobuf (~> 3.14)
55
- grpc (1.42.0)
56
- google-protobuf (~> 3.18)
57
+ grpc (1.48.0)
58
+ google-protobuf (~> 3.19)
57
59
  googleapis-common-protos-types (~> 1.0)
58
- grpc-tools (1.42.0)
59
- gruf (2.10.0)
60
+ grpc (1.48.0-x86_64-darwin)
61
+ google-protobuf (~> 3.19)
62
+ googleapis-common-protos-types (~> 1.0)
63
+ grpc (1.48.0-x86_64-linux)
64
+ google-protobuf (~> 3.19)
65
+ googleapis-common-protos-types (~> 1.0)
66
+ grpc-tools (1.48.0)
67
+ gruf (2.15.1)
60
68
  activesupport (> 4)
61
69
  concurrent-ruby (> 1)
62
- e2mmap (~> 0.1)
70
+ e2mmap (>= 0.1)
63
71
  grpc (~> 1.10)
64
72
  grpc-tools (~> 1.10)
65
73
  json (>= 2.3)
66
- slop (~> 4.6)
67
- thwait (~> 0.1)
74
+ slop (>= 4.6)
75
+ thwait (>= 0.1)
76
+ zeitwerk (>= 2)
68
77
  http (5.0.4)
69
78
  addressable (~> 2.8)
70
79
  http-cookie (~> 1.0)
@@ -77,56 +86,56 @@ GEM
77
86
  ffi-compiler (>= 1.0, < 2.0)
78
87
  httprb-opentracing (0.4.0)
79
88
  opentracing (~> 0.5.0)
80
- i18n (1.8.11)
89
+ i18n (1.12.0)
81
90
  concurrent-ruby (~> 1.0)
82
91
  jaeger-client (1.1.0)
83
92
  opentracing (~> 0.3)
84
93
  thrift
85
- json (2.6.1)
94
+ json (2.6.2)
86
95
  llhttp-ffi (0.4.0)
87
96
  ffi-compiler (~> 1.0)
88
97
  rake (~> 13.0)
89
- loofah (2.13.0)
98
+ loofah (2.18.0)
90
99
  crass (~> 1.0.2)
91
100
  nokogiri (>= 1.5.9)
92
101
  method_source (1.0.0)
93
- mini_portile2 (2.6.1)
94
- minitest (5.15.0)
95
- nokogiri (1.12.5)
96
- mini_portile2 (~> 2.6.1)
102
+ mini_portile2 (2.8.0)
103
+ minitest (5.16.2)
104
+ nokogiri (1.13.8)
105
+ mini_portile2 (~> 2.8.0)
97
106
  racc (~> 1.4)
98
- nokogiri (1.12.5-x86_64-darwin)
107
+ nokogiri (1.13.8-x86_64-darwin)
99
108
  racc (~> 1.4)
100
- nokogiri (1.12.5-x86_64-linux)
109
+ nokogiri (1.13.8-x86_64-linux)
101
110
  racc (~> 1.4)
102
111
  opentracing (0.5.0)
103
112
  opentracing_test_tracer (0.1.1)
104
113
  opentracing
105
- parallel (1.21.0)
106
- parser (3.0.3.2)
114
+ parallel (1.22.1)
115
+ parser (3.1.2.0)
107
116
  ast (~> 2.4.1)
108
117
  pry (0.14.1)
109
118
  coderay (~> 1.1)
110
119
  method_source (~> 1.0)
111
120
  public_suffix (4.0.6)
112
121
  racc (1.6.0)
113
- rack (2.2.3)
114
- rack-test (1.1.0)
115
- rack (>= 1.0, < 3)
122
+ rack (2.2.4)
123
+ rack-test (2.0.2)
124
+ rack (>= 1.3)
116
125
  rails-dom-testing (2.0.3)
117
126
  activesupport (>= 4.2.0)
118
127
  nokogiri (>= 1.6)
119
- rails-html-sanitizer (1.4.2)
128
+ rails-html-sanitizer (1.4.3)
120
129
  loofah (~> 2.3)
121
- railties (6.1.4.4)
122
- actionpack (= 6.1.4.4)
123
- activesupport (= 6.1.4.4)
130
+ railties (6.1.6.1)
131
+ actionpack (= 6.1.6.1)
132
+ activesupport (= 6.1.6.1)
124
133
  method_source
125
- rake (>= 0.13)
134
+ rake (>= 12.2)
126
135
  thor (~> 1.0)
127
- rainbow (3.0.0)
136
+ rainbow (3.1.1)
128
137
  rake (13.0.6)
129
- regexp_parser (2.2.0)
138
+ regexp_parser (2.5.0)
130
139
  rexml (3.2.5)
131
140
  rspec (3.10.0)
132
141
  rspec-core (~> 3.10.0)
@@ -141,37 +150,36 @@ GEM
141
150
  diff-lcs (>= 1.2.0, < 2.0)
142
151
  rspec-support (~> 3.10.0)
143
152
  rspec-support (3.10.3)
144
- rubocop (1.17.0)
153
+ rubocop (1.30.1)
145
154
  parallel (~> 1.10)
146
- parser (>= 3.0.0.0)
155
+ parser (>= 3.1.0.0)
147
156
  rainbow (>= 2.2.2, < 4.0)
148
157
  regexp_parser (>= 1.8, < 3.0)
149
- rexml
150
- rubocop-ast (>= 1.7.0, < 2.0)
158
+ rexml (>= 3.2.5, < 4.0)
159
+ rubocop-ast (>= 1.18.0, < 2.0)
151
160
  ruby-progressbar (~> 1.7)
152
161
  unicode-display_width (>= 1.4.0, < 3.0)
153
- rubocop-ast (1.15.0)
154
- parser (>= 3.0.1.1)
155
- rubocop-config-umbrellio (1.17.0.53)
156
- rubocop (= 1.17.0)
157
- rubocop-performance (= 1.10.0)
158
- rubocop-rails (= 2.9.1)
159
- rubocop-rake (= 0.5.1)
160
- rubocop-rspec (= 2.2.0)
161
- rubocop-sequel (= 0.2.0)
162
- rubocop-performance (1.10.0)
163
- rubocop (>= 0.90.0, < 2.0)
162
+ rubocop-ast (1.19.1)
163
+ parser (>= 3.1.1.0)
164
+ rubocop-config-umbrellio (1.30.0.65)
165
+ rubocop (~> 1.30.0)
166
+ rubocop-performance (~> 1.14.0)
167
+ rubocop-rails (~> 2.14.2)
168
+ rubocop-rake (~> 0.6.0)
169
+ rubocop-rspec (~> 2.11.1)
170
+ rubocop-sequel (~> 0.3.3)
171
+ rubocop-performance (1.14.3)
172
+ rubocop (>= 1.7.0, < 2.0)
164
173
  rubocop-ast (>= 0.4.0)
165
- rubocop-rails (2.9.1)
174
+ rubocop-rails (2.14.2)
166
175
  activesupport (>= 4.2.0)
167
176
  rack (>= 1.1)
168
- rubocop (>= 0.90.0, < 2.0)
169
- rubocop-rake (0.5.1)
170
- rubocop
171
- rubocop-rspec (2.2.0)
177
+ rubocop (>= 1.7.0, < 2.0)
178
+ rubocop-rake (0.6.0)
172
179
  rubocop (~> 1.0)
173
- rubocop-ast (>= 1.1.0)
174
- rubocop-sequel (0.2.0)
180
+ rubocop-rspec (2.11.1)
181
+ rubocop (~> 1.19)
182
+ rubocop-sequel (0.3.4)
175
183
  rubocop (~> 1.0)
176
184
  ruby-progressbar (1.11.0)
177
185
  simplecov (0.21.2)
@@ -181,18 +189,18 @@ GEM
181
189
  simplecov-html (0.12.3)
182
190
  simplecov-lcov (0.8.0)
183
191
  simplecov_json_formatter (0.1.3)
184
- slop (4.9.1)
185
- thor (1.1.0)
186
- thrift (0.15.0)
192
+ slop (4.9.2)
193
+ thor (1.2.1)
194
+ thrift (0.16.0)
187
195
  thwait (0.2.0)
188
196
  e2mmap
189
- tzinfo (2.0.4)
197
+ tzinfo (2.0.5)
190
198
  concurrent-ruby (~> 1.0)
191
199
  unf (0.1.4)
192
200
  unf_ext
193
201
  unf_ext (0.0.8)
194
- unicode-display_width (2.1.0)
195
- zeitwerk (2.5.1)
202
+ unicode-display_width (2.2.0)
203
+ zeitwerk (2.6.0)
196
204
 
197
205
  PLATFORMS
198
206
  ruby
@@ -215,4 +223,4 @@ DEPENDENCIES
215
223
  simplecov-lcov
216
224
 
217
225
  BUNDLED WITH
218
- 2.2.15
226
+ 2.2.31
data/README.md CHANGED
@@ -42,7 +42,7 @@ UDP Sender(default):
42
42
  hostname: "custom-hostname",
43
43
  custom_tag: "custom-tag-value",
44
44
  }
45
- config.rack_ignore_paths = %w[/api/test]
45
+ config.rack_ignore_path_patterns = ["/api/test", %r{/sidekiq}]
46
46
  end
47
47
 
48
48
  # Set middleware for wrapping all requests
@@ -60,7 +60,7 @@ TCP Sender:
60
60
  hostname: "custom-hostname",
61
61
  custom_tag: "custom-tag-value",
62
62
  }
63
- config.rack_ignore_paths = %w[/api/test]
63
+ config.rack_ignore_path_patterns = ["/api/test", %r{/sidekiq}]
64
64
  end
65
65
 
66
66
  # Set middleware for wrapping all requests
data/lib/jcw/config.rb CHANGED
@@ -9,7 +9,7 @@ module JCW
9
9
  :flush_interval,
10
10
  :tags,
11
11
  :grpc_ignore_methods,
12
- :rack_ignore_paths
12
+ :rack_ignore_path_patterns
13
13
 
14
14
  def enabled
15
15
  @enabled ||= false
@@ -41,8 +41,8 @@ module JCW
41
41
  @grpc_ignore_methods ||= []
42
42
  end
43
43
 
44
- def rack_ignore_paths
45
- @rack_ignore_paths ||= []
44
+ def rack_ignore_path_patterns
45
+ @rack_ignore_path_patterns ||= []
46
46
  end
47
47
  end
48
48
  end
@@ -15,7 +15,7 @@ module JCW
15
15
  # is called.
16
16
  # @param on_start_span [Proc, nil] A callback evaluated after a new span is created.
17
17
  # @param on_finish_span [Proc, nil] A callback evaluated after a span is finished.
18
- # @param ignore_paths [Array<Class>] An array of paths to be skiped by the tracer.
18
+ # @param ignore_path_patterns [Array<Class>] An array of paths to be skiped by the tracer.
19
19
  # @param errors [Array<Class>] An array of error classes to be captured by the tracer
20
20
  # as errors. Errors are **not** muted by the middleware, they're re-raised afterwards.
21
21
  def initialize(app, # rubocop:disable Metrics/ParameterLists
@@ -23,7 +23,7 @@ module JCW
23
23
  on_start_span: nil,
24
24
  on_finish_span: nil,
25
25
  trust_incoming_span: true,
26
- ignore_paths: Wrapper.config.rack_ignore_paths,
26
+ ignore_path_patterns: Wrapper.config.rack_ignore_path_patterns,
27
27
  errors: [StandardError])
28
28
  @app = app
29
29
  @tracer = tracer
@@ -31,7 +31,7 @@ module JCW
31
31
  @on_finish_span = on_finish_span
32
32
  @trust_incoming_span = trust_incoming_span
33
33
  @errors = errors
34
- @ignore_paths = ignore_paths
34
+ @ignore_path_patterns = ignore_path_patterns
35
35
  end
36
36
 
37
37
  def call(env)
@@ -39,44 +39,31 @@ module JCW
39
39
  path = env[REQUEST_PATH]
40
40
  url = env[REQUEST_URI]
41
41
 
42
- return @app.call(env) if @ignore_paths.include?(path)
42
+ return @app.call(env) if @ignore_path_patterns.find { |pattern| pattern === path }
43
43
 
44
- handle_error(@errors) do
45
- env["uber-trace-id"] = env["HTTP_UBER_TRACE_ID"]
46
- context = @tracer.extract(OpenTracing::FORMAT_TEXT_MAP, env) if @trust_incoming_span
47
- @scope = build_scope(method, url, context)
48
- @span = @scope.span
49
-
50
- perform_on_start_span(env, @span, @on_start_span)
51
-
52
- @app.call(env).tap do |status_code, _headers, _body|
53
- set_tag(@span, status_code, env)
54
- end
55
- end
56
- end
57
-
58
- private
59
-
60
- def handle_error(errors)
61
- yield
62
- rescue *errors => e
63
- @span.set_tag("error", true)
64
- @span.log_kv(
65
- event: "error",
66
- "error.kind": e.class.to_s,
67
- "error.object": e,
68
- message: e.message,
69
- stack: e.backtrace.join("\n"),
70
- )
44
+ set_extract_env(env)
45
+ context = @tracer.extract(OpenTracing::FORMAT_TEXT_MAP, env) if @trust_incoming_span
46
+ scope = build_scope(method, url, context)
47
+ span = scope.span
48
+ perform_on_start_span(env, span, @on_start_span)
49
+ call_request(env, span)
50
+ rescue *@errors => error
51
+ build_error_log(span, error)
71
52
  raise
72
53
  ensure
73
54
  begin
74
- @scope.close
55
+ close_scope(scope)
75
56
  ensure
76
- perform_on_finish_span
57
+ perform_on_finish_span(span)
77
58
  end
78
59
  end
79
60
 
61
+ private
62
+
63
+ def set_extract_env(env)
64
+ env["uber-trace-id"] = env["HTTP_UBER_TRACE_ID"]
65
+ end
66
+
80
67
  def build_scope(method, url, context)
81
68
  @tracer.start_active_span(
82
69
  method,
@@ -95,10 +82,16 @@ module JCW
95
82
  env["rack.span"] = span
96
83
  end
97
84
 
85
+ def call_request(env, span)
86
+ @app.call(env).tap do |status_code, _headers, _body|
87
+ set_tag(span, status_code, env)
88
+ end
89
+ end
90
+
98
91
  def set_tag(span, status_code, env)
99
92
  span.set_tag("http.status_code", status_code)
100
93
  route = route_from_env(env)
101
- span.operation_name = route if route
94
+ span.operation_name = route
102
95
  end
103
96
 
104
97
  def route_from_env(env)
@@ -109,6 +102,8 @@ module JCW
109
102
  "#{method} #{rails_controller.controller_name}/#{rails_controller.action_name}"
110
103
  elsif (grape_route_args = env["grape.routing_args"] || env["rack.routing_args"])
111
104
  "#{method} #{grape_route_from_args(grape_route_args)}"
105
+ else
106
+ "#{method} #{env[REQUEST_PATH] || env["SCRIPT_NAME"] || env["PATH_INFO"]}".strip
112
107
  end
113
108
  end
114
109
 
@@ -121,9 +116,24 @@ module JCW
121
116
  end
122
117
  end
123
118
 
124
- def perform_on_finish_span
119
+ def build_error_log(span, error)
120
+ span.set_tag("error", true)
121
+ span.log_kv(
122
+ event: "error",
123
+ "error.kind": error.class.to_s,
124
+ "error.object": error,
125
+ message: error.message,
126
+ stack: error.backtrace.join("\n"),
127
+ )
128
+ end
129
+
130
+ def perform_on_finish_span(span)
125
131
  return unless @on_finish_span
126
- @on_finish_span.call(@span)
132
+ @on_finish_span.call(span)
133
+ end
134
+
135
+ def close_scope(scope)
136
+ scope&.close
127
137
  end
128
138
  end
129
139
  end
@@ -7,12 +7,12 @@ module JCW
7
7
  IGNORED_PAYLOAD_KEYS = %i[request response headers exception exception_object].freeze
8
8
 
9
9
  def subscribe_to_event!(event)
10
- ActiveSupport::Notifications.subscribe(event) do |name, _start, _finish, _uid, payload|
11
- add(name, payload)
10
+ ActiveSupport::Notifications.subscribe(event) do |name, start, finish, _uid, payload|
11
+ add(name, payload, finish - start)
12
12
  end
13
13
  end
14
14
 
15
- def add(name, payload)
15
+ def add(name, payload, duration)
16
16
  # skip Rails internal events
17
17
  return if name.start_with?("!")
18
18
 
@@ -23,7 +23,10 @@ module JCW
23
23
  # we should only mutate the copy of the payload
24
24
  payload = payload.dup
25
25
  IGNORED_PAYLOAD_KEYS.each { |key| payload.delete(key) if payload.key?(key) }
26
+ else
27
+ payload = { payload: payload }
26
28
  end
29
+ payload[:duration] = duration
27
30
 
28
31
  span.log_kv(message: name, context: JSON.dump(payload))
29
32
  end
data/lib/jcw/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JCW
4
- VERSION = "0.2.2"
4
+ VERSION = "0.3.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jcw
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Starovojtov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-12-27 00:00:00.000000000 Z
11
+ date: 2022-07-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -293,7 +293,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
293
293
  - !ruby/object:Gem::Version
294
294
  version: '0'
295
295
  requirements: []
296
- rubygems_version: 3.1.6
296
+ rubygems_version: 3.3.7
297
297
  signing_key:
298
298
  specification_version: 4
299
299
  summary: Wrapper for jaeger-client