sqreen 1.20.4-java → 1.21.0.beta3-java
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 +15 -24
- data/lib/sqreen/condition_evaluator.rb +6 -5
- data/lib/sqreen/conditionable.rb +24 -6
- data/lib/sqreen/deliveries/batch.rb +8 -1
- data/lib/sqreen/ecosystem/dispatch_table.rb +43 -0
- data/lib/sqreen/ecosystem/exception_reporting.rb +26 -0
- data/lib/sqreen/ecosystem/http/net_http.rb +50 -0
- data/lib/sqreen/ecosystem/http/rack_request.rb +39 -0
- data/lib/sqreen/ecosystem/loggable.rb +13 -0
- data/lib/sqreen/ecosystem/module_api/event_listener.rb +18 -0
- data/lib/sqreen/ecosystem/module_api/instrumentation.rb +23 -0
- data/lib/sqreen/ecosystem/module_api/message_producer.rb +51 -0
- data/lib/sqreen/ecosystem/module_api/signal_producer.rb +24 -0
- data/lib/sqreen/ecosystem/module_api/tracing/client_data.rb +31 -0
- data/lib/sqreen/ecosystem/module_api/tracing/server_data.rb +27 -0
- data/lib/sqreen/ecosystem/module_api/tracing.rb +45 -0
- data/lib/sqreen/ecosystem/module_api/tracing_id_generation.rb +16 -0
- data/lib/sqreen/ecosystem/module_api/transaction_storage.rb +71 -0
- data/lib/sqreen/ecosystem/module_api.rb +30 -0
- data/lib/sqreen/ecosystem/module_registry.rb +44 -0
- data/lib/sqreen/ecosystem/redis/redis_connection.rb +43 -0
- data/lib/sqreen/ecosystem/tracing/modules/client.rb +31 -0
- data/lib/sqreen/ecosystem/tracing/modules/server.rb +30 -0
- data/lib/sqreen/ecosystem/tracing/sampler.rb +160 -0
- data/lib/sqreen/ecosystem/tracing/sampling_configuration.rb +150 -0
- data/lib/sqreen/ecosystem/tracing/signals/tracing_client.rb +53 -0
- data/lib/sqreen/ecosystem/tracing/signals/tracing_server.rb +53 -0
- data/lib/sqreen/ecosystem/tracing_broker.rb +101 -0
- data/lib/sqreen/ecosystem/tracing_id_setup.rb +34 -0
- data/lib/sqreen/ecosystem/transaction_storage.rb +64 -0
- data/lib/sqreen/ecosystem/util/call_writers_from_init.rb +13 -0
- data/lib/sqreen/ecosystem.rb +96 -0
- data/lib/sqreen/ecosystem_integration/around_callbacks.rb +99 -0
- data/lib/sqreen/ecosystem_integration/instrumentation_service.rb +42 -0
- data/lib/sqreen/ecosystem_integration/request_lifecycle_tracking.rb +58 -0
- data/lib/sqreen/ecosystem_integration/signal_consumption.rb +35 -0
- data/lib/sqreen/ecosystem_integration.rb +87 -0
- data/lib/sqreen/frameworks/generic.rb +15 -1
- data/lib/sqreen/graft/call.rb +30 -1
- data/lib/sqreen/graft/hook.rb +88 -78
- data/lib/sqreen/graft/hook_point.rb +17 -10
- data/lib/sqreen/legacy/old_event_submission_strategy.rb +7 -1
- data/lib/sqreen/metrics/req_detailed.rb +41 -0
- data/lib/sqreen/metrics.rb +1 -0
- data/lib/sqreen/remote_command.rb +3 -0
- data/lib/sqreen/rules/rule_cb.rb +2 -2
- data/lib/sqreen/runner.rb +44 -15
- data/lib/sqreen/session.rb +2 -0
- data/lib/sqreen/signals/conversions.rb +6 -1
- data/lib/sqreen/version.rb +1 -1
- data/lib/sqreen/weave/budget.rb +3 -14
- data/lib/sqreen/weave/legacy/instrumentation.rb +145 -94
- metadata +41 -5
    
        data/lib/sqreen/weave/budget.rb
    CHANGED
    
    | @@ -9,24 +9,14 @@ require 'sqreen/weave' | |
| 9 9 | 
             
            class Sqreen::Weave::Budget
         | 
| 10 10 | 
             
              include Sqreen::Log::Loggable
         | 
| 11 11 |  | 
| 12 | 
            -
              def initialize(threshold | 
| 12 | 
            +
              def initialize(threshold)
         | 
| 13 13 | 
             
                @threshold = threshold
         | 
| 14 | 
            -
                @ratio = ratio
         | 
| 15 | 
            -
              end
         | 
| 16 | 
            -
             | 
| 17 | 
            -
              def static?
         | 
| 18 | 
            -
                threshold && !ratio
         | 
| 19 | 
            -
              end
         | 
| 20 | 
            -
             | 
| 21 | 
            -
              def dynamic?
         | 
| 22 | 
            -
                threshold && ratio
         | 
| 23 14 | 
             
              end
         | 
| 24 15 |  | 
| 25 16 | 
             
              attr_reader :threshold
         | 
| 26 | 
            -
              attr_reader :ratio
         | 
| 27 17 |  | 
| 28 18 | 
             
              def to_h
         | 
| 29 | 
            -
                { threshold: threshold | 
| 19 | 
            +
                { threshold: threshold }
         | 
| 30 20 | 
             
              end
         | 
| 31 21 |  | 
| 32 22 | 
             
              class << self
         | 
| @@ -38,9 +28,8 @@ class Sqreen::Weave::Budget | |
| 38 28 | 
             
                  return @current = nil if opts.nil? || opts.empty?
         | 
| 39 29 |  | 
| 40 30 | 
             
                  threshold = opts[:threshold]
         | 
| 41 | 
            -
                  ratio = opts[:ratio]
         | 
| 42 31 |  | 
| 43 | 
            -
                  @current =  | 
| 32 | 
            +
                  @current = threshold
         | 
| 44 33 | 
             
                end
         | 
| 45 34 | 
             
              end
         | 
| 46 35 | 
             
            end
         | 
| @@ -11,19 +11,34 @@ require 'sqreen/call_countable' | |
| 11 11 | 
             
            require 'sqreen/rules'
         | 
| 12 12 | 
             
            require 'sqreen/rules/record_request_context'
         | 
| 13 13 | 
             
            require 'sqreen/sqreen_signed_verifier'
         | 
| 14 | 
            +
            require 'rack/request'
         | 
| 15 | 
            +
            begin
         | 
| 16 | 
            +
              require 'sq_detailed_metrics'
         | 
| 17 | 
            +
            rescue LoadError => _e # rubocop:disable Lint/HandleExceptions
         | 
| 18 | 
            +
            end
         | 
| 14 19 |  | 
| 15 20 | 
             
            class Sqreen::Weave::Legacy::Instrumentation
         | 
| 16 21 | 
             
              attr_accessor :metrics_engine
         | 
| 17 22 |  | 
| 23 | 
            +
              HAS_SQ_DETAILED_METRICS = defined?(::SqDetailedMetrics)
         | 
| 24 | 
            +
              REQ_LVL_2_METRIC = 'request_level_perf'.freeze
         | 
| 25 | 
            +
             | 
| 18 26 | 
             
              def initialize(metrics_engine, opts = {})
         | 
| 19 27 | 
             
                Sqreen::Weave.logger.debug { "#{self.class.name}#initialize #{metrics_engine}" }
         | 
| 20 28 | 
             
                @hooks = []
         | 
| 21 29 |  | 
| 30 | 
            +
                unless HAS_SQ_DETAILED_METRICS
         | 
| 31 | 
            +
                  Sqreen::Weave.logger.warn { "Detailed metrics are unavailable" }
         | 
| 32 | 
            +
                end
         | 
| 33 | 
            +
             | 
| 22 34 | 
             
                self.metrics_engine = metrics_engine
         | 
| 23 35 |  | 
| 24 36 | 
             
                ### bail out if no metric engine
         | 
| 25 37 | 
             
                return if metrics_engine.nil?
         | 
| 26 38 |  | 
| 39 | 
            +
                # XXX: these metric definitions do not support change of opts
         | 
| 40 | 
            +
                #      due to features updates!
         | 
| 41 | 
            +
             | 
| 27 42 | 
             
                ### init metric to count calls to sqreen
         | 
| 28 43 | 
             
                metrics_engine.create_metric(
         | 
| 29 44 | 
             
                  'name' => 'sqreen_call_counts',
         | 
| @@ -90,6 +105,15 @@ class Sqreen::Weave::Legacy::Instrumentation | |
| 90 105 | 
             
                  'kind' => 'Binning',
         | 
| 91 106 | 
             
                  'options' => opts[:perf_metric_percent] || { 'base' => 1.3, 'factor' => 1.0 },
         | 
| 92 107 | 
             
                )
         | 
| 108 | 
            +
             | 
| 109 | 
            +
                if HAS_SQ_DETAILED_METRICS # rubocop:disable Style/GuardClause
         | 
| 110 | 
            +
                  @lvl_2_metric = metrics_engine.create_metric(
         | 
| 111 | 
            +
                    'name' => REQ_LVL_2_METRIC,
         | 
| 112 | 
            +
                    'period' => opts[:perf_req_metrics_period] || 60,
         | 
| 113 | 
            +
                    'kind' => 'ReqDetailed',
         | 
| 114 | 
            +
                  )
         | 
| 115 | 
            +
                  @lvl_2_max_reqs = opts[:perf_req_metrics_max_reqs] || 100
         | 
| 116 | 
            +
                end
         | 
| 93 117 | 
             
              end
         | 
| 94 118 |  | 
| 95 119 | 
             
              # needed by Sqreen::Runner#initialize
         | 
| @@ -159,11 +183,13 @@ class Sqreen::Weave::Legacy::Instrumentation | |
| 159 183 | 
             
                end
         | 
| 160 184 |  | 
| 161 185 | 
             
                metrics_engine = self.metrics_engine
         | 
| 186 | 
            +
                lvl_2_metric = @lvl_2_metric
         | 
| 187 | 
            +
                lvl_2_max_reqs = @lvl_2_max_reqs
         | 
| 162 188 |  | 
| 163 189 | 
             
                request_hook = Sqreen::Graft::Hook['Sqreen::ShrinkWrap#call', strategy]
         | 
| 164 190 | 
             
                @hooks << request_hook
         | 
| 165 191 | 
             
                request_hook.add do
         | 
| 166 | 
            -
                  before('wave,meta,request', rank: -100000, mandatory: true) do | | 
| 192 | 
            +
                  before('wave,meta,request', rank: -100000, mandatory: true) do |call|
         | 
| 167 193 | 
             
                    next unless Sqreen.instrumentation_ready
         | 
| 168 194 |  | 
| 169 195 | 
             
                    # shrinkwrap_timer = Sqreen::Graft::Timer.new('weave,shrinkwrap')
         | 
| @@ -173,25 +199,42 @@ class Sqreen::Weave::Legacy::Instrumentation | |
| 173 199 | 
             
                    request_timer.start
         | 
| 174 200 | 
             
                    sqreen_timer = Sqreen::Graft::Timer.new("sqreen")
         | 
| 175 201 | 
             
                    budget = Sqreen::Weave::Budget.current
         | 
| 176 | 
            -
             | 
| 177 | 
            -
                    request_budget_ratio = budget.ratio if budget
         | 
| 178 | 
            -
                    request_budget_is_dynamic = !request_budget_ratio.nil?
         | 
| 179 | 
            -
                    request_budget = !request_budget_threshold.nil?
         | 
| 202 | 
            +
             | 
| 180 203 | 
             
                    timed_level = (Sqreen.features['perf_level'] || 1).to_i
         | 
| 181 | 
            -
                     | 
| 204 | 
            +
                    timed_level = 1 if !HAS_SQ_DETAILED_METRICS && timed_level == 2
         | 
| 205 | 
            +
                    if timed_level == 2 && lvl_2_metric.num_requests >= lvl_2_max_reqs
         | 
| 206 | 
            +
                      timed_level = 1
         | 
| 207 | 
            +
                      Sqreen::Weave.logger.debug { "Reducing timed level to 1 (#{lvl_2_metric.num_requests} reqs accumulated)" }
         | 
| 208 | 
            +
                    end
         | 
| 209 | 
            +
             | 
| 210 | 
            +
                    Sqreen::Weave.logger.debug { "request budget: #{budget} timed.level: #{timed_level}" } if Sqreen::Weave.logger.debug?
         | 
| 211 | 
            +
             | 
| 212 | 
            +
                    route_found = nil
         | 
| 213 | 
            +
                    if timed_level >= 2
         | 
| 214 | 
            +
                      rack_env, = call.args
         | 
| 215 | 
            +
                      rack_request = Rack::Request.new(rack_env) if rack_env
         | 
| 216 | 
            +
             | 
| 217 | 
            +
                      # TODO: Rails engines
         | 
| 218 | 
            +
                      # TODO: Struct
         | 
| 219 | 
            +
                      # TODO: Sinatra
         | 
| 220 | 
            +
                      # TODO: Rack?
         | 
| 221 | 
            +
                      Rails.application.routes.router.recognize(rack_request) do |route, params|
         | 
| 222 | 
            +
                        route = ActionDispatch::Routing::RouteWrapper.new(route)
         | 
| 223 | 
            +
                        route_found = { name: route.name, verb: route.verb, path: route.path, reqs: route.reqs, params: params }
         | 
| 224 | 
            +
                      end if defined?(Rails) && Rails.application && defined?(ActionDispatch::Routing::RouteWrapper)
         | 
| 225 | 
            +
                    end
         | 
| 182 226 |  | 
| 227 | 
            +
                    # TODO: Struct
         | 
| 183 228 | 
             
                    Thread.current[:sqreen_http_request] = {
         | 
| 184 229 | 
             
                      request_timer: request_timer,
         | 
| 185 230 | 
             
                      sqreen_timer: sqreen_timer,
         | 
| 186 231 | 
             
                      time_budget_expended: false,
         | 
| 187 | 
            -
                       | 
| 188 | 
            -
                      time_budget_dynamic: request_budget_is_dynamic,
         | 
| 189 | 
            -
                      time_budget_ratio: request_budget_ratio,
         | 
| 190 | 
            -
                      time_budget: request_budget,
         | 
| 232 | 
            +
                      time_budget: budget,
         | 
| 191 233 | 
             
                      timed_callbacks: [],
         | 
| 192 234 | 
             
                      timed_hooks: [],
         | 
| 193 235 | 
             
                      timed_level: timed_level,
         | 
| 194 236 | 
             
                      skipped_callbacks: [],
         | 
| 237 | 
            +
                      route: ("#{route_found[:verb]} #{route_found[:path]}" if route_found),
         | 
| 195 238 | 
             
                      # timed_shrinkwrap: shrinkwrap_timer,
         | 
| 196 239 | 
             
                    }
         | 
| 197 240 |  | 
| @@ -203,6 +246,9 @@ class Sqreen::Weave::Legacy::Instrumentation | |
| 203 246 |  | 
| 204 247 | 
             
                    next if request.nil?
         | 
| 205 248 |  | 
| 249 | 
            +
                    timed_level = request[:timed_level]
         | 
| 250 | 
            +
                    req_detailed = SqDetailedMetrics::Request.new if timed_level >= 2
         | 
| 251 | 
            +
             | 
| 206 252 | 
             
                    # shrinkwrap_timer = request[:timed_shrinkwrap]
         | 
| 207 253 | 
             
                    # shrinkwrap_timer.start
         | 
| 208 254 |  | 
| @@ -210,39 +256,30 @@ class Sqreen::Weave::Legacy::Instrumentation | |
| 210 256 | 
             
                    request_timer = request[:request_timer]
         | 
| 211 257 | 
             
                    now = request_timer.stop
         | 
| 212 258 |  | 
| 213 | 
            -
                    if  | 
| 259 | 
            +
                    if timed_level >= 1
         | 
| 214 260 | 
             
                      request[:timed_callbacks].each do |timer|
         | 
| 215 | 
            -
                         | 
| 216 | 
            -
             | 
| 217 | 
            -
                         | 
| 218 | 
            -
                         | 
| 219 | 
            -
             | 
| 220 | 
            -
                        whence = case timer.tag
         | 
| 221 | 
            -
                                 when /@before/ then 'pre'
         | 
| 222 | 
            -
                                 when /@after/  then 'post'
         | 
| 223 | 
            -
                                 when /@raised/ then 'failing'
         | 
| 224 | 
            -
                                 end
         | 
| 225 | 
            -
                        next unless whence
         | 
| 261 | 
            +
                        duration_ms = timer.duration * 1000.0
         | 
| 262 | 
            +
                        # XXX: the timer tag should have this structured data;
         | 
| 263 | 
            +
                        # it would be better than recomputing this for every measurement
         | 
| 264 | 
            +
                        metric_name = ::Sqreen::Weave::Legacy::Instrumentation.tag_to_metric_name(timer.tag)
         | 
| 226 265 |  | 
| 227 | 
            -
                         | 
| 228 | 
            -
                        metrics_engine.update(metric_name, now, nil, duration * 1000)
         | 
| 229 | 
            -
                        # Sqreen.observations_queue.push([metric_name, nil, duration * 1000, utc_now])
         | 
| 230 | 
            -
                      end
         | 
| 266 | 
            +
                        next unless metric_name
         | 
| 231 267 |  | 
| 232 | 
            -
             | 
| 233 | 
            -
                         | 
| 234 | 
            -
                         | 
| 235 | 
            -
                        # Sqreen.observations_queue.push(['sq.hook.overhead', nil, duration * 1000, utc_now])
         | 
| 268 | 
            +
                        metrics_engine.update(metric_name, now, nil, duration_ms)
         | 
| 269 | 
            +
                        duration_ms *= -1.0 if timer.conditions_passed
         | 
| 270 | 
            +
                        req_detailed.add_measurement metric_name, duration_ms if req_detailed
         | 
| 236 271 | 
             
                      end
         | 
| 237 272 | 
             
                    end
         | 
| 238 273 |  | 
| 239 274 | 
             
                    sqreen_timer = request[:sqreen_timer]
         | 
| 240 | 
            -
                     | 
| 241 | 
            -
             | 
| 242 | 
            -
                     | 
| 243 | 
            -
                    Sqreen::Weave.logger.debug  | 
| 244 | 
            -
             | 
| 245 | 
            -
                    if  | 
| 275 | 
            +
                    Sqreen::Weave.logger.debug do
         | 
| 276 | 
            +
                      "request sqreen_timer.total: #{'%.03fus' % (sqreen_timer.duration * 1_000_000)}"
         | 
| 277 | 
            +
                    end if Sqreen::Weave.logger.debug?
         | 
| 278 | 
            +
                    Sqreen::Weave.logger.debug do
         | 
| 279 | 
            +
                      "request request_timer.total: #{'%.03fus' % (request_timer.duration * 1_000_000)}"
         | 
| 280 | 
            +
                    end if Sqreen::Weave.logger.debug?
         | 
| 281 | 
            +
             | 
| 282 | 
            +
                    if timed_level >= 1 && Sqreen::Weave.logger.debug?
         | 
| 246 283 | 
             
                      skipped = request[:skipped_callbacks].map(&:name)
         | 
| 247 284 | 
             
                      Sqreen::Weave.logger.debug { "request callback.skipped.count: #{skipped.count}" } if Sqreen::Weave.logger.debug?
         | 
| 248 285 | 
             
                      timings = request[:timed_callbacks].map(&:to_s)
         | 
| @@ -253,50 +290,27 @@ class Sqreen::Weave::Legacy::Instrumentation | |
| 253 290 | 
             
                      Sqreen::Weave.logger.debug { "request hook.total: #{'%.03fus' % (total * 1_000_000)} hook.count: #{timings.count}" } if Sqreen::Weave.logger.debug?
         | 
| 254 291 | 
             
                    end
         | 
| 255 292 |  | 
| 256 | 
            -
                     | 
| 257 | 
            -
             | 
| 258 | 
            -
                    metrics_engine.update('request_overtime', now,  | 
| 259 | 
            -
                    # Sqreen.observations_queue.push(['request_overtime', skipped_rule_name, 1, utc_now]) if skipped_rule_name
         | 
| 293 | 
            +
                    overtime_cb = ::Sqreen::Weave::Legacy::Instrumentation.tag_to_metric_name(request[:overtime_cb]) \
         | 
| 294 | 
            +
                                  if request[:overtime_cb]
         | 
| 295 | 
            +
                    metrics_engine.update('request_overtime', now, overtime_cb, 1) if overtime_cb
         | 
| 260 296 |  | 
| 261 | 
            -
                    sqreen_request_duration = sqreen_timer.duration
         | 
| 262 | 
            -
                    metrics_engine.update('sq', now, nil, sqreen_request_duration | 
| 263 | 
            -
                    # Sqreen.observations_queue.push(['sq', nil, sqreen_request_duration * 1000, utc_now])
         | 
| 297 | 
            +
                    sqreen_request_duration = sqreen_timer.duration * 1000.0
         | 
| 298 | 
            +
                    metrics_engine.update('sq', now, nil, sqreen_request_duration)
         | 
| 264 299 |  | 
| 265 | 
            -
                    request_duration = request_timer.duration
         | 
| 266 | 
            -
                    metrics_engine.update('req', now, nil, request_duration | 
| 267 | 
            -
                    # Sqreen.observations_queue.push(['req', nil, request_duration * 1000, utc_now])
         | 
| 300 | 
            +
                    request_duration = request_timer.duration * 1000.0
         | 
| 301 | 
            +
                    metrics_engine.update('req', now, nil, request_duration)
         | 
| 268 302 |  | 
| 269 303 | 
             
                    sqreen_request_ratio = (sqreen_request_duration * 100.0) / (request_duration - sqreen_request_duration)
         | 
| 270 304 | 
             
                    metrics_engine.update('pct', now, nil, sqreen_request_ratio)
         | 
| 271 | 
            -
                    # Sqreen.observations_queue.push(['pct', nil, sqreen_request_ratio, utc_now])
         | 
| 272 305 | 
             
                    Sqreen::Weave.logger.debug { "request sqreen_timer.ratio: #{'%.03f' % (sqreen_request_ratio / 100.0)}" } if Sqreen::Weave.logger.debug?
         | 
| 273 306 |  | 
| 274 | 
            -
                    if  | 
| 275 | 
            -
                       | 
| 276 | 
            -
                       | 
| 277 | 
            -
             | 
| 278 | 
            -
             | 
| 279 | 
            -
                        timer.tag =~ /weave,rule=(.*)$/ && rule = $1
         | 
| 280 | 
            -
                        next unless rule
         | 
| 281 | 
            -
             | 
| 282 | 
            -
                        whence = case timer.tag
         | 
| 283 | 
            -
                                 when /@before/ then 'pre'
         | 
| 284 | 
            -
                                 when /@after/  then 'post'
         | 
| 285 | 
            -
                                 when /@raised/ then 'failing'
         | 
| 286 | 
            -
                                 end
         | 
| 287 | 
            -
                        next unless whence
         | 
| 288 | 
            -
             | 
| 289 | 
            -
                        metric_name = "req.sq.#{rule}.#{whence}"
         | 
| 290 | 
            -
                        tallies[metric_name] += duration
         | 
| 291 | 
            -
                      end
         | 
| 292 | 
            -
                      tallies.each do |metric_name, duration|
         | 
| 293 | 
            -
                        metrics_engine.update(metric_name, now, nil, duration * 1000)
         | 
| 294 | 
            -
                        # Sqreen.observations_queue.push([metric_name, nil, duration * 1000, utc_now])
         | 
| 295 | 
            -
                      end
         | 
| 307 | 
            +
                    if req_detailed
         | 
| 308 | 
            +
                      req_detailed.route = request[:route]
         | 
| 309 | 
            +
                      req_detailed.overtime_cb = overtime_cb if overtime_cb
         | 
| 310 | 
            +
                      req_detailed.add_measurement 'sq', sqreen_request_duration
         | 
| 311 | 
            +
                      req_detailed.add_measurement 'req', request_duration
         | 
| 296 312 |  | 
| 297 | 
            -
                       | 
| 298 | 
            -
                      metrics_engine.update('req.sq.hook.overhead', now, nil, duration * 1000)
         | 
| 299 | 
            -
                      # Sqreen.observations_queue.push(['req.sq.hook.overhead', nil, duration * 1000, utc_now])
         | 
| 313 | 
            +
                      metrics_engine.update(REQ_LVL_2_METRIC, now, nil, req_detailed)
         | 
| 300 314 | 
             
                    end
         | 
| 301 315 |  | 
| 302 316 | 
             
                    # shrinkwrap_timer.stop
         | 
| @@ -355,7 +369,8 @@ class Sqreen::Weave::Legacy::Instrumentation | |
| 355 369 | 
             
                hook = Sqreen::Graft::Hook[hook_point, strategy]
         | 
| 356 370 | 
             
                hook.add do
         | 
| 357 371 | 
             
                  if callback.pre?
         | 
| 358 | 
            -
                     | 
| 372 | 
            +
                    use_flow = block || callback.is_a?(::Sqreen::Conditionable)
         | 
| 373 | 
            +
                    before(rule, rank: priority, mandatory: !callback.overtimeable, flow: use_flow, ignore: ignore) do |call, b|
         | 
| 359 374 | 
             
                      next unless Thread.current[:sqreen_http_request]
         | 
| 360 375 |  | 
| 361 376 | 
             
                      i = call.instance
         | 
| @@ -387,8 +402,12 @@ class Sqreen::Weave::Legacy::Instrumentation | |
| 387 402 | 
             
                          else
         | 
| 388 403 | 
             
                            b.raise(Sqreen::AttackBlocked.new("Sqreen blocked a security threat (type: #{callback.rule_name}). No action is required."))
         | 
| 389 404 | 
             
                          end
         | 
| 390 | 
            -
                        end
         | 
| 405 | 
            +
                        end if block
         | 
| 391 406 |  | 
| 407 | 
            +
                      if ret && ret[:passed_conditions]
         | 
| 408 | 
            +
                        throw_val ||= b.noop
         | 
| 409 | 
            +
                        throw_val.passed_conditions!
         | 
| 410 | 
            +
                      end
         | 
| 392 411 | 
             
                      next unless throw_val
         | 
| 393 412 | 
             
                      throw_val.break! if ret[:skip_rem_cbs]
         | 
| 394 413 | 
             
                      throw(b, throw_val)
         | 
| @@ -415,13 +434,21 @@ class Sqreen::Weave::Legacy::Instrumentation | |
| 415 434 | 
             
                        end
         | 
| 416 435 | 
             
                      end
         | 
| 417 436 |  | 
| 418 | 
            -
                       | 
| 419 | 
            -
             | 
| 420 | 
            -
                         | 
| 421 | 
            -
             | 
| 422 | 
            -
                         | 
| 423 | 
            -
             | 
| 424 | 
            -
             | 
| 437 | 
            +
                      throw_val =
         | 
| 438 | 
            +
                        case ret[:status]
         | 
| 439 | 
            +
                        when :override, 'override'
         | 
| 440 | 
            +
                          b.return(ret[:new_return_value]) if ret.key?(:new_return_value)
         | 
| 441 | 
            +
                        when :raise, 'raise'
         | 
| 442 | 
            +
                          b.raise(ret[:exception]) if ret.key?(:exception)
         | 
| 443 | 
            +
                          b.raise(Sqreen::AttackBlocked.new("Sqreen blocked a security threat (type: #{callback.rule_name}). No action is required."))
         | 
| 444 | 
            +
                        end unless ret.nil? || !ret.is_a?(Hash) || !block
         | 
| 445 | 
            +
             | 
| 446 | 
            +
                      if ret && ret[:passed_conditions]
         | 
| 447 | 
            +
                        throw_val ||= b.noop
         | 
| 448 | 
            +
                        throw_val.passed_conditions!
         | 
| 449 | 
            +
                      end
         | 
| 450 | 
            +
                      next unless throw_val
         | 
| 451 | 
            +
                      throw(b, throw_val)
         | 
| 425 452 | 
             
                    end
         | 
| 426 453 | 
             
                  end
         | 
| 427 454 |  | 
| @@ -447,19 +474,27 @@ class Sqreen::Weave::Legacy::Instrumentation | |
| 447 474 |  | 
| 448 475 | 
             
                      throw(b, b.raise(e)) if ret.nil? || !ret.is_a?(Hash)
         | 
| 449 476 |  | 
| 450 | 
            -
                       | 
| 451 | 
            -
             | 
| 452 | 
            -
                         | 
| 453 | 
            -
             | 
| 454 | 
            -
                         | 
| 455 | 
            -
             | 
| 456 | 
            -
                         | 
| 457 | 
            -
             | 
| 458 | 
            -
             | 
| 459 | 
            -
                         | 
| 460 | 
            -
             | 
| 461 | 
            -
                         | 
| 462 | 
            -
             | 
| 477 | 
            +
                      throw_val =
         | 
| 478 | 
            +
                        case ret[:status]
         | 
| 479 | 
            +
                        when :override, 'override'
         | 
| 480 | 
            +
                          b.return(ret[:new_return_value]) if ret.key?(:new_return_value)
         | 
| 481 | 
            +
                        when :retry, 'retry'
         | 
| 482 | 
            +
                          b.retry
         | 
| 483 | 
            +
                        when :raise, 'raise'
         | 
| 484 | 
            +
                          b.raise(ret[:exception]) if ret.key?(:exception)
         | 
| 485 | 
            +
                          b.raise(Sqreen::AttackBlocked.new("Sqreen blocked a security threat (type: #{callback.rule_name}). No action is required."))
         | 
| 486 | 
            +
                        when :reraise, 'reraise'
         | 
| 487 | 
            +
                          b.raise(e)
         | 
| 488 | 
            +
                        else
         | 
| 489 | 
            +
                          b.raise(e)
         | 
| 490 | 
            +
                        end unless ret.nil? || !ret.is_a?(Hash) || !block
         | 
| 491 | 
            +
             | 
| 492 | 
            +
                      if ret && ret[:passed_conditions]
         | 
| 493 | 
            +
                        throw_val ||= b.noop
         | 
| 494 | 
            +
                        throw_val.passed_conditions!
         | 
| 495 | 
            +
                      end
         | 
| 496 | 
            +
                      next unless throw_val
         | 
| 497 | 
            +
                      throw(b, throw_val)
         | 
| 463 498 | 
             
                    end
         | 
| 464 499 | 
             
                  end
         | 
| 465 500 | 
             
                end.install
         | 
| @@ -494,4 +529,20 @@ class Sqreen::Weave::Legacy::Instrumentation | |
| 494 529 | 
             
                  Sqreen::Rules::RunUserActions.new(Sqreen, :auth_track, 1),
         | 
| 495 530 | 
             
                ]
         | 
| 496 531 | 
             
              end
         | 
| 532 | 
            +
             | 
| 533 | 
            +
              def self.tag_to_metric_name(tag)
         | 
| 534 | 
            +
                cached = @cache_tag_to_metric[tag]
         | 
| 535 | 
            +
                return cached unless cached.nil?
         | 
| 536 | 
            +
             | 
| 537 | 
            +
                tag =~ /weave,rule=(.*)$/ && rule = $1 and # rubocop:disable Style/AndOr
         | 
| 538 | 
            +
                  (tag =~ /@before/ && whence = 'pre' or # rubocop:disable Style/AndOr
         | 
| 539 | 
            +
                    tag =~ /@after/  && whence = 'post' or # rubocop:disable Style/AndOr
         | 
| 540 | 
            +
                    tag =~ /@raised/ && whence = 'failing' or # rubocop:disable Style/AndOr
         | 
| 541 | 
            +
                    tag =~ /@ensured/ && whence = 'finally')
         | 
| 542 | 
            +
             | 
| 543 | 
            +
                @cache_tag_to_metric[tag] =
         | 
| 544 | 
            +
                  rule && whence ? "sq.#{rule}.#{whence}" : false
         | 
| 545 | 
            +
              end
         | 
| 546 | 
            +
             | 
| 547 | 
            +
              @cache_tag_to_metric = {}
         | 
| 497 548 | 
             
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: sqreen
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 1. | 
| 4 | 
            +
              version: 1.21.0.beta3
         | 
| 5 5 | 
             
            platform: java
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Sqreen
         | 
| 8 8 | 
             
            autorequire:
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2020-09- | 
| 11 | 
            +
            date: 2020-09-14 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| @@ -123,6 +123,39 @@ files: | |
| 123 123 | 
             
            - lib/sqreen/dependency/sentry.rb
         | 
| 124 124 | 
             
            - lib/sqreen/dependency/sinatra.rb
         | 
| 125 125 | 
             
            - lib/sqreen/deprecation.rb
         | 
| 126 | 
            +
            - lib/sqreen/ecosystem.rb
         | 
| 127 | 
            +
            - lib/sqreen/ecosystem/dispatch_table.rb
         | 
| 128 | 
            +
            - lib/sqreen/ecosystem/exception_reporting.rb
         | 
| 129 | 
            +
            - lib/sqreen/ecosystem/http/net_http.rb
         | 
| 130 | 
            +
            - lib/sqreen/ecosystem/http/rack_request.rb
         | 
| 131 | 
            +
            - lib/sqreen/ecosystem/loggable.rb
         | 
| 132 | 
            +
            - lib/sqreen/ecosystem/module_api.rb
         | 
| 133 | 
            +
            - lib/sqreen/ecosystem/module_api/event_listener.rb
         | 
| 134 | 
            +
            - lib/sqreen/ecosystem/module_api/instrumentation.rb
         | 
| 135 | 
            +
            - lib/sqreen/ecosystem/module_api/message_producer.rb
         | 
| 136 | 
            +
            - lib/sqreen/ecosystem/module_api/signal_producer.rb
         | 
| 137 | 
            +
            - lib/sqreen/ecosystem/module_api/tracing.rb
         | 
| 138 | 
            +
            - lib/sqreen/ecosystem/module_api/tracing/client_data.rb
         | 
| 139 | 
            +
            - lib/sqreen/ecosystem/module_api/tracing/server_data.rb
         | 
| 140 | 
            +
            - lib/sqreen/ecosystem/module_api/tracing_id_generation.rb
         | 
| 141 | 
            +
            - lib/sqreen/ecosystem/module_api/transaction_storage.rb
         | 
| 142 | 
            +
            - lib/sqreen/ecosystem/module_registry.rb
         | 
| 143 | 
            +
            - lib/sqreen/ecosystem/redis/redis_connection.rb
         | 
| 144 | 
            +
            - lib/sqreen/ecosystem/tracing/modules/client.rb
         | 
| 145 | 
            +
            - lib/sqreen/ecosystem/tracing/modules/server.rb
         | 
| 146 | 
            +
            - lib/sqreen/ecosystem/tracing/sampler.rb
         | 
| 147 | 
            +
            - lib/sqreen/ecosystem/tracing/sampling_configuration.rb
         | 
| 148 | 
            +
            - lib/sqreen/ecosystem/tracing/signals/tracing_client.rb
         | 
| 149 | 
            +
            - lib/sqreen/ecosystem/tracing/signals/tracing_server.rb
         | 
| 150 | 
            +
            - lib/sqreen/ecosystem/tracing_broker.rb
         | 
| 151 | 
            +
            - lib/sqreen/ecosystem/tracing_id_setup.rb
         | 
| 152 | 
            +
            - lib/sqreen/ecosystem/transaction_storage.rb
         | 
| 153 | 
            +
            - lib/sqreen/ecosystem/util/call_writers_from_init.rb
         | 
| 154 | 
            +
            - lib/sqreen/ecosystem_integration.rb
         | 
| 155 | 
            +
            - lib/sqreen/ecosystem_integration/around_callbacks.rb
         | 
| 156 | 
            +
            - lib/sqreen/ecosystem_integration/instrumentation_service.rb
         | 
| 157 | 
            +
            - lib/sqreen/ecosystem_integration/request_lifecycle_tracking.rb
         | 
| 158 | 
            +
            - lib/sqreen/ecosystem_integration/signal_consumption.rb
         | 
| 126 159 | 
             
            - lib/sqreen/endpoint_testing.rb
         | 
| 127 160 | 
             
            - lib/sqreen/error_handling_middleware.rb
         | 
| 128 161 | 
             
            - lib/sqreen/event.rb
         | 
| @@ -175,6 +208,7 @@ files: | |
| 175 208 | 
             
            - lib/sqreen/metrics/base.rb
         | 
| 176 209 | 
             
            - lib/sqreen/metrics/binning.rb
         | 
| 177 210 | 
             
            - lib/sqreen/metrics/collect.rb
         | 
| 211 | 
            +
            - lib/sqreen/metrics/req_detailed.rb
         | 
| 178 212 | 
             
            - lib/sqreen/metrics/sum.rb
         | 
| 179 213 | 
             
            - lib/sqreen/metrics_store.rb
         | 
| 180 214 | 
             
            - lib/sqreen/metrics_store/already_registered_metric.rb
         | 
| @@ -278,7 +312,9 @@ metadata: | |
| 278 312 | 
             
              changelog_uri: https://docs.sqreen.com/ruby/release-notes/
         | 
| 279 313 | 
             
              source_code_uri: https://github.com/sqreen/ruby-agent
         | 
| 280 314 | 
             
              bug_tracker_uri: https://github.com/sqreen/ruby-agent/issues
         | 
| 281 | 
            -
            post_install_message:
         | 
| 315 | 
            +
            post_install_message: |2
         | 
| 316 | 
            +
                  This is a Sqreen beta release and may not work in all situations.
         | 
| 317 | 
            +
                  Make sure to review CHANGELOG.md for important details.
         | 
| 282 318 | 
             
            rdoc_options: []
         | 
| 283 319 | 
             
            require_paths:
         | 
| 284 320 | 
             
            - lib
         | 
| @@ -289,9 +325,9 @@ required_ruby_version: !ruby/object:Gem::Requirement | |
| 289 325 | 
             
                  version: 1.9.3
         | 
| 290 326 | 
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 291 327 | 
             
              requirements:
         | 
| 292 | 
            -
              - - " | 
| 328 | 
            +
              - - ">"
         | 
| 293 329 | 
             
                - !ruby/object:Gem::Version
         | 
| 294 | 
            -
                  version:  | 
| 330 | 
            +
                  version: 1.3.1
         | 
| 295 331 | 
             
            requirements: []
         | 
| 296 332 | 
             
            rubyforge_project:
         | 
| 297 333 | 
             
            rubygems_version: 2.6.14.1
         |