class Google::Cloud::Trace::AsyncReporter::Batch
@private
Attributes
created_at[R]
traces[R]
Public Class Methods
new(reporter)
click to toggle source
# File lib/google/cloud/trace/async_reporter.rb, line 301 def initialize reporter @reporter = reporter @traces = [] @traces_bytes = reporter.project.bytesize + 4 # initial size @created_at = nil end
Public Instance Methods
add(trace, addl_bytes: nil)
click to toggle source
# File lib/google/cloud/trace/async_reporter.rb, line 308 def add trace, addl_bytes: nil addl_bytes ||= addl_bytes_for trace @traces << trace @traces_bytes += addl_bytes @created_at ||= Time.now nil end
addl_bytes_for(trace)
click to toggle source
# File lib/google/cloud/trace/async_reporter.rb, line 345 def addl_bytes_for trace trace.to_grpc.to_proto.bytesize + 2 end
publish_at()
click to toggle source
# File lib/google/cloud/trace/async_reporter.rb, line 334 def publish_at return nil if @created_at.nil? @created_at + @reporter.interval end
publish_wait()
click to toggle source
# File lib/google/cloud/trace/async_reporter.rb, line 339 def publish_wait publish_wait = publish_at - Time.now return 0 if publish_wait.negative? publish_wait end
ready?()
click to toggle source
# File lib/google/cloud/trace/async_reporter.rb, line 328 def ready? @traces.count >= @reporter.max_count || @traces_bytes >= @reporter.max_bytes || (@created_at.nil? || (publish_at < Time.now)) end
try_add(trace)
click to toggle source
# File lib/google/cloud/trace/async_reporter.rb, line 316 def try_add trace addl_bytes = addl_bytes_for trace new_message_count = @traces.count + 1 new_message_bytes = @traces_bytes + addl_bytes if new_message_count > @reporter.max_count || new_message_bytes >= @reporter.max_bytes return false end add trace, addl_bytes: addl_bytes true end