rookout 0.1.28 → 0.1.50

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.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rookout/augs/actions/action_run_processor.rb +1 -0
  3. data/lib/rookout/augs/aug.rb +7 -6
  4. data/lib/rookout/augs/aug_factory.rb +71 -19
  5. data/lib/rookout/augs/aug_rate_limiter.rb +35 -36
  6. data/lib/rookout/augs/limits_manager.rb +32 -0
  7. data/lib/rookout/augs/locations/location.rb +1 -1
  8. data/lib/rookout/augs/locations/location_file_line.rb +5 -1
  9. data/lib/rookout/com_ws/agent_com_ws.rb +24 -20
  10. data/lib/rookout/com_ws/command_handler.rb +1 -1
  11. data/lib/rookout/com_ws/envelope_wrapper.rb +68 -0
  12. data/lib/rookout/com_ws/git.rb +1 -1
  13. data/lib/rookout/com_ws/information.rb +45 -1
  14. data/lib/rookout/com_ws/output.rb +62 -12
  15. data/lib/rookout/commit.rb +1 -1
  16. data/lib/rookout/config.rb +86 -15
  17. data/lib/rookout/exceptions.rb +49 -10
  18. data/lib/rookout/interface.rb +10 -8
  19. data/lib/rookout/logger.rb +13 -7
  20. data/lib/rookout/processor/namespace_serializer.rb +1 -1
  21. data/lib/rookout/processor/namespace_serializer2.rb +331 -0
  22. data/lib/rookout/processor/namespaces/container_namespace.rb +5 -0
  23. data/lib/rookout/processor/namespaces/frame_namespace.rb +2 -3
  24. data/lib/rookout/processor/namespaces/namespace.rb +1 -0
  25. data/lib/rookout/processor/namespaces/noop_namespace.rb +0 -4
  26. data/lib/rookout/processor/namespaces/ruby_object_namespace.rb +37 -22
  27. data/lib/rookout/processor/namespaces/ruby_object_serializer.rb +9 -7
  28. data/lib/rookout/processor/namespaces/ruby_utils_namespace.rb +0 -4
  29. data/lib/rookout/processor/namespaces/stack_namespace.rb +1 -0
  30. data/lib/rookout/processor/namespaces/traceback_namespace.rb +5 -0
  31. data/lib/rookout/processor/operations/set_operation.rb +2 -0
  32. data/lib/rookout/processor/paths/arithmetic_path.rb +4 -2
  33. data/lib/rookout/processor/paths/canopy/actions.rb +5 -1
  34. data/lib/rookout/processor/paths/canopy/consts.rb +6 -4
  35. data/lib/rookout/processor/paths/canopy/markers.rb +15 -5
  36. data/lib/rookout/processor/processor_factory.rb +0 -2
  37. data/lib/rookout/processor/rook_error.rb +3 -1
  38. data/lib/rookout/protobuf/controller_info_pb.rb +1 -0
  39. data/lib/rookout/protobuf/messages_pb.rb +54 -0
  40. data/lib/rookout/protobuf/variant2_pb.rb +42 -0
  41. data/lib/rookout/protobuf/variant_pb.rb +22 -0
  42. data/lib/rookout/rookout_singleton.rb +4 -3
  43. data/lib/rookout/sanitizer.rb +22 -0
  44. data/lib/rookout/services/position.rb +4 -3
  45. data/lib/rookout/services/tracer.rb +5 -2
  46. data/lib/rookout/utils.rb +28 -14
  47. data/lib/rookout/version.rb +1 -1
  48. data/lib/rookout.rb +4 -0
  49. metadata +46 -13
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3056007f4e19ad4f973d551922cc733ceb394515a2cebad17f8e6d1186b3ec79
4
- data.tar.gz: ee4920718d14a9ac843134a6fe37afa3b5292274924a6ded0c76247d9605f695
3
+ metadata.gz: 72f208b3a47ef61e59b2123afe3e666a2f3efa8295ddec10950e221e5547770a
4
+ data.tar.gz: 216a478be4998de21db6b2df156123d6cde587a54369914d93ba2f3ef8f9b5a7
5
5
  SHA512:
6
- metadata.gz: a7a7ae5c046fa155ba5146ef30a2e381abb439ddd0936f56f3302258f72d7ae499bc18359cd8d5156434e809fc9704b93250e383c98ed3f09f89a80b56877c71
7
- data.tar.gz: c71d7b41cb93686cae932edab6ce62c21d79e56b1368befe548db2046a5cf366c64d48112b07d6c09b49fdb0cb05949f3ffcfe15df90f763bb75e537aef886eb
6
+ metadata.gz: c9c2e1c91cba199a499fb360f519dcce9081f9c5693cf9919aaff369cd2389534900be7b580e03a3b9ef24e91394db0eec9d25e3968163de87a9390aec288392
7
+ data.tar.gz: 476c8d023ae8e04214693c3b929d0dae31bcf364cf23cc443bf3aab2c29bd05f08db4646a366cb54b4b5208d188df22024886bd35421849c73e331db720eb960
@@ -5,6 +5,7 @@ module Rookout
5
5
  module Actions
6
6
  class ActionRunProcessor < Action
7
7
  def initialize arguments, processor_factory
8
+ super()
8
9
  @processor = processor_factory.create_processor arguments["operations"]
9
10
 
10
11
  post_operations = arguments["post_operations"]
@@ -10,14 +10,13 @@ module Rookout
10
10
  require_relative "../logger"
11
11
 
12
12
  class Aug
13
- def initialize aug_id, action, condition, rate_limiter, _max_aug_time
14
- # NOTE: max_aux_time is not implemented
15
-
13
+ def initialize aug_id, action, condition, limits_manager, _max_aug_time
16
14
  @id = aug_id
17
15
  @action = action
18
16
  @condition = condition
19
- @rate_limiter = rate_limiter
17
+ @limits_manager = limits_manager
20
18
 
19
+ @executed = false
21
20
  @enabled = true
22
21
  @status = nil
23
22
  @log_cache = []
@@ -29,14 +28,16 @@ module Rookout
29
28
  return unless @enabled
30
29
 
31
30
  if output.user_messages_queue_full?
32
- Logger.instance.warning "Skipping aug-\t#{id} execution because the queue is full"
31
+ output.send_output_queue_full_warning @id
33
32
  return
34
33
  end
35
34
 
36
35
  namespace = create_namespaces frame, extracted
37
36
  return if @condition && !@condition.evaluate(namespace)
38
37
 
39
- @rate_limiter.with_limit do
38
+ should_skip_limiters = @condition.nil? && !@executed
39
+ @limits_manager.with_limit should_skip_limiters do
40
+ @executed = true
40
41
  report_id = Utils.uuid
41
42
  Logger.instance.info "Executing aug-\t#{id} (msg ID #{report_id})"
42
43
  @action.execute @id, report_id, namespace, output
@@ -10,7 +10,9 @@ module Rookout
10
10
  require_relative "locations/location_exception_handler"
11
11
  require_relative "aug_rate_limiter"
12
12
  require_relative "aug"
13
+ require_relative "limits_manager"
13
14
  require_relative "../utils"
15
+ require_relative "../logger"
14
16
 
15
17
  class AugFactory
16
18
  def initialize output
@@ -29,14 +31,15 @@ module Rookout
29
31
  max_aug_time = configuration["maxAugTime"] || Config.instrumentation_max_aug_time
30
32
 
31
33
  condition_configuration = configuration["conditional"]
32
- raise Exceptions::RookAugInvalidKey.new("conditional", configuration) unless
33
- condition_configuration.nil? || condition_configuration.is_a?(String)
34
+ unless condition_configuration.nil? || condition_configuration.is_a?(String)
35
+ raise Exceptions::RookAugInvalidKey.new("conditional", configuration)
36
+ end
34
37
  condition = condition_configuration.nil? ? nil : Conditions::Condition.new(condition_configuration)
35
38
 
36
- rate_limit = create_rate_limit configuration
39
+ limits_manager = create_limits_manager configuration
37
40
 
38
41
  max_aug_time_ns = Utils.milliseconds_to_nanoseconds max_aug_time
39
- aug = Aug.new aug_id, action, condition, rate_limit, max_aug_time_ns
42
+ aug = Aug.new aug_id, action, condition, limits_manager, max_aug_time_ns
40
43
 
41
44
  location_configuration = configuration["location"]
42
45
  raise Exceptions::RookAugInvalidKey.new("location", configuration) unless location_configuration.is_a? Hash
@@ -47,37 +50,86 @@ module Rookout
47
50
 
48
51
  def create_location configuration, aug
49
52
  name = configuration["name"]
50
- raise Exceptions::RookObjectNameMissing if name.nil?
53
+ raise Exceptions::RookObjectNameMissing, configuration if name.nil?
51
54
 
52
55
  case name
53
56
  when "file_line"
54
- return Locations::LocationFileLine.new configuration, @output, aug
57
+ Locations::LocationFileLine.new configuration, @output, aug
55
58
  when "exception_handler"
56
- return Locations::LocationExceptionHandler.new configuration, @output, aug
59
+ Locations::LocationExceptionHandler.new configuration, @output, aug
60
+ when "log_handler"
61
+ raise Exceptions::RookUnsupportedLiveLogger
57
62
  else
58
- raise Exceptions::RookUnsupportedLocation if name != "file_line"
63
+ raise Exceptions::RookUnsupportedLocation, configuration if name != "file_line"
59
64
  end
60
65
  end
61
66
 
62
- def create_rate_limit configuration
63
- window_quota = 200
64
- window_size = 5000
67
+ def create_limits_manager configuration
68
+ limiters = []
69
+ if global_rate_limiter.nil?
70
+ rate_limit = parse_rate_limit configuration["rateLimit"], configuration["rateLimitModifier"], 200, 5000
71
+ unless rate_limit.nil?
72
+ limiters.append AugRateLimiter.new(*rate_limit)
73
+ end
74
+ else
75
+ limiters.append global_rate_limiter
76
+ end
65
77
 
66
- rate_limit = configuration["rateLimit"]
67
- if rate_limit
68
- rate_limit_splitted = rate_limit.split "/"
69
- if rate_limit_splitted.length == 2
70
- window_quota = rate_limit_splitted[0].to_i
71
- window_size = rate_limit_splitted[1].to_i
78
+ LimitsManager.new limiters
79
+ end
80
+
81
+ def global_rate_limiter
82
+ if @global_rate_limiter.nil? && Rookout::Config.global_rate_limit != ""
83
+ begin
84
+ rate_limit = parse_rate_limit Rookout::Config.global_rate_limit,
85
+ "0", 0, 0
86
+ if rate_limit.nil?
87
+ raise Exceptions::RookInvalidRateLimitConfiguration, Rookout::Config.global_rate_limit
88
+ end
89
+ rescue Exceptions::RookInvalidRateLimitConfiguration => e
90
+ Logger.instance.warning "Failed to create global rate limiter: #{e.message}"
91
+ err = Processor::RookError.new e
92
+ UserWarnings.notify_error err
93
+ return nil
72
94
  end
95
+
96
+ @global_rate_limiter = AugRateLimiter.new(*rate_limit)
97
+ Logger.instance.debug "Using global rate limiter with configuration: #{rate_limit}"
98
+ Rookout::Config.using_global_rate_limiter = true
73
99
  end
74
100
 
75
- rate_limit_modifier = configuration["rateLimitModifier"] || 5
101
+ @global_rate_limiter
102
+ end
103
+
104
+ def parse_rate_limit config, modifier_config, default_quota, default_window
105
+ window_quota = default_quota
106
+ window_size = default_window
107
+
108
+ unless config.nil? || config.empty?
109
+ rate_limit_split = config.split "/"
110
+ unless rate_limit_split.length == 2 && \
111
+ Utils.is_number?(rate_limit_split[0]) && \
112
+ Utils.is_number?(rate_limit_split[1])
113
+ raise Exceptions::RookInvalidRateLimitConfiguration, config
114
+ end
115
+
116
+ window_quota = rate_limit_split[0].to_i
117
+ window_size = rate_limit_split[1].to_i
118
+ end
76
119
 
77
120
  window_quota_ns = Utils.milliseconds_to_nanoseconds window_quota
78
121
  window_size_ns = Utils.milliseconds_to_nanoseconds window_size
122
+ rate_limit_modifier = modifier_config.to_i || 5
123
+
124
+ if window_quota_ns == 0
125
+ return nil
126
+ end
127
+
128
+ if window_quota_ns >= window_size_ns
129
+ raise Exceptions::RookInvalidRateLimitConfiguration, config
130
+ end
79
131
 
80
- AugRateLimiter.new window_quota_ns, window_size_ns, rate_limit_modifier
132
+ [window_quota_ns, window_size_ns, rate_limit_modifier]
81
133
  end
82
134
  end
83
135
  end
@@ -8,51 +8,50 @@ module Rookout
8
8
  @quota = quota
9
9
  @has_quota = !@quota.nil? && (@quota > 0)
10
10
  @window_size = window_size
11
- @active_weight = quota / active_limit
11
+ if active_limit > 0
12
+ @active_weight = quota / active_limit
13
+ else
14
+ @active_weight = 0
15
+ end
12
16
 
13
17
  @mutex = Mutex.new
14
18
  @active_count = 0
15
19
  @windows = {}
16
20
  end
17
21
 
18
- def with_limit start_time = nil
19
- active = false
20
- start_time ||= Time.now
21
-
22
- # If quota, verify it
23
- if @has_quota
24
- # Get current time
25
- now_ns = Utils.time_to_nanoseconds start_time
26
-
27
- # Calculate window keys
28
- current_window_key, prev_window_key = timestamp_to_window_keys now_ns
29
-
30
- @mutex.synchronize do
31
- # Clean old windows
32
- cleanup now_ns
33
- # Increase active count
34
- @active_count += 1
35
- active = true
36
-
37
- # If exceeding quota
38
- if current_usage(now_ns, current_window_key, prev_window_key) > @quota
39
- warning = Processor::RookError.new Exceptions::RookRuleRateLimited.new
40
- UserWarnings.notify_warning warning
41
- return
42
- end
22
+ def before_run start_time
23
+ # If no quota, we can safely exit
24
+ unless @has_quota
25
+ return true
26
+ end
27
+ now_ns = Utils.time_to_nanoseconds start_time
28
+ current_window_key, prev_window_key = timestamp_to_window_keys now_ns
29
+
30
+ @mutex.synchronize do
31
+ # Clean old windows
32
+ cleanup now_ns
33
+ usage = current_usage now_ns, current_window_key, prev_window_key
34
+ @active_count += 1
35
+
36
+ # If exceeding quota
37
+ if usage > @quota
38
+ warning = Processor::RookError.new Exceptions::RookRuleRateLimited.create
39
+ UserWarnings.notify_warning warning
40
+ return false
43
41
  end
42
+
43
+ return true
44
44
  end
45
+ end
45
46
 
46
- begin
47
- yield
48
- ensure
49
- if @has_quota
50
- @mutex.synchronize { record_usage current_window_key, Utils.time_to_nanoseconds(Time.now) - now_ns }
51
- end
47
+ def after_run start_time
48
+ if @has_quota
49
+ now_ns = Utils.time_to_nanoseconds start_time
50
+ current_window_key, = timestamp_to_window_keys now_ns
51
+ @mutex.synchronize { record_usage current_window_key, Utils.time_to_nanoseconds(Time.now) - now_ns }
52
52
  end
53
- ensure
54
53
  # Reduce active count
55
- @mutex.synchronize { @active_count -= 1 } if active
54
+ @mutex.synchronize { @active_count -= 1 }
56
55
  end
57
56
 
58
57
  private
@@ -75,7 +74,7 @@ module Rookout
75
74
  prev_window_usage = @windows[prev_window_key] || 0
76
75
 
77
76
  # Previous window weight
78
- prev_weight = 1 - (now_ns - current_window_key) / @window_size.to_f
77
+ prev_weight = 1 - ((now_ns - current_window_key) / @window_size.to_f)
79
78
 
80
79
  # Final weighted usage
81
80
  (prev_window_usage * prev_weight) + (@active_count * @active_weight) + current_window_usage
@@ -91,7 +90,7 @@ module Rookout
91
90
  end
92
91
 
93
92
  def cleanup now_ns
94
- @windows.reject! { |key, _| key < (now_ns - @window_size * 5) } if @windows.length > 10
93
+ @windows.reject! { |key, _| key < (now_ns - (@window_size * 5)) } if @windows.length > 10
95
94
  end
96
95
  end
97
96
  end
@@ -0,0 +1,32 @@
1
+ module Rookout
2
+ module Augs
3
+ class LimitsManager
4
+ def initialize limiters
5
+ @limiters = limiters
6
+ end
7
+
8
+ def with_limit skip_limiters, start_time = nil
9
+ start_time ||= Time.now
10
+ can_execute = true
11
+ after_execute = []
12
+
13
+ @limiters.each do |limiter|
14
+ limiter_passed = limiter.before_run start_time
15
+ if limiter_passed || skip_limiters
16
+ after_execute.append -> { limiter.after_run start_time }
17
+ else
18
+ can_execute = false
19
+ end
20
+ end
21
+
22
+ if can_execute
23
+ yield
24
+ end
25
+ ensure
26
+ unless after_execute.nil?
27
+ after_execute.each(&:call)
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -53,7 +53,7 @@ module Rookout
53
53
  def notify_warning error
54
54
  return if silence_log? error
55
55
 
56
- Logger.instance.warning error.message
56
+ Logger.instance.warning error.message, error.exception
57
57
 
58
58
  # For easier testing
59
59
  return if @output.nil?
@@ -21,7 +21,11 @@ module Rookout
21
21
  @line_unique = arguments["line_unique"] || false
22
22
  end
23
23
 
24
- attr_reader :filename, :lineno, :file_hash, :line_crc, :line_unique
24
+ attr_reader :filename
25
+ attr_reader :lineno
26
+ attr_reader :file_hash
27
+ attr_reader :line_crc
28
+ attr_reader :line_unique
25
29
 
26
30
  def add_aug trigger_services
27
31
  trigger_services.get_service("position").add_aug self
@@ -26,8 +26,12 @@ module Rookout
26
26
  attr_reader :pending_messages
27
27
 
28
28
  def initialize output, agent_host, agent_port, proxy, token, labels, print_on_connect
29
- agent_host_with_protocl = agent_host.include?("://") ? agent_host : "ws://#{agent_host}"
30
- @uri = "#{agent_host_with_protocl}:#{agent_port}/v1"
29
+ if agent_host.nil? || agent_host.empty?
30
+ @uri = ""
31
+ else
32
+ agent_host_with_protocl = agent_host.include?("://") ? agent_host : "ws://#{agent_host}"
33
+ @uri = "#{agent_host_with_protocl}:#{agent_port}/v1"
34
+ end
31
35
  if proxy.nil? || proxy.empty?
32
36
  @proxy = nil
33
37
  else
@@ -44,6 +48,7 @@ module Rookout
44
48
  @main_thread = nil
45
49
  @outgoing_thread = nil
46
50
  @pending_messages = Queue.new
51
+ @pending_messages_length = 0
47
52
 
48
53
  @running = false
49
54
  @ready_event = Concurrent::Event.new
@@ -52,18 +57,15 @@ module Rookout
52
57
  @print_on_initial_connection = print_on_connect
53
58
  end
54
59
 
55
- def add message
56
- buffer = wrap_in_envelope message
57
- if buffer.length > Config.agent_com_max_message_limit
58
- exc = Exceptions::RookMessageSizeExceeded.new buffer.length, Config.agent_com_max_message_limit
59
- warning = Processor::RookError.new exc
60
- UserWarnings.notify_warning warning
61
-
62
- Logger.instance.warning "Dropping message, size was #{buffer.length} which is over the message size limit"
63
- return
60
+ def add envelope_wrapper
61
+ msg_size = envelope_wrapper.calculate_size
62
+ if @pending_messages_length + msg_size > Config.agent_com_max_queue_messages_length ||
63
+ queue_full?
64
+ raise Exceptions::RookOutputQueueFull
64
65
  end
65
66
 
66
- @pending_messages.push buffer if @pending_messages.length < Config.agent_com_max_queued_messages
67
+ @pending_messages.push envelope_wrapper
68
+ @pending_messages_length += msg_size
67
69
  end
68
70
 
69
71
  def queue_full?
@@ -103,7 +105,6 @@ module Rookout
103
105
 
104
106
  private
105
107
 
106
- # rubocop:disable Style/StderrPuts
107
108
  def connection_thread
108
109
  backoff = Backoff.new
109
110
 
@@ -113,7 +114,8 @@ module Rookout
113
114
 
114
115
  if @print_on_initial_connection
115
116
  @print_on_initial_connection = false
116
- STDERR.puts "[Rookout] Successfully connected to controller"
117
+ Utils.quiet_puts "[Rookout] Successfully connected to controller."
118
+ Logger.instance.debug "[Rookout] Agent ID is #{@agent_id}"
117
119
  end
118
120
  Logger.instance.debug "WebSocket connected successfully"
119
121
  Logger.instance.info "Finished initialization"
@@ -128,7 +130,7 @@ module Rookout
128
130
  @ready_event.set
129
131
  end
130
132
 
131
- Logger.instance.info "Connection failed; reason = #{e.message}"
133
+ Logger.instance.warning "Connection failed; reason = #{e.message}"
132
134
  end
133
135
 
134
136
  backoff.after_disconnect
@@ -137,13 +139,11 @@ module Rookout
137
139
  rescue Exception => e
138
140
  Logger.instance.error "Unexpected error in connection_thread", e
139
141
  end
140
- # rubocop:enable Style/StderrPuts
141
142
 
142
143
  def open_new_connection
143
144
  client = WebsocketClient.new @uri, @proxy, @token
144
145
  client.connect
145
146
 
146
- Logger.instance.info "Registering agent with id #{@agent_id}"
147
147
  msg = Com::Rookout::NewAgentMessage.new agent_info: @info.pack
148
148
  client.send_frame wrap_in_envelope(msg)
149
149
 
@@ -191,15 +191,19 @@ module Rookout
191
191
  def outgoing client, on_exit
192
192
  Pinger.new(client, Config.agent_com_ping_interval, Config.agent_com_ping_timeout).repeat do
193
193
  begin
194
- msg = @pending_messages.pop true
194
+ envelope_wrapper = @pending_messages.pop true
195
195
  rescue ThreadError
196
196
  sleep 0.25
197
197
  next
198
198
  end
199
199
 
200
- if msg.is_a? ExitMessage
200
+ msg = envelope_wrapper.envelope
201
+ @pending_messages_length -= envelope_wrapper.calculate_size
202
+
203
+ case msg
204
+ when ExitMessage
201
205
  break if msg.thread == Thread.current
202
- elsif msg.is_a? FlushMessage
206
+ when FlushMessage
203
207
  msg.event.set
204
208
  else
205
209
  begin
@@ -5,10 +5,10 @@ module Rookout
5
5
  class CommandHandler
6
6
  def initialize agent_com, augs_manager
7
7
  agent_com.on "Com::Rookout::InitialAugsCommand" do |initial_augs|
8
+ Config.update_config initial_augs.sdk_configuration
8
9
  augs = initial_augs.augs.map { |aug_json| JSON.parse aug_json }
9
10
  augs_manager.initialize_augs augs
10
11
  end
11
-
12
12
  agent_com.on "Com::Rookout::AddAugCommand" do |command|
13
13
  augs_manager.add_aug JSON.parse(command.aug_json)
14
14
  end
@@ -0,0 +1,68 @@
1
+ require_relative "../protobuf/envelope_pb"
2
+ require_relative "../processor/namespace_serializer2"
3
+
4
+
5
+ class EnvelopeWrapperBase
6
+ def wrap_in_envelope message
7
+ any_message = Google::Protobuf::Any.pack message
8
+ timestamp = Google::Protobuf::Timestamp.new
9
+ timestamp.from_time Time.new
10
+ envelope = Com::Rookout::Envelope.new msg: any_message, timestamp: timestamp
11
+ Com::Rookout::Envelope.encode envelope
12
+ end
13
+
14
+ def envelope
15
+ raise NotImplementedError
16
+ end
17
+
18
+ def calculate_size
19
+ raise NotImplementedError
20
+ end
21
+ end
22
+
23
+ class Variant2EnvelopeWrapper < EnvelopeWrapperBase
24
+ def initialize agent_id, aug_id, report_id, arguments
25
+ super()
26
+
27
+ @aug_report_message = Com::Rookout::AugReportMessage.new agent_id: agent_id,
28
+ aug_id: aug_id,
29
+ report_id: report_id
30
+ @serializer = Rookout::Processor::NamespaceSerializer2.new
31
+ @aug_report_message.arguments2 = @serializer.dump arguments, true
32
+
33
+ @estimated_length = @serializer.estimated_pending_bytes
34
+ @envelope = nil
35
+ end
36
+
37
+ def envelope
38
+ if @envelope.nil?
39
+ @serializer.string_cache.each do |key, value|
40
+ @aug_report_message.strings_cache[key.encode "UTF-8", invalid: :replace, undef: :replace, replace: "?"] = value
41
+ end
42
+ @envelope = wrap_in_envelope @aug_report_message
43
+
44
+ @serializer = nil
45
+ @aug_report_message = nil
46
+ end
47
+ @envelope
48
+ end
49
+
50
+ def calculate_size
51
+ @estimated_length
52
+ end
53
+ end
54
+
55
+ class EnvelopeWrapper < EnvelopeWrapperBase
56
+ def initialize message
57
+ super()
58
+ @envelope = wrap_in_envelope message
59
+ end
60
+
61
+ def envelope
62
+ @envelope
63
+ end
64
+
65
+ def calculate_size
66
+ @envelope.length
67
+ end
68
+ end
@@ -42,7 +42,7 @@ module Rookout
42
42
  link_contents = File.read link_path
43
43
 
44
44
  if link_contents.start_with? "ref:"
45
- next_link = (link_contents.split " ")[1].strip
45
+ next_link = link_contents.split[1].strip
46
46
  follow_sym_links root, next_link
47
47
  else
48
48
  link_contents.strip
@@ -21,6 +21,8 @@ module Rookout
21
21
  @labels["k8s_namespace"] = k8_namespace
22
22
  end
23
23
 
24
+ collect_serverless_labels
25
+
24
26
  @ip_addr = local_ip
25
27
 
26
28
  @scm_info = create_scm_information
@@ -54,7 +56,8 @@ module Rookout
54
56
  scm: @scm_info
55
57
  end
56
58
 
57
- attr_accessor :agent_id, :labels
59
+ attr_accessor :agent_id
60
+ attr_accessor :labels
58
61
 
59
62
  private
60
63
 
@@ -97,6 +100,47 @@ module Rookout
97
100
 
98
101
  Com::Rookout::SCMInformation.new origin: user_git_origin, commit: user_git_commit
99
102
  end
103
+
104
+ def aws_lambda?
105
+ !ENV["AWS_LAMBDA_FUNCTION_NAME"].nil?
106
+ end
107
+
108
+ def google_cloud_function?
109
+ !ENV["FUNCTION_TARGET"].nil? && !ENV["FUNCTION_SIGNATURE_TYPE"].nil?
110
+ end
111
+
112
+ def cloud_run_or_fire_base?
113
+ !ENV["K_SERVICE"].nil? &&
114
+ !ENV["K_REVISION"].nil? &&
115
+ !ENV["K_CONFIGURATION"].nil? &&
116
+ !ENV["PORT"].nil?
117
+ end
118
+
119
+ def azure_function?
120
+ !ENV["FUNCTIONS_WORKER_RUNTIME"].nil? && !ENV["WEBSITE_SITE_NAME"].nil?
121
+ end
122
+
123
+ def collect_serverless_labels
124
+ if aws_lambda?
125
+ @labels["function_name"] = ENV["AWS_LAMBDA_FUNCTION_NAME"]
126
+ @labels["aws_region"] = ENV["AWS_REGION"]
127
+
128
+ elsif google_cloud_function? || cloud_run_or_fire_base?
129
+ function_name = ENV["FUNCTION_NAME"]
130
+ if function_name.nil?
131
+ function_name = ENV["K_SERVICE"]
132
+ end
133
+ @labels["function_name"] = function_name
134
+
135
+ elsif azure_function?
136
+ @labels["function_name"] = ENV["WEBSITE_SITE_NAME"]
137
+ @labels["azure_region"] = ENV["REGION_NAME"]
138
+ end
139
+
140
+ return unless @labels.key? "function_name"
141
+
142
+ @labels["rookout_serverless"] = "true"
143
+ end
100
144
  end
101
145
  end
102
146
  end