contrast-agent 6.6.0 → 6.6.1

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: b9901918f58625ea7f9366f73110afcdd5f05e119261ba9a08f24f36903fe897
4
- data.tar.gz: c618ebc74b006529e2317cd62ba59fabbba9d0c8fbf24c7988dfd98ec627b04e
3
+ metadata.gz: 0ba6de8e82da25931f2fd6d90f515451c33521c02c0fd00e0120ea05701bdc23
4
+ data.tar.gz: 953297f4f0908bcdcf4791f91869dcf69312f44fe05e743e1e681ce9d3aa9b6f
5
5
  SHA512:
6
- metadata.gz: d2f584a6658ab0e316b41021575888d9ecc1eaacf79d971492fd2e6317609bfd0cb3a762a64d620b08fc18c76e2434d05cc3d82f8d587c86cdae5116df6cae61
7
- data.tar.gz: df8f941fe730188be0bc3b69bd9a9d6d60f9695be8ee8e8eb0b6e35ab1207d97debba28220ff796bec702ad3b158f53f00f87a58f1c14939092ed843bef66715
6
+ metadata.gz: f7e96583d53e23400fd53fd24aed86c728e0d9b8d79a17179cc1bb96a50ad002e047805b10cea0eaa362802c494ff0b45463a16b53a008e9921723cd9e6e43f9
7
+ data.tar.gz: f3c7c2a5b575233f4f8d3e9058b281352133625ab42d50b3c6590c7178728ceda8c494953890a0d50e1413ad5f1e50c04595cc035d5f3ed247611f3a1401095e
@@ -38,19 +38,20 @@ module Contrast
38
38
  # @param ret [Object] the Return of the invoked method
39
39
  # @param args [Array<Object>] the Arguments with which the method was invoked
40
40
  def apply_source method_policy, object, ret, args
41
- return unless analyze?(method_policy, object, ret, args)
42
- return if event_limit?(method_policy)
43
- return unless (source_node = method_policy.source_node)
41
+ logger.trace_with_time('Elapsed time for Contrast::Agent::Assess::Policy::SourceMethod#apply_source') do
42
+ return unless analyze?(method_policy, object, ret, args)
43
+ return if event_limit?(method_policy)
44
+ return unless (source_node = method_policy.source_node)
44
45
 
45
- # used to hold the object and ret
46
- source_data = Contrast::Agent::Assess::Events::EventData.new(nil, nil, object, ret, nil)
46
+ # used to hold the object and ret
47
+ source_data = Contrast::Agent::Assess::Events::EventData.new(nil, nil, object, ret, nil)
47
48
 
48
- return unless (target = determine_target(source_node, source_data, args))
49
- return if target.cs__frozen? && !Contrast::Agent::Assess::Tracker.trackable?(target)
49
+ return unless (target = determine_target(source_node, source_data, args))
50
+ return if target.cs__frozen? && !Contrast::Agent::Assess::Tracker.trackable?(target)
50
51
 
51
- process_source(source_node, target, source_data, source_node.type, nil, *args)
52
+ process_source(source_node, target, source_data, source_node.type, nil, *args)
53
+ end
52
54
  end
53
- Contrast::Components::Logger.add_trace_log_timing_for(SourceMethod, :apply_source)
54
55
 
55
56
  private
56
57
 
@@ -61,13 +61,14 @@ module Contrast
61
61
  # @return [Array,Rack::Response] the Response of this and subsequent Middlewares to be passed back to the user up
62
62
  # the Rack framework.
63
63
  def call env
64
- return app.call(env) unless ::Contrast::AGENT.enabled?
64
+ logger.trace_with_time('Elapsed time for Contrast::Agent::Middleware#call') do
65
+ return app.call(env) unless ::Contrast::AGENT.enabled?
65
66
 
66
- Contrast::Agent.heapdump_util.start_thread!
67
- handle_first_request
68
- call_with_agent(env)
67
+ Contrast::Agent.heapdump_util.start_thread!
68
+ handle_first_request
69
+ call_with_agent(env)
70
+ end
69
71
  end
70
- ::Contrast::Components::Logger.add_trace_log_timing_for(::Contrast::Agent::Middleware, :call)
71
72
 
72
73
  private
73
74
 
@@ -3,6 +3,6 @@
3
3
 
4
4
  module Contrast
5
5
  module Agent
6
- VERSION = '6.6.0'
6
+ VERSION = '6.6.1'
7
7
  end
8
8
  end
@@ -16,16 +16,6 @@ module Contrast
16
16
  def cef_logger
17
17
  @_cef_logger ||= Contrast::Logger::CEFLog.instance.tap(&:build_logger)
18
18
  end
19
-
20
- def add_trace_perf_logging_for sym, custom_message = nil
21
- logger.add_trace_perf_logging(self, sym, custom_message)
22
- end
23
- end
24
-
25
- class << self
26
- def add_trace_log_timing_for clazz, method_name, custom_message = nil
27
- Contrast::Logger::Log.instance.add_method_to_trace_timing(clazz, method_name, custom_message)
28
- end
29
19
  end
30
20
 
31
21
  # So This class here follows the update for the configuration
@@ -12,7 +12,8 @@ module Contrast
12
12
  return unless info?
13
13
 
14
14
  info('Process environment information', p_id: Process.pid, pp_id: Process.ppid,
15
- agent_version: Contrast::Agent::VERSION)
15
+ agent_version: Contrast::Agent::VERSION,
16
+ ruby_version: RUBY_VERSION)
16
17
  ENV.each do |env_key, env_value|
17
18
  env_key = env_key.to_s
18
19
  next unless ENV_KEYS.include?(env_key) ||
@@ -13,72 +13,6 @@ require 'contrast/logger/time'
13
13
  require 'contrast/components/config'
14
14
  require 'contrast/utils/log_utils'
15
15
 
16
- module Contrast
17
- # This module allows us to dynamically weave timing into our code, so that only when the time is actually needed do
18
- # we pay the penalty for that timing block
19
- module TraceTiming
20
- def methods_to_time
21
- @_methods_to_time ||= []
22
- end
23
-
24
- # Store info about methods for later patching.
25
- METHOD_INFO = Struct.new(:clazz, :method_name, :custom_msg, :aliased)
26
-
27
- # Add a method to the list of methods to be trace timed if logger set to TRACE. Enables trace timing after if
28
- # logger set to TRACE.
29
- #
30
- # @param: clazz [Class] the class of the method to time.
31
- # @param: method [Symbol] the method to time.
32
- # @param: method [String] optional custom logging message.
33
- def add_method_to_trace_timing clazz, method, msg = nil
34
- methods_to_time.append(METHOD_INFO.new(clazz, method, msg, false))
35
- enable_trace_timing if logger.level == ::Ougai::Logging::TRACE
36
- end
37
-
38
- # Add a method to the list of methods to be trace timed if logger set to TRACE. Enables trace timing after if
39
- # logger set to TRACE.
40
- #
41
- # @param: meth_spec [METHOD_INFO] specs about the method to be timed.
42
- # @param: class_method [Boolean] whether this is or isn't a class/module method.
43
- def trace_time_class_method meth_spec, class_method # rubocop:disable Metrics/AbcSize
44
- untimed_func_symbol = "untimed_#{ meth_spec.method_name }".to_sym
45
- send_to = class_method ? meth_spec.clazz.cs__singleton_class : meth_spec.clazz
46
- meth_spec.clazz.class_eval do
47
- include(Contrast::Components::Logger::InstanceMethods)
48
- extend(Contrast::Components::Logger::InstanceMethods)
49
-
50
- send_to.send(:alias_method, untimed_func_symbol, meth_spec.method_name)
51
- meth_spec.aliased = true
52
-
53
- log_message = "Elapsed time for #{ meth_spec.method_name }."
54
- log_message = meth_spec.custom_message if meth_spec.custom_msg
55
-
56
- send_to.send(:define_method, meth_spec.method_name) do |*args, **kwargs, &block| # rubocop:disable Performance/Kernel/DefineMethod
57
- start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
58
- rv = if kwargs.empty?
59
- send(untimed_func_symbol, *args, &block)
60
- else
61
- send(untimed_func_symbol, *args, **kwargs, &block)
62
- end
63
- delta = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start
64
- logger.trace(log_message, elapsed: delta * 1000)
65
- rv
66
- end
67
- end
68
- end
69
-
70
- # Enable trace timing of methods specified in @_methods_to_time via aliasing.
71
- def enable_trace_timing
72
- methods_to_time.each do |meth_spec|
73
- next if meth_spec.aliased
74
-
75
- is_class_method = meth_spec.clazz.singleton_methods(false).include?(meth_spec.method_name)
76
- trace_time_class_method(meth_spec, is_class_method)
77
- end
78
- end
79
- end
80
- end
81
-
82
16
  module Contrast
83
17
  # Used as a wrapper around our logging. The module option specifically adds in a new method for error that raises the
84
18
  # logged exception, used in testing so that we can see if anything unexpected happens without it being swallowed
@@ -105,7 +39,6 @@ module Contrast
105
39
  # level based on updates to TeamServer.
106
40
  class Log
107
41
  include Singleton
108
- include ::Contrast::TraceTiming
109
42
  include Contrast::Utils::LogUtils
110
43
 
111
44
  attr_reader :previous_path, :previous_level
@@ -132,8 +65,6 @@ module Contrast
132
65
  @previous_path = current_path
133
66
  @previous_level = current_level_const
134
67
 
135
- enable_trace_timing if current_level_const == ::Ougai::Logging::TRACE
136
-
137
68
  progname = Contrast::CONFIG.root.agent.logger.progname
138
69
  @_logger = build(path: current_path, level_const: current_level_const, progname: progname)
139
70
  # If we're logging to a new path, then let's start it w/ our helpful
@@ -8,31 +8,38 @@ module Contrast
8
8
  module Time
9
9
  # Log the message at the given level.
10
10
  #
11
- # @param level [String] the name of the method to use. Should be one of
12
- # trace, debug, info, warn, error
11
+ # @param level [String] the name of the method to use. Should be one of trace, debug, info, warn, error
13
12
  # @param message [String] the message to log
14
13
  def with_level level, message
15
14
  send(level.to_sym, message)
16
15
  end
17
16
 
18
- # Log, at the debug level, the action with a message including the time
19
- # it took for the wrapped function to complete.
17
+ # Log, at the debug level, the action with a message including the time it took for the wrapped function to
18
+ # complete. If not logging to debug, simply yield the given block.
20
19
  #
21
- # @param msgs [Array<Object>] the arguments to pass to the logger.
22
- # msgs[0] will be modified to include the elapsed time.
20
+ # @param msgs [Array<Object>] the arguments to pass to the logger. msgs[0] will be modified to include the elapsed
21
+ # time.
23
22
  # @param block [Block, Proc] the block to execute
24
23
  def debug_with_time *msgs, &block
25
- log_with_time(:debug, *msgs, &block)
24
+ if debug?
25
+ log_with_time(:debug, *msgs, &block)
26
+ elsif block
27
+ yield
28
+ end
26
29
  end
27
30
 
28
- # Log, at the trace level, the action with a message including the time
29
- # it took for the wrapped function to complete.
31
+ # Log, at the trace level, the action with a message including the time it took for the wrapped function to
32
+ # complete. If not logging to debug, simply yield the given block.
30
33
  #
31
- # @param msgs [Array<Object>] the arguments to pass to the logger.
32
- # msgs[0] will be modified to include the elapsed time.
34
+ # @param msgs [Array<Object>] the arguments to pass to the logger. msgs[0] will be modified to include the elapsed
35
+ # time.
33
36
  # @param block [Block, Proc] the block to execute
34
37
  def trace_with_time *msgs, &block
35
- log_with_time(:trace, *msgs, &block)
38
+ if trace?
39
+ log_with_time(:trace, *msgs, &block)
40
+ elsif block
41
+ yield
42
+ end
36
43
  end
37
44
 
38
45
  private
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: contrast-agent
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.6.0
4
+ version: 6.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - galen.palmer@contrastsecurity.com