skylight-core 4.0.0.beta2 → 4.0.0.beta3

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: 5667f3a36781897ae62521c5d959f4b840901098bd3fe639b8bbce7751b7339b
4
- data.tar.gz: c39fbb604997035cbfdaabafb2a6f9774c744711b41ae2201e34bf8ba6ee82ca
3
+ metadata.gz: c7f814841fc2a99900fe3822a5d94a09712ce2d1cdd3c42435386f82715acad6
4
+ data.tar.gz: 681c34b79a73d5f5eb53a04944046ef8d133db0ab349c204619359e65678e325
5
5
  SHA512:
6
- metadata.gz: 4afc3b9e000c00161e196a91936894b15a04adc6edb15760c69dd6adaa44357d1ed397f8dfe59f5105268f68faff22a72fcc1c1e8a0060236adc1141c97c3416
7
- data.tar.gz: 23f7bca0c54d9266865ea766798640a6bc4d24815611fcde6dc0e0bd81a05a7710a81ab6e22ef19dd959cbdbef099b8af0c4854ccab4daea96366825369e0c0a
6
+ metadata.gz: 6a90106d989fce292267c2be2166045cb175a3bde412ca9cff73c8a1a5321c3c131440d2c0802a313278db987ca5cc07085ff1415385b416492aa501a604b3b4
7
+ data.tar.gz: 7bc49449984efa83ceef8ea6ee020027ea98730c4ccf45aeb3b27fc8d1d5a252bb3d757854a958f3783298a5cb5c244160a7d927e558dc1cacb3e97d6a2d8665
@@ -25,16 +25,7 @@ module Skylight::Core
25
25
  def normalize_after(trace, _span, _name, payload)
26
26
  return unless config.enable_segments?
27
27
 
28
- # Show 'error' if there's an unhandled exception or if the status is 4xx or 5xx
29
- if payload[:exception] || payload[:exception_object] || payload[:status].to_s =~ /^[45]/
30
- segment = "error"
31
- # We won't have a sk_rendered_format if it's a `head` outside of a `respond_to` block.
32
- elsif payload[:sk_rendered_format]
33
- # We only show the variant if we actually have a format
34
- segment = [payload[:sk_rendered_format], payload[:sk_variant]].compact.flatten.join("+")
35
- end
36
-
37
- if segment
28
+ if (segment = segment_from_payload(payload))
38
29
  trace.segment = segment
39
30
  end
40
31
  end
@@ -44,6 +35,27 @@ module Skylight::Core
44
35
  def controller_action(payload)
45
36
  "#{payload[:controller]}##{payload[:action]}"
46
37
  end
38
+
39
+ def segment_from_payload(payload)
40
+ # Show 'error' if there's an unhandled exception or if the status is 4xx or 5xx
41
+ return "error" if payload[:exception] || payload[:exception_object]
42
+ segment_from_status(payload[:status]) || if payload[:sk_rendered_format]
43
+ # We only show the variant if we actually have a format
44
+ # We won't have a sk_rendered_format if it's a `head` outside of a `respond_to` block.
45
+ [payload[:sk_rendered_format], payload[:sk_variant]].compact.flatten.join("+")
46
+ end
47
+ end
48
+
49
+ def segment_from_status(status)
50
+ case status
51
+ when 304
52
+ "not modified"
53
+ when (300..399)
54
+ "redirect"
55
+ when (400..599)
56
+ "error"
57
+ end
58
+ end
47
59
  end
48
60
  end
49
61
  end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Skylight::Core
4
+ module Normalizers
5
+ module ActionDispatch
6
+ class ProcessMiddleware < Normalizer
7
+ register "process_middleware.action_dispatch"
8
+
9
+ CAT = "rack.middleware"
10
+ ANONYMOUS_MIDDLEWARE = "Anonymous Middleware"
11
+ ANONYMOUS = /\A#<(Class|Module|Proc):/
12
+
13
+ def normalize(trace, _name, payload)
14
+ name = payload[:middleware].to_s
15
+ name = ANONYMOUS_MIDDLEWARE if name[ANONYMOUS]
16
+ trace.endpoint = name
17
+ [CAT, name, nil]
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -5,14 +5,16 @@ module Skylight::Core
5
5
  register "render.active_model_serializers"
6
6
 
7
7
  CAT = "view.render.active_model_serializers".freeze
8
+ ANONYMOUS = "<Anonymous Serializer>".freeze
8
9
 
9
10
  def normalize(_trace, _name, payload)
10
11
  serializer_class = payload[:serializer]
11
12
 
12
- title = serializer_class.name.sub(/^ActiveModel::(Serializer::)?/, "")
13
+ title = serializer_class.name || ANONYMOUS
14
+ title = title.sub(/^ActiveModel::(Serializer::)?/, "")
13
15
 
14
16
  if (adapter_instance = payload[:adapter])
15
- adapter_name = adapter_instance.class.name.
17
+ adapter_name = adapter_instance.class.name.to_s.
16
18
  sub(/^ActiveModel::Serializer::Adapter::/, "").
17
19
  sub(/^ActiveModelSerializers::Adapter::/, "")
18
20
  desc = "Adapter: #{adapter_name}"
@@ -1,3 +1,5 @@
1
+ require 'skylight/core/formatters/http'
2
+
1
3
  module Skylight::Core
2
4
  module Normalizers
3
5
  module Faraday
@@ -94,6 +94,7 @@ module Skylight::Core
94
94
 
95
95
  %w[ action_controller/process_action
96
96
  action_controller/send_file
97
+ action_dispatch/process_middleware
97
98
  action_view/render_collection
98
99
  action_view/render_partial
99
100
  action_view/render_template
@@ -10,13 +10,13 @@ module Skylight::Core
10
10
  append_info_to_payload_without_sk(payload)
11
11
 
12
12
  rendered_mime = begin
13
- if respond_to?(:rendered_format) && rendered_format
14
- rendered_format
15
- elsif content_type.is_a?(Mime::Type)
13
+ if content_type.is_a?(Mime::Type)
16
14
  content_type
17
15
  elsif content_type.respond_to?(:to_s)
18
16
  type_str = content_type.to_s.split(';').first
19
17
  Mime::Type.lookup(type_str) unless type_str.blank?
18
+ elsif respond_to?(:rendered_format) && rendered_format
19
+ rendered_format
20
20
  end
21
21
  end
22
22
 
@@ -11,8 +11,8 @@ module Skylight::Core
11
11
  when 2
12
12
  args
13
13
  when 4
14
- # Rails >= 6.0.0.beta2 arguments are (view, path, template, locals)
15
- [args[1], args[3]]
14
+ # Rails > 6.0.0.beta3 arguments are (view, template, path, locals)
15
+ [args[2], args[3]]
16
16
  end
17
17
 
18
18
  layout = nil
@@ -28,7 +28,7 @@ module Skylight::Core
28
28
  begin
29
29
  name = self.class.name || "#{default_name}"
30
30
 
31
- traces.each{|t| t.endpoint = name }
31
+ traces.each{ |t| t.endpoint = name }
32
32
 
33
33
  spans = Skylight::Core::Fanout.instrument(title: name, category: "#{category}")
34
34
  resp = call_without_sk(*args, &block)
@@ -54,6 +54,8 @@ module Skylight::Core
54
54
  end
55
55
 
56
56
  def install
57
+ return if defined?(::ActionDispatch::MiddlewareStack::InstrumentationProxy)
58
+
57
59
  ::ActionDispatch::MiddlewareStack::Middleware.class_eval do
58
60
  alias_method :build_without_sk, :build
59
61
  def build(*args)
@@ -36,15 +36,11 @@ module Skylight::Core
36
36
 
37
37
  if activate?(config)
38
38
  if config
39
- begin
40
- if self.class.namespace.start!(config)
41
- set_middleware_position(app, config)
42
- Rails.logger.info "#{log_prefix} #{self.class.gem_name} agent enabled"
43
- else
44
- Rails.logger.info "#{log_prefix} Unable to start, see the #{self.class.gem_name} logs for more details"
45
- end
46
- rescue ConfigError => e
47
- Rails.logger.error "#{log_prefix} #{e.message}; disabling #{self.class.gem_name} agent"
39
+ if self.class.namespace.start!(config)
40
+ set_middleware_position(app, config)
41
+ Rails.logger.info "#{log_prefix} #{self.class.gem_name} agent enabled"
42
+ else
43
+ Rails.logger.info "#{log_prefix} Unable to start, see the #{self.class.gem_name} logs for more details"
48
44
  end
49
45
  end
50
46
  elsif Rails.env.development?
@@ -57,6 +53,8 @@ module Skylight::Core
57
53
  log_warning config, "#{log_prefix} You are running in the #{Rails.env} environment but haven't added it to config.#{self.class.root_key}.environments, so no data will be sent to #{config.class.service_name} servers."
58
54
  end
59
55
  end
56
+ rescue ConfigError => e
57
+ Rails.logger.error "#{log_prefix} #{e.message}; disabling #{self.class.gem_name} agent"
60
58
  end
61
59
 
62
60
  def log_warning(config, msg)
@@ -3,7 +3,7 @@ module Skylight::Core
3
3
  class Subscriber
4
4
  include Util::Logging
5
5
 
6
- attr_reader :config
6
+ attr_reader :config, :normalizers
7
7
 
8
8
  def initialize(config, instrumenter)
9
9
  @config = config
@@ -41,29 +41,7 @@ module Skylight::Core
41
41
  def start(name, _id, payload)
42
42
  return if @instrumenter.disabled?
43
43
  return unless (trace = @instrumenter.current_trace)
44
-
45
- result = normalize(trace, name, payload)
46
-
47
- unless result == :skip
48
- case result.size
49
- when 3, 4
50
- cat, title, desc, meta = result
51
- else
52
- raise "Invalid normalizer result: #{result.inspect}"
53
- end
54
-
55
- span = trace.instrument(cat, title, desc, meta)
56
- end
57
-
58
- trace.notifications << Notification.new(name, span)
59
- rescue Exception => e
60
- error "Subscriber#start error; msg=%s", e.message
61
- debug "trace=%s", trace.inspect
62
- debug "in: name=%s", name.inspect
63
- debug "in: payload=%s", payload.inspect
64
- debug "out: cat=%s, title=%s, desc=%s", cat.inspect, name.inspect, desc.inspect
65
- t { e.backtrace.join("\n") }
66
- nil
44
+ _start(trace, name, payload)
67
45
  end
68
46
 
69
47
  def finish(name, _id, payload)
@@ -104,5 +82,30 @@ module Skylight::Core
104
82
  def normalize_after(*args)
105
83
  @normalizers.normalize_after(*args)
106
84
  end
85
+
86
+ def _start(trace, name, payload)
87
+ result = normalize(trace, name, payload)
88
+
89
+ unless result == :skip
90
+ case result.size
91
+ when 3, 4
92
+ cat, title, desc, meta = result
93
+ else
94
+ raise "Invalid normalizer result: #{result.inspect}"
95
+ end
96
+
97
+ span = trace.instrument(cat, title, desc, meta)
98
+ end
99
+ rescue Exception => e
100
+ error "Subscriber#start error; msg=%s", e.message
101
+ debug "trace=%s", trace.inspect
102
+ debug "in: name=%s", name.inspect
103
+ debug "in: payload=%s", payload.inspect
104
+ debug "out: cat=%s, title=%s, desc=%s", cat.inspect, name.inspect, desc.inspect
105
+ t { e.backtrace.join("\n") }
106
+ nil
107
+ ensure
108
+ trace.notifications << Notification.new(name, span)
109
+ end
107
110
  end
108
111
  end
@@ -1,5 +1,5 @@
1
1
  module Skylight
2
2
  module Core
3
- VERSION = "4.0.0-beta2".freeze
3
+ VERSION = "4.0.0-beta3".freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: skylight-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0.beta2
4
+ version: 4.0.0.beta3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tilde, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-11 00:00:00.000000000 Z
11
+ date: 2019-04-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -170,6 +170,7 @@ files:
170
170
  - lib/skylight/core/normalizers.rb
171
171
  - lib/skylight/core/normalizers/action_controller/process_action.rb
172
172
  - lib/skylight/core/normalizers/action_controller/send_file.rb
173
+ - lib/skylight/core/normalizers/action_dispatch/process_middleware.rb
173
174
  - lib/skylight/core/normalizers/action_view/render_collection.rb
174
175
  - lib/skylight/core/normalizers/action_view/render_partial.rb
175
176
  - lib/skylight/core/normalizers/action_view/render_template.rb
@@ -265,7 +266,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
265
266
  - !ruby/object:Gem::Version
266
267
  version: 1.3.1
267
268
  requirements: []
268
- rubygems_version: 3.0.2
269
+ rubygems_version: 3.0.3
269
270
  signing_key:
270
271
  specification_version: 4
271
272
  summary: The core methods of the Skylight profiler.