skylight 5.0.1 → 5.1.1
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 +4 -4
- data/CHANGELOG.md +395 -364
- data/CLA.md +1 -1
- data/LICENSE.md +7 -17
- data/README.md +1 -1
- data/ext/extconf.rb +42 -54
- data/ext/libskylight.yml +9 -6
- data/lib/skylight.rb +20 -30
- data/lib/skylight/api.rb +22 -18
- data/lib/skylight/cli.rb +47 -46
- data/lib/skylight/cli/doctor.rb +50 -50
- data/lib/skylight/cli/helpers.rb +19 -19
- data/lib/skylight/cli/merger.rb +141 -139
- data/lib/skylight/config.rb +265 -300
- data/lib/skylight/deprecation.rb +4 -4
- data/lib/skylight/errors.rb +3 -4
- data/lib/skylight/extensions.rb +17 -29
- data/lib/skylight/extensions/source_location.rb +128 -128
- data/lib/skylight/formatters/http.rb +1 -3
- data/lib/skylight/gc.rb +30 -40
- data/lib/skylight/helpers.rb +43 -41
- data/lib/skylight/instrumenter.rb +25 -18
- data/lib/skylight/middleware.rb +31 -35
- data/lib/skylight/native.rb +8 -10
- data/lib/skylight/native_ext_fetcher.rb +10 -12
- data/lib/skylight/normalizers.rb +43 -39
- data/lib/skylight/normalizers/action_controller/process_action.rb +24 -25
- data/lib/skylight/normalizers/action_controller/send_file.rb +7 -6
- data/lib/skylight/normalizers/action_dispatch/route_set.rb +7 -7
- data/lib/skylight/normalizers/active_job/perform.rb +48 -44
- data/lib/skylight/normalizers/active_model_serializers/render.rb +7 -3
- data/lib/skylight/normalizers/active_storage.rb +11 -13
- data/lib/skylight/normalizers/active_support/cache.rb +1 -12
- data/lib/skylight/normalizers/coach/handler_finish.rb +1 -3
- data/lib/skylight/normalizers/default.rb +1 -9
- data/lib/skylight/normalizers/faraday/request.rb +1 -3
- data/lib/skylight/normalizers/grape/endpoint.rb +13 -19
- data/lib/skylight/normalizers/grape/endpoint_run.rb +16 -18
- data/lib/skylight/normalizers/grape/endpoint_run_filters.rb +1 -3
- data/lib/skylight/normalizers/graphql/base.rb +23 -28
- data/lib/skylight/normalizers/render.rb +19 -21
- data/lib/skylight/normalizers/shrine.rb +15 -17
- data/lib/skylight/normalizers/sql.rb +4 -4
- data/lib/skylight/probes.rb +38 -46
- data/lib/skylight/probes/action_controller.rb +32 -28
- data/lib/skylight/probes/action_dispatch/request_id.rb +9 -5
- data/lib/skylight/probes/action_dispatch/routing/route_set.rb +7 -5
- data/lib/skylight/probes/action_view.rb +9 -10
- data/lib/skylight/probes/active_job_enqueue.rb +3 -9
- data/lib/skylight/probes/active_model_serializers.rb +8 -8
- data/lib/skylight/probes/delayed_job.rb +37 -42
- data/lib/skylight/probes/elasticsearch.rb +3 -5
- data/lib/skylight/probes/excon.rb +1 -1
- data/lib/skylight/probes/excon/middleware.rb +22 -23
- data/lib/skylight/probes/graphql.rb +2 -7
- data/lib/skylight/probes/middleware.rb +14 -5
- data/lib/skylight/probes/mongo.rb +83 -91
- data/lib/skylight/probes/net_http.rb +1 -1
- data/lib/skylight/probes/redis.rb +5 -17
- data/lib/skylight/probes/sequel.rb +7 -11
- data/lib/skylight/probes/sinatra.rb +8 -5
- data/lib/skylight/probes/tilt.rb +2 -4
- data/lib/skylight/railtie.rb +121 -135
- data/lib/skylight/sidekiq.rb +4 -5
- data/lib/skylight/subscriber.rb +31 -33
- data/lib/skylight/test.rb +89 -84
- data/lib/skylight/trace.rb +121 -115
- data/lib/skylight/user_config.rb +14 -17
- data/lib/skylight/util/clock.rb +1 -0
- data/lib/skylight/util/component.rb +18 -21
- data/lib/skylight/util/deploy.rb +11 -13
- data/lib/skylight/util/http.rb +104 -105
- data/lib/skylight/util/logging.rb +4 -6
- data/lib/skylight/util/lru_cache.rb +2 -6
- data/lib/skylight/util/platform.rb +2 -6
- data/lib/skylight/util/ssl.rb +1 -25
- data/lib/skylight/version.rb +1 -1
- data/lib/skylight/vm/gc.rb +1 -9
- metadata +6 -6
| @@ -4,17 +4,9 @@ module Skylight | |
| 4 4 | 
             
                  # Unfortunately, because of the nature of pipelining, there's no way for us to
         | 
| 5 5 | 
             
                  # give a time breakdown on the individual items.
         | 
| 6 6 |  | 
| 7 | 
            -
                  PIPELINED_OPTS = {
         | 
| 8 | 
            -
             | 
| 9 | 
            -
             | 
| 10 | 
            -
                    internal: true
         | 
| 11 | 
            -
                  }.freeze
         | 
| 12 | 
            -
             | 
| 13 | 
            -
                  MULTI_OPTS = {
         | 
| 14 | 
            -
                    category: "db.redis.multi".freeze,
         | 
| 15 | 
            -
                    title:    "MULTI".freeze,
         | 
| 16 | 
            -
                    internal: true
         | 
| 17 | 
            -
                  }.freeze
         | 
| 7 | 
            +
                  PIPELINED_OPTS = { category: "db.redis.pipelined".freeze, title: "PIPELINE".freeze, internal: true }.freeze
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                  MULTI_OPTS = { category: "db.redis.multi".freeze, title: "MULTI".freeze, internal: true }.freeze
         | 
| 18 10 |  | 
| 19 11 | 
             
                  module ClientInstrumentation
         | 
| 20 12 | 
             
                    def call(command, *)
         | 
| @@ -22,11 +14,7 @@ module Skylight | |
| 22 14 |  | 
| 23 15 | 
             
                      return super if command_name == :auth
         | 
| 24 16 |  | 
| 25 | 
            -
                      opts = {
         | 
| 26 | 
            -
                        category: "db.redis.command",
         | 
| 27 | 
            -
                        title:    command_name.upcase.to_s,
         | 
| 28 | 
            -
                        internal: true
         | 
| 29 | 
            -
                      }
         | 
| 17 | 
            +
                      opts = { category: "db.redis.command", title: command_name.upcase.to_s, internal: true }
         | 
| 30 18 |  | 
| 31 19 | 
             
                      Skylight.instrument(opts) { super }
         | 
| 32 20 | 
             
                    end
         | 
| @@ -48,7 +36,7 @@ module Skylight | |
| 48 36 |  | 
| 49 37 | 
             
                      if !version || version < Gem::Version.new("3.0.0")
         | 
| 50 38 | 
             
                        Skylight.error "The installed version of Redis doesn't support Middlewares. " \
         | 
| 51 | 
            -
             | 
| 39 | 
            +
                                         "At least version 3.0.0 is required."
         | 
| 52 40 | 
             
                        return
         | 
| 53 41 | 
             
                      end
         | 
| 54 42 |  | 
| @@ -8,20 +8,16 @@ module Skylight | |
| 8 8 |  | 
| 9 9 | 
             
                      method_name = ::Sequel::Database.method_defined?(:log_connection_yield) ? "log_connection_yield" : "log_yield"
         | 
| 10 10 |  | 
| 11 | 
            -
                      mod = | 
| 12 | 
            -
                         | 
| 13 | 
            -
                           | 
| 14 | 
            -
                             | 
| 15 | 
            -
                              "sql.sequel",
         | 
| 16 | 
            -
             | 
| 17 | 
            -
                               | 
| 18 | 
            -
                              binds: args
         | 
| 19 | 
            -
                            ) do
         | 
| 20 | 
            -
                              block.call
         | 
| 11 | 
            +
                      mod =
         | 
| 12 | 
            +
                        Module.new do
         | 
| 13 | 
            +
                          define_method method_name do |sql, *args, &block|
         | 
| 14 | 
            +
                            super(sql, *args) do
         | 
| 15 | 
            +
                              ::ActiveSupport::Notifications.instrument("sql.sequel", sql: sql, name: "SQL", binds: args) do
         | 
| 16 | 
            +
                                block.call
         | 
| 17 | 
            +
                              end
         | 
| 21 18 | 
             
                            end
         | 
| 22 19 | 
             
                          end
         | 
| 23 20 | 
             
                        end
         | 
| 24 | 
            -
                      end
         | 
| 25 21 |  | 
| 26 22 | 
             
                      ::Sequel::Database.prepend(mod)
         | 
| 27 23 | 
             
                    end
         | 
| @@ -37,11 +37,14 @@ module Skylight | |
| 37 37 | 
             
                    end
         | 
| 38 38 |  | 
| 39 39 | 
             
                    def compile_template(engine, data, options, *)
         | 
| 40 | 
            -
                       | 
| 41 | 
            -
             | 
| 42 | 
            -
             | 
| 43 | 
            -
             | 
| 44 | 
            -
             | 
| 40 | 
            +
                      super.tap do |template|
         | 
| 41 | 
            +
                        if defined?(::Tilt::Template) && template.is_a?(::Tilt::Template)
         | 
| 42 | 
            +
                          # Pass along a useful "virtual path" to Tilt. The Tilt probe will handle
         | 
| 43 | 
            +
                          # instrumenting correctly.
         | 
| 44 | 
            +
                          virtual_path = data.is_a?(Symbol) ? data.to_s : "Inline template (#{engine})"
         | 
| 45 | 
            +
                          template.instance_variable_set(:@__sky_virtual_path, virtual_path)
         | 
| 46 | 
            +
                        end
         | 
| 47 | 
            +
                      end
         | 
| 45 48 | 
             
                    end
         | 
| 46 49 | 
             
                  end
         | 
| 47 50 |  | 
    
        data/lib/skylight/probes/tilt.rb
    CHANGED
    
    | @@ -6,12 +6,10 @@ module Skylight | |
| 6 6 | 
             
                    def render(*args, &block)
         | 
| 7 7 | 
             
                      opts = {
         | 
| 8 8 | 
             
                        category: "view.render.template",
         | 
| 9 | 
            -
                        title: | 
| 9 | 
            +
                        title: @__sky_virtual_path || options[:sky_virtual_path] || basename || "Unknown template name"
         | 
| 10 10 | 
             
                      }
         | 
| 11 11 |  | 
| 12 | 
            -
                      Skylight.instrument(opts)  | 
| 13 | 
            -
                        super(*args, &block)
         | 
| 14 | 
            -
                      end
         | 
| 12 | 
            +
                      Skylight.instrument(opts) { super(*args, &block) }
         | 
| 15 13 | 
             
                    end
         | 
| 16 14 | 
             
                  end
         | 
| 17 15 |  | 
    
        data/lib/skylight/railtie.rb
    CHANGED
    
    | @@ -28,183 +28,169 @@ module Skylight | |
| 28 28 |  | 
| 29 29 | 
             
                private
         | 
| 30 30 |  | 
| 31 | 
            -
             | 
| 32 | 
            -
             | 
| 33 | 
            -
             | 
| 34 | 
            -
             | 
| 35 | 
            -
             | 
| 36 | 
            -
             | 
| 31 | 
            +
                # We must have an opt-in signal
         | 
| 32 | 
            +
                def show_worker_activation_warning(sk_config)
         | 
| 33 | 
            +
                  reasons = []
         | 
| 34 | 
            +
                  reasons << "the 'active_job' probe is enabled" if sk_rails_config.probes.include?("active_job")
         | 
| 35 | 
            +
                  reasons << "the 'delayed_job' probe is enabled" if sk_rails_config.probes.include?("delayed_job")
         | 
| 36 | 
            +
                  reasons << "SKYLIGHT_ENABLE_SIDEKIQ is set" if sk_config.enable_sidekiq?
         | 
| 37 37 |  | 
| 38 | 
            -
             | 
| 38 | 
            +
                  return if reasons.empty?
         | 
| 39 39 |  | 
| 40 | 
            -
             | 
| 41 | 
            -
             | 
| 40 | 
            +
                  sk_config.logger.warn("Activating Skylight for Background Jobs because #{reasons.to_sentence}")
         | 
| 41 | 
            +
                end
         | 
| 42 42 |  | 
| 43 | 
            -
             | 
| 44 | 
            -
             | 
| 45 | 
            -
             | 
| 43 | 
            +
                def log_prefix
         | 
| 44 | 
            +
                  "[SKYLIGHT] [#{Skylight::VERSION}]"
         | 
| 45 | 
            +
                end
         | 
| 46 46 |  | 
| 47 | 
            -
             | 
| 48 | 
            -
             | 
| 49 | 
            -
             | 
| 50 | 
            -
             | 
| 47 | 
            +
                def development_warning
         | 
| 48 | 
            +
                  "#{log_prefix} Running Skylight in development mode. No data will be reported until you deploy your app.\n" \
         | 
| 49 | 
            +
                    "(To disable this message for all local apps, run `skylight disable_dev_warning`.)"
         | 
| 50 | 
            +
                end
         | 
| 51 51 |  | 
| 52 | 
            -
             | 
| 53 | 
            -
             | 
| 54 | 
            -
             | 
| 52 | 
            +
                def run_initializer(app)
         | 
| 53 | 
            +
                  # Load probes even when agent is inactive to catch probe related bugs sooner
         | 
| 54 | 
            +
                  load_probes
         | 
| 55 55 |  | 
| 56 | 
            -
             | 
| 56 | 
            +
                  config = load_skylight_config(app)
         | 
| 57 57 |  | 
| 58 | 
            -
             | 
| 59 | 
            -
             | 
| 60 | 
            -
             | 
| 61 | 
            -
             | 
| 62 | 
            -
             | 
| 63 | 
            -
             | 
| 64 | 
            -
             | 
| 65 | 
            -
                        end
         | 
| 66 | 
            -
                      end
         | 
| 67 | 
            -
                    elsif Rails.env.development?
         | 
| 68 | 
            -
                      unless config.user_config.disable_dev_warning?
         | 
| 69 | 
            -
                        log_warning config, development_warning
         | 
| 70 | 
            -
                      end
         | 
| 71 | 
            -
                    elsif !Rails.env.test?
         | 
| 72 | 
            -
                      unless config.user_config.disable_env_warning?
         | 
| 73 | 
            -
                        log_warning config, "#{log_prefix} You are running in the #{Rails.env} environment but haven't added it " \
         | 
| 74 | 
            -
                                            "to config.skylight.environments, so no data will be sent to Skylight servers."
         | 
| 58 | 
            +
                  if activate?(config)
         | 
| 59 | 
            +
                    if config
         | 
| 60 | 
            +
                      if Skylight.start!(config)
         | 
| 61 | 
            +
                        set_middleware_position(app, config)
         | 
| 62 | 
            +
                        Rails.logger.info "#{log_prefix} Skylight agent enabled"
         | 
| 63 | 
            +
                      else
         | 
| 64 | 
            +
                        Rails.logger.info "#{log_prefix} Unable to start, see the Skylight logs for more details"
         | 
| 75 65 | 
             
                      end
         | 
| 76 66 | 
             
                    end
         | 
| 77 | 
            -
                   | 
| 78 | 
            -
                     | 
| 79 | 
            -
                   | 
| 80 | 
            -
             | 
| 81 | 
            -
             | 
| 82 | 
            -
             | 
| 83 | 
            -
             | 
| 84 | 
            -
                    else
         | 
| 85 | 
            -
                      Rails.logger.warn(msg)
         | 
| 67 | 
            +
                  elsif Rails.env.development?
         | 
| 68 | 
            +
                    log_warning config, development_warning unless config.user_config.disable_dev_warning?
         | 
| 69 | 
            +
                  elsif !Rails.env.test?
         | 
| 70 | 
            +
                    unless config.user_config.disable_env_warning?
         | 
| 71 | 
            +
                      log_warning config,
         | 
| 72 | 
            +
                                  "#{log_prefix} You are running in the #{Rails.env} environment but haven't added it " \
         | 
| 73 | 
            +
                                    "to config.skylight.environments, so no data will be sent to Skylight servers."
         | 
| 86 74 | 
             
                    end
         | 
| 87 75 | 
             
                  end
         | 
| 76 | 
            +
                rescue Skylight::ConfigError => e
         | 
| 77 | 
            +
                  Rails.logger.error "#{log_prefix} #{e.message}; disabling Skylight agent"
         | 
| 78 | 
            +
                end
         | 
| 88 79 |  | 
| 89 | 
            -
             | 
| 90 | 
            -
             | 
| 91 | 
            -
             | 
| 80 | 
            +
                def log_warning(config, msg)
         | 
| 81 | 
            +
                  config ? config.alert_logger.warn(msg) : Rails.logger.warn(msg)
         | 
| 82 | 
            +
                end
         | 
| 92 83 |  | 
| 93 | 
            -
             | 
| 94 | 
            -
             | 
| 95 | 
            -
             | 
| 84 | 
            +
                def existent_paths(paths)
         | 
| 85 | 
            +
                  paths.respond_to?(:existent) ? paths.existent : paths.select { |f| File.exist?(f) }
         | 
| 86 | 
            +
                end
         | 
| 96 87 |  | 
| 97 | 
            -
             | 
| 98 | 
            -
             | 
| 99 | 
            -
             | 
| 100 | 
            -
                    end
         | 
| 88 | 
            +
                def load_skylight_config(app)
         | 
| 89 | 
            +
                  path = config_path(app)
         | 
| 90 | 
            +
                  path = nil unless File.exist?(path)
         | 
| 101 91 |  | 
| 102 | 
            -
             | 
| 103 | 
            -
                     | 
| 92 | 
            +
                  unless (tmp = app.config.paths["tmp"].first)
         | 
| 93 | 
            +
                    Rails.logger.error "#{log_prefix} tmp directory missing from rails configuration"
         | 
| 94 | 
            +
                    return nil
         | 
| 95 | 
            +
                  end
         | 
| 104 96 |  | 
| 105 | 
            -
             | 
| 97 | 
            +
                  config = Config.load(file: path, priority_key: Rails.env.to_s)
         | 
| 98 | 
            +
                  config[:root] = Rails.root
         | 
| 106 99 |  | 
| 107 | 
            -
             | 
| 108 | 
            -
                    config[:'normalizers.render.view_paths'] = existent_paths(app.config.paths["app/views"]) + [Rails.root.to_s]
         | 
| 100 | 
            +
                  configure_logging(config, app)
         | 
| 109 101 |  | 
| 110 | 
            -
             | 
| 111 | 
            -
             | 
| 112 | 
            -
                    end
         | 
| 102 | 
            +
                  config[:'daemon.sockdir_path'] ||= tmp
         | 
| 103 | 
            +
                  config[:'normalizers.render.view_paths'] = existent_paths(app.config.paths["app/views"]) + [Rails.root.to_s]
         | 
| 113 104 |  | 
| 114 | 
            -
             | 
| 115 | 
            -
                  end
         | 
| 105 | 
            +
                  config[:env] ||= Rails.env.to_s if config[:report_rails_env]
         | 
| 116 106 |  | 
| 117 | 
            -
                   | 
| 118 | 
            -
             | 
| 119 | 
            -
                      config.logger = logger
         | 
| 120 | 
            -
                    else
         | 
| 121 | 
            -
                      # Configure the log file destination
         | 
| 122 | 
            -
                      if (log_file = sk_rails_config(app).log_file)
         | 
| 123 | 
            -
                        config["log_file"] = log_file
         | 
| 124 | 
            -
                      end
         | 
| 107 | 
            +
                  config
         | 
| 108 | 
            +
                end
         | 
| 125 109 |  | 
| 126 | 
            -
             | 
| 127 | 
            -
             | 
| 128 | 
            -
             | 
| 110 | 
            +
                def configure_logging(config, app)
         | 
| 111 | 
            +
                  if (logger = sk_rails_config(app).logger)
         | 
| 112 | 
            +
                    config.logger = logger
         | 
| 113 | 
            +
                  else
         | 
| 114 | 
            +
                    # Configure the log file destination
         | 
| 115 | 
            +
                    if (log_file = sk_rails_config(app).log_file)
         | 
| 116 | 
            +
                      config["log_file"] = log_file
         | 
| 117 | 
            +
                    end
         | 
| 129 118 |  | 
| 130 | 
            -
             | 
| 131 | 
            -
             | 
| 132 | 
            -
             | 
| 119 | 
            +
                    if (native_log_file = sk_rails_config(app).native_log_file)
         | 
| 120 | 
            +
                      config["native_log_file"] = native_log_file
         | 
| 121 | 
            +
                    end
         | 
| 133 122 |  | 
| 134 | 
            -
             | 
| 135 | 
            -
             | 
| 123 | 
            +
                    config["log_file"] = File.join(Rails.root, "log/skylight.log") if !config.key?("log_file") && !config.on_heroku?
         | 
| 124 | 
            +
             | 
| 125 | 
            +
                    # Configure the log level
         | 
| 126 | 
            +
                    if (level = sk_rails_config(app).log_level)
         | 
| 127 | 
            +
                      config["log_level"] = level
         | 
| 128 | 
            +
                    elsif !config.key?("log_level")
         | 
| 129 | 
            +
                      if (level = app.config.log_level)
         | 
| 136 130 | 
             
                        config["log_level"] = level
         | 
| 137 | 
            -
                      elsif !config.key?("log_level")
         | 
| 138 | 
            -
                        if (level = app.config.log_level)
         | 
| 139 | 
            -
                          config["log_level"] = level
         | 
| 140 | 
            -
                        end
         | 
| 141 131 | 
             
                      end
         | 
| 142 132 | 
             
                    end
         | 
| 143 133 | 
             
                  end
         | 
| 134 | 
            +
                end
         | 
| 144 135 |  | 
| 145 | 
            -
             | 
| 146 | 
            -
             | 
| 147 | 
            -
             | 
| 136 | 
            +
                def config_path(app)
         | 
| 137 | 
            +
                  File.expand_path(sk_rails_config.config_path, app.root)
         | 
| 138 | 
            +
                end
         | 
| 148 139 |  | 
| 149 | 
            -
             | 
| 150 | 
            -
             | 
| 151 | 
            -
             | 
| 140 | 
            +
                def environments
         | 
| 141 | 
            +
                  Array(sk_rails_config.environments).map { |e| e&.to_s }.compact
         | 
| 142 | 
            +
                end
         | 
| 152 143 |  | 
| 153 | 
            -
             | 
| 154 | 
            -
             | 
| 144 | 
            +
                def activate?(sk_config)
         | 
| 145 | 
            +
                  return false unless sk_config
         | 
| 155 146 |  | 
| 156 | 
            -
             | 
| 157 | 
            -
             | 
| 158 | 
            -
                      if ENV.key?(key)
         | 
| 159 | 
            -
                        ENV[key] !~ /^false$/i
         | 
| 160 | 
            -
                      else
         | 
| 161 | 
            -
                        environments.include?(Rails.env.to_s)
         | 
| 162 | 
            -
                      end
         | 
| 147 | 
            +
                  key = "SKYLIGHT_ENABLED"
         | 
| 148 | 
            +
                  activate = ENV.key?(key) ? ENV[key] !~ /^false$/i : environments.include?(Rails.env.to_s)
         | 
| 163 149 |  | 
| 164 | 
            -
             | 
| 150 | 
            +
                  show_worker_activation_warning(sk_config) if activate
         | 
| 165 151 |  | 
| 166 | 
            -
             | 
| 167 | 
            -
             | 
| 152 | 
            +
                  activate
         | 
| 153 | 
            +
                end
         | 
| 168 154 |  | 
| 169 | 
            -
             | 
| 170 | 
            -
             | 
| 171 | 
            -
             | 
| 172 | 
            -
             | 
| 155 | 
            +
                def load_probes
         | 
| 156 | 
            +
                  probes = sk_rails_config.probes || []
         | 
| 157 | 
            +
                  Skylight::Probes.probe(*probes)
         | 
| 158 | 
            +
                end
         | 
| 173 159 |  | 
| 174 | 
            -
             | 
| 175 | 
            -
             | 
| 176 | 
            -
             | 
| 177 | 
            -
             | 
| 178 | 
            -
             | 
| 179 | 
            -
                    end
         | 
| 160 | 
            +
                def middleware_position
         | 
| 161 | 
            +
                  if sk_rails_config.middleware_position.is_a?(Hash)
         | 
| 162 | 
            +
                    sk_rails_config.middleware_position.symbolize_keys
         | 
| 163 | 
            +
                  else
         | 
| 164 | 
            +
                    sk_rails_config.middleware_position
         | 
| 180 165 | 
             
                  end
         | 
| 166 | 
            +
                end
         | 
| 181 167 |  | 
| 182 | 
            -
             | 
| 183 | 
            -
             | 
| 184 | 
            -
             | 
| 185 | 
            -
             | 
| 186 | 
            -
             | 
| 187 | 
            -
             | 
| 188 | 
            -
             | 
| 168 | 
            +
                def insert_middleware(app, config)
         | 
| 169 | 
            +
                  if middleware_position.key?(:after)
         | 
| 170 | 
            +
                    app.middleware.insert_after(middleware_position[:after], Skylight::Middleware, config: config)
         | 
| 171 | 
            +
                  elsif middleware_position.key?(:before)
         | 
| 172 | 
            +
                    app.middleware.insert_before(middleware_position[:before], Skylight::Middleware, config: config)
         | 
| 173 | 
            +
                  else
         | 
| 174 | 
            +
                    raise "The middleware position you have set is invalid. Please be sure " \
         | 
| 189 175 | 
             
                            "`config.skylight.middleware_position` is set up correctly."
         | 
| 190 | 
            -
                    end
         | 
| 191 176 | 
             
                  end
         | 
| 177 | 
            +
                end
         | 
| 192 178 |  | 
| 193 | 
            -
             | 
| 194 | 
            -
             | 
| 195 | 
            -
             | 
| 196 | 
            -
             | 
| 197 | 
            -
             | 
| 198 | 
            -
             | 
| 199 | 
            -
             | 
| 200 | 
            -
             | 
| 201 | 
            -
             | 
| 179 | 
            +
                def set_middleware_position(app, config)
         | 
| 180 | 
            +
                  if middleware_position.is_a?(Integer)
         | 
| 181 | 
            +
                    app.middleware.insert middleware_position, Skylight::Middleware, config: config
         | 
| 182 | 
            +
                  elsif middleware_position.is_a?(Hash) && middleware_position.keys.count == 1
         | 
| 183 | 
            +
                    insert_middleware(app, config)
         | 
| 184 | 
            +
                  elsif middleware_position.nil?
         | 
| 185 | 
            +
                    app.middleware.insert 0, Skylight::Middleware, config: config
         | 
| 186 | 
            +
                  else
         | 
| 187 | 
            +
                    raise "The middleware position you have set is invalid. Please be sure " \
         | 
| 202 188 | 
             
                            "`config.skylight.middleware_position` is set up correctly."
         | 
| 203 | 
            -
                    end
         | 
| 204 189 | 
             
                  end
         | 
| 190 | 
            +
                end
         | 
| 205 191 |  | 
| 206 | 
            -
             | 
| 207 | 
            -
             | 
| 208 | 
            -
             | 
| 192 | 
            +
                def sk_rails_config(target = self)
         | 
| 193 | 
            +
                  target.config.skylight
         | 
| 194 | 
            +
                end
         | 
| 209 195 | 
             
              end
         | 
| 210 196 | 
             
            end
         | 
    
        data/lib/skylight/sidekiq.rb
    CHANGED
    
    | @@ -38,11 +38,10 @@ module Skylight | |
| 38 38 | 
             
                  end
         | 
| 39 39 | 
             
                end
         | 
| 40 40 |  | 
| 41 | 
            -
                ActiveSupport::Notifications.subscribe( | 
| 42 | 
            -
             | 
| 43 | 
            -
             | 
| 44 | 
            -
             | 
| 45 | 
            -
                  end
         | 
| 41 | 
            +
                ActiveSupport::Notifications.subscribe(
         | 
| 42 | 
            +
                  "started_instrumenter.skylight"
         | 
| 43 | 
            +
                ) do |_name, _started, _finished, _unique_id, payload|
         | 
| 44 | 
            +
                  add_middleware if payload[:instrumenter].config.enable_sidekiq?
         | 
| 46 45 | 
             
                end
         | 
| 47 46 | 
             
              end
         | 
| 48 47 | 
             
            end
         | 
    
        data/lib/skylight/subscriber.rb
    CHANGED
    
    | @@ -6,17 +6,15 @@ module Skylight | |
| 6 6 | 
             
                attr_reader :config, :normalizers
         | 
| 7 7 |  | 
| 8 8 | 
             
                def initialize(config, instrumenter)
         | 
| 9 | 
            -
                  @config | 
| 10 | 
            -
                  @normalizers | 
| 9 | 
            +
                  @config = config
         | 
| 10 | 
            +
                  @normalizers = Normalizers.build(config)
         | 
| 11 11 | 
             
                  @instrumenter = instrumenter
         | 
| 12 | 
            -
                  @subscribers | 
| 12 | 
            +
                  @subscribers = []
         | 
| 13 13 | 
             
                end
         | 
| 14 14 |  | 
| 15 15 | 
             
                def register!
         | 
| 16 16 | 
             
                  unregister!
         | 
| 17 | 
            -
                  @normalizers. | 
| 18 | 
            -
                    @subscribers << ActiveSupport::Notifications.subscribe(key, self)
         | 
| 19 | 
            -
                  end
         | 
| 17 | 
            +
                  @normalizers.each_key { |key| @subscribers << ActiveSupport::Notifications.subscribe(key, self) }
         | 
| 20 18 | 
             
                end
         | 
| 21 19 |  | 
| 22 20 | 
             
                def unregister!
         | 
| @@ -74,37 +72,37 @@ module Skylight | |
| 74 72 |  | 
| 75 73 | 
             
                private
         | 
| 76 74 |  | 
| 77 | 
            -
             | 
| 78 | 
            -
             | 
| 79 | 
            -
             | 
| 80 | 
            -
             | 
| 81 | 
            -
                  def normalize_after(*args)
         | 
| 82 | 
            -
                    @normalizers.normalize_after(*args)
         | 
| 83 | 
            -
                  end
         | 
| 75 | 
            +
                def normalize(*args)
         | 
| 76 | 
            +
                  @normalizers.normalize(*args)
         | 
| 77 | 
            +
                end
         | 
| 84 78 |  | 
| 85 | 
            -
             | 
| 86 | 
            -
             | 
| 79 | 
            +
                def normalize_after(*args)
         | 
| 80 | 
            +
                  @normalizers.normalize_after(*args)
         | 
| 81 | 
            +
                end
         | 
| 87 82 |  | 
| 88 | 
            -
             | 
| 89 | 
            -
             | 
| 90 | 
            -
                      when 3, 4
         | 
| 91 | 
            -
                        cat, title, desc, meta = result
         | 
| 92 | 
            -
                      else
         | 
| 93 | 
            -
                        raise "Invalid normalizer result: #{result.inspect}"
         | 
| 94 | 
            -
                      end
         | 
| 83 | 
            +
                def _start(trace, name, payload)
         | 
| 84 | 
            +
                  result = normalize(trace, name, payload)
         | 
| 95 85 |  | 
| 96 | 
            -
             | 
| 86 | 
            +
                  unless result == :skip
         | 
| 87 | 
            +
                    case result.size
         | 
| 88 | 
            +
                    when 3, 4
         | 
| 89 | 
            +
                      cat, title, desc, meta = result
         | 
| 90 | 
            +
                    else
         | 
| 91 | 
            +
                      raise "Invalid normalizer result: #{result.inspect}"
         | 
| 97 92 | 
             
                    end
         | 
| 98 | 
            -
             | 
| 99 | 
            -
                     | 
| 100 | 
            -
                    debug "trace=%s", trace.inspect
         | 
| 101 | 
            -
                    debug "in:  name=%s", name.inspect
         | 
| 102 | 
            -
                    debug "in:  payload=%s", payload.inspect
         | 
| 103 | 
            -
                    debug "out: cat=%s, title=%s, desc=%s", cat.inspect, name.inspect, desc.inspect
         | 
| 104 | 
            -
                    t { e.backtrace.join("\n") }
         | 
| 105 | 
            -
                    nil
         | 
| 106 | 
            -
                  ensure
         | 
| 107 | 
            -
                    trace.notifications << Notification.new(name, span)
         | 
| 93 | 
            +
             | 
| 94 | 
            +
                    span = trace.instrument(cat, title, desc, meta)
         | 
| 108 95 | 
             
                  end
         | 
| 96 | 
            +
                rescue Exception => e
         | 
| 97 | 
            +
                  error "Subscriber#start error; msg=%s", e.message
         | 
| 98 | 
            +
                  debug "trace=%s", trace.inspect
         | 
| 99 | 
            +
                  debug "in:  name=%s", name.inspect
         | 
| 100 | 
            +
                  debug "in:  payload=%s", payload.inspect
         | 
| 101 | 
            +
                  debug "out: cat=%s, title=%s, desc=%s", cat.inspect, name.inspect, desc.inspect
         | 
| 102 | 
            +
                  t { e.backtrace.join("\n") }
         | 
| 103 | 
            +
                  nil
         | 
| 104 | 
            +
                ensure
         | 
| 105 | 
            +
                  trace.notifications << Notification.new(name, span)
         | 
| 106 | 
            +
                end
         | 
| 109 107 | 
             
              end
         | 
| 110 108 | 
             
            end
         |