skylight 5.1.0.beta3 → 5.2.0.beta2

Sign up to get free protection for your applications and to get access to all the features.
@@ -68,5 +68,8 @@ module Skylight
68
68
 
69
69
  # E0006
70
70
  register(6, "InvalidUtf8", "Invalid UTF-8")
71
+
72
+ # E0007
73
+ register(7, "GrpcConnect", "Failed to connect to gRPC server.")
71
74
  end
72
75
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "skylight/util/lru_cache"
4
- require "active_support/dependencies"
4
+ require "active_support/inflector"
5
5
 
6
6
  module Skylight
7
7
  module Extensions
@@ -163,7 +163,7 @@ module Skylight
163
163
 
164
164
  def instance_method_source_location(constant_name, method_name, source_name: :instance_method)
165
165
  @instance_method_source_location_cache.fetch([constant_name, method_name, source_name]) do
166
- if (constant = ::ActiveSupport::Dependencies.safe_constantize(constant_name))
166
+ if (constant = ::ActiveSupport::Inflector.safe_constantize(constant_name))
167
167
  if constant.instance_methods.include?(:"before_instrument_#{method_name}")
168
168
  method_name = :"before_instrument_#{method_name}"
169
169
  end
@@ -3,6 +3,8 @@ require "securerandom"
3
3
  module Skylight
4
4
  # @api private
5
5
  class Middleware
6
+ SKYLIGHT_REQUEST_ID = "skylight.request_id".freeze
7
+
6
8
  class BodyProxy
7
9
  def initialize(body, &block)
8
10
  @body = body
@@ -81,7 +83,8 @@ module Skylight
81
83
  set_request_id(env)
82
84
 
83
85
  if Skylight.tracing?
84
- error "Already instrumenting. Make sure the Skylight Rack Middleware hasn't been added more than once."
86
+ debug "Already instrumenting. Make sure the Skylight Rack Middleware hasn't been added more than once."
87
+ return @app.call(env)
85
88
  end
86
89
 
87
90
  if env["REQUEST_METHOD"] == "HEAD"
@@ -108,7 +111,7 @@ module Skylight
108
111
 
109
112
  def log_context
110
113
  # Don't cache this, it will change
111
- { request_id: @current_request_id, inst: Skylight.instrumenter&.uuid }
114
+ { request_id: current_request_id, inst: Skylight.instrumenter&.uuid }
112
115
  end
113
116
 
114
117
  # Allow for overwriting
@@ -122,8 +125,10 @@ module Skylight
122
125
 
123
126
  # Request ID code based on ActionDispatch::RequestId
124
127
  def set_request_id(env)
128
+ return if env[SKYLIGHT_REQUEST_ID]
129
+
125
130
  existing_request_id = env["action_dispatch.request_id"] || env["HTTP_X_REQUEST_ID"]
126
- @current_request_id = env["skylight.request_id"] = make_request_id(existing_request_id)
131
+ self.current_request_id = env[SKYLIGHT_REQUEST_ID] = make_request_id(existing_request_id)
127
132
  end
128
133
 
129
134
  def make_request_id(request_id)
@@ -133,5 +138,13 @@ module Skylight
133
138
  def internal_request_id
134
139
  SecureRandom.uuid
135
140
  end
141
+
142
+ def current_request_id
143
+ Thread.current[SKYLIGHT_REQUEST_ID]
144
+ end
145
+
146
+ def current_request_id=(request_id)
147
+ Thread.current[SKYLIGHT_REQUEST_ID] = request_id
148
+ end
136
149
  end
137
150
  end
@@ -15,7 +15,7 @@ module Skylight
15
15
  .tap do |str|
16
16
  if str.match(DELIVERY_JOB)
17
17
  mailer_class, mailer_method, * = job_instance.arguments
18
- return "#{mailer_class}##{mailer_method}", str
18
+ return "#{mailer_class}##{mailer_method}", str if mailer_class && mailer_method
19
19
  end
20
20
  end
21
21
  end
@@ -33,9 +33,7 @@ module Skylight
33
33
  end
34
34
 
35
35
  def normalize_after(trace, _span, _name, payload)
36
- return unless config.enable_segments? && assign_endpoint?(trace, payload)
37
-
38
- trace.segment = payload[:job].queue_name
36
+ maybe_set_endpoint(trace, payload)
39
37
  end
40
38
 
41
39
  private
@@ -53,31 +51,30 @@ module Skylight
53
51
  end
54
52
 
55
53
  def maybe_set_endpoint(trace, payload)
56
- trace.endpoint = normalize_title(payload[:job]) if assign_endpoint?(trace, payload)
57
- end
54
+ endpoint = normalize_title(payload[:job])
58
55
 
59
- def assign_endpoint?(trace, payload)
60
56
  # Always assign the endpoint if it has not yet been assigned by the ActiveJob probe.
61
- return true unless trace.endpoint
62
- if defined?(Skylight::Probes::ActiveJob::TITLE) && trace.endpoint == Skylight::Probes::ActiveJob::TITLE
63
- return true
64
- end
65
- if defined?(SKylight::Probes::DelayedJob::Probe::UNKNOWN) &&
66
- trace.endpoint == Skylight::Probes::DelayedJob::Probe::UNKNOWN
67
- return true
57
+ if !trace.endpoint ||
58
+ (defined?(Skylight::Probes::ActiveJob::TITLE) && trace.endpoint == Skylight::Probes::ActiveJob::TITLE) ||
59
+ (
60
+ defined?(Skylight::Probes::DelayedJob::Probe::UNKNOWN) &&
61
+ trace.endpoint == Skylight::Probes::DelayedJob::Probe::UNKNOWN
62
+ ) ||
63
+ # If a job is called using #perform_now inside a controller action
64
+ # or within another job's #perform method, we do not want this to
65
+ # overwrite the existing endpoint name (unless it is the default from ActiveJob).
66
+ #
67
+ # If the current endpoint name matches this payload, return true to allow the
68
+ # segment to be assigned by normalize_after.
69
+ trace.endpoint =~ DELIVERY_JOB ||
70
+ # This adapter wrapper needs to be handled specifically due to interactions with the
71
+ # standalone Delayed::Job probe, as there is no consistent way to get the wrapped
72
+ # job name among all Delayed::Job backends.
73
+ trace.endpoint == DELAYED_JOB_WRAPPER
74
+ trace.endpoint = endpoint
68
75
  end
69
76
 
70
- # If a job is called using #perform_now inside a controller action
71
- # or within another job's #perform method, we do not want this to
72
- # overwrite the existing endpoint name (unless it is the default from ActiveJob).
73
- #
74
- # If the current endpoint name matches this payload, return true to allow the
75
- # segment to be assigned by normalize_after.
76
- trace.endpoint == DELIVERY_JOB || trace.endpoint == normalize_title(payload[:job]) ||
77
- # This adapter wrapper needs to be handled specifically due to interactions with the
78
- # standalone Delayed::Job probe, as there is no consistent way to get the wrapped
79
- # job name among all Delayed::Job backends.
80
- trace.endpoint == DELAYED_JOB_WRAPPER
77
+ trace.segment = payload[:job].queue_name if trace.endpoint == endpoint && config.enable_segments?
81
78
  end
82
79
 
83
80
  def normalize_title(job_instance)
@@ -20,7 +20,7 @@ module Skylight
20
20
 
21
21
  def get_namespace(endpoint)
22
22
  # slice off preceding slash for data continuity
23
- ::Grape::Namespace.joined_space_path(endpoint.namespace_stackable(:namespace)).to_s[1..-1]
23
+ ::Grape::Namespace.joined_space_path(endpoint.namespace_stackable(:namespace)).to_s[1..]
24
24
  end
25
25
  end
26
26
  end
@@ -25,10 +25,10 @@ module Skylight
25
25
  # for Rails <= 5.2 ActionDispatch::MiddlewareStack::Middleware
26
26
  module Instrumentation
27
27
  def build(*)
28
- sk_instrument_middleware(super)
28
+ Instrumentation.sk_instrument_middleware(super)
29
29
  end
30
30
 
31
- def sk_instrument_middleware(middleware)
31
+ def self.sk_instrument_middleware(middleware)
32
32
  return middleware if middleware.is_a?(Skylight::Middleware)
33
33
 
34
34
  # Not sure how this would actually happen
@@ -0,0 +1,37 @@
1
+ module Skylight
2
+ module Probes
3
+ module Rack
4
+ module Builder
5
+ module Instrumentation
6
+ def use(middleware, *args, &block)
7
+ if @map
8
+ mapping = @map
9
+ @map = nil
10
+ @use << proc { |app| generate_map(app, mapping) }
11
+ end
12
+ @use << proc do |app|
13
+ middleware
14
+ .new(app, *args, &block)
15
+ .tap do |middleware_instance|
16
+ Skylight::Probes::Middleware::Instrumentation.sk_instrument_middleware(middleware_instance)
17
+ end
18
+ end
19
+ end
20
+ ruby2_keywords(:use) if respond_to?(:ruby2_keywords, true)
21
+ end
22
+
23
+ class Probe
24
+ def install
25
+ if defined?(::Rack.release) && Gem::Version.new(::Rack.release) >= ::Gem::Version.new("1.4") &&
26
+ defined?(::Rack::Builder)
27
+ require "skylight/probes/middleware"
28
+ ::Rack::Builder.prepend(Instrumentation)
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+
35
+ register(:rack_builder, "Rack::Builder", "rack/builder", Skylight::Probes::Rack::Builder::Probe.new)
36
+ end
37
+ end
@@ -2,8 +2,8 @@ module Skylight
2
2
  module Probes
3
3
  module Sinatra
4
4
  module Instrumentation
5
- def build(*)
6
- use Skylight::Middleware
5
+ def setup_default_middleware(builder)
6
+ builder.use Skylight::Middleware
7
7
  super
8
8
  end
9
9
  end
@@ -99,8 +99,8 @@ module Skylight
99
99
 
100
100
  configure_logging(config, app)
101
101
 
102
- config[:'daemon.sockdir_path'] ||= tmp
103
- config[:'normalizers.render.view_paths'] = existent_paths(app.config.paths["app/views"]) + [Rails.root.to_s]
102
+ config[:"daemon.sockdir_path"] ||= tmp
103
+ config[:"normalizers.render.view_paths"] = existent_paths(app.config.paths["app/views"]) + [Rails.root.to_s]
104
104
 
105
105
  config[:env] ||= Rails.env.to_s if config[:report_rails_env]
106
106
 
@@ -1,2 +1,2 @@
1
1
  require "skylight"
2
- Skylight.probe(:sinatra_add_middleware, :sinatra, :tilt, :sequel)
2
+ Skylight.probe(:sinatra_add_middleware, :sinatra, :tilt, :sequel, :rack_builder)
@@ -13,7 +13,7 @@ module Skylight
13
13
  # rubocop:disable Lint/DuplicateMethods
14
14
  def tick
15
15
  now = Time.now
16
- now.to_i * 1_000_000_000 + now.usec * 1_000
16
+ (now.to_i * 1_000_000_000) + (now.usec * 1_000)
17
17
  end
18
18
 
19
19
  # rubocop:enable Lint/DuplicateMethods
@@ -52,15 +52,15 @@ module Skylight
52
52
  end
53
53
 
54
54
  def id
55
- config.get(:'deploy.id') || git_sha
55
+ config.get(:"deploy.id") || git_sha
56
56
  end
57
57
 
58
58
  def git_sha
59
- config.get(:'deploy.git_sha')
59
+ config.get(:"deploy.git_sha")
60
60
  end
61
61
 
62
62
  def description
63
- config.get(:'deploy.description')
63
+ config.get(:"deploy.description")
64
64
  end
65
65
  end
66
66
 
@@ -85,7 +85,7 @@ module Skylight
85
85
  private
86
86
 
87
87
  def get_info
88
- info_path = config[:'heroku.dyno_info_path']
88
+ info_path = config[:"heroku.dyno_info_path"]
89
89
 
90
90
  if File.exist?(info_path) && (info = JSON.parse(File.read(info_path)))
91
91
  info["release"]
@@ -38,8 +38,8 @@ module Skylight
38
38
  "x86"
39
39
  when /ppc|powerpc/
40
40
  "powerpc"
41
- when /^arm/
42
- "arm"
41
+ when /arm64|aarch64/
42
+ "aarch64"
43
43
  else
44
44
  cpu
45
45
  end
@@ -3,5 +3,5 @@ module Skylight
3
3
  # for compatibility with semver when it is parsed by the rust agent.
4
4
  # This string will be transformed in the gemspec to "5.0.0.alpha"
5
5
  # to conform with rubygems.
6
- VERSION = "5.1.0-beta3".freeze
6
+ VERSION = "5.2.0-beta2".freeze
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: skylight
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.1.0.beta3
4
+ version: 5.2.0.beta2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tilde, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-21 00:00:00.000000000 Z
11
+ date: 2021-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -142,14 +142,14 @@ dependencies:
142
142
  requirements:
143
143
  - - "~>"
144
144
  - !ruby/object:Gem::Version
145
- version: 1.15.0
145
+ version: 1.21.0
146
146
  type: :development
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
150
  - - "~>"
151
151
  - !ruby/object:Gem::Version
152
- version: 1.15.0
152
+ version: 1.21.0
153
153
  - !ruby/object:Gem::Dependency
154
154
  name: simplecov
155
155
  requirement: !ruby/object:Gem::Requirement
@@ -296,6 +296,7 @@ files:
296
296
  - lib/skylight/probes/mongo.rb
297
297
  - lib/skylight/probes/mongoid.rb
298
298
  - lib/skylight/probes/net_http.rb
299
+ - lib/skylight/probes/rack_builder.rb
299
300
  - lib/skylight/probes/redis.rb
300
301
  - lib/skylight/probes/sequel.rb
301
302
  - lib/skylight/probes/sinatra.rb
@@ -375,14 +376,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
375
376
  requirements:
376
377
  - - ">="
377
378
  - !ruby/object:Gem::Version
378
- version: '2.5'
379
+ version: '2.6'
379
380
  required_rubygems_version: !ruby/object:Gem::Requirement
380
381
  requirements:
381
382
  - - ">"
382
383
  - !ruby/object:Gem::Version
383
384
  version: 1.3.1
384
385
  requirements: []
385
- rubygems_version: 3.2.15
386
+ rubygems_version: 3.0.8
386
387
  signing_key:
387
388
  specification_version: 4
388
389
  summary: Skylight is a smart profiler for Rails, Sinatra, and other Ruby apps.