lib/opentelemetry/sdk/trace/span.rb in opentelemetry-sdk-0.16.0 vs lib/opentelemetry/sdk/trace/span.rb in opentelemetry-sdk-0.17.0
- old
+ new
@@ -131,11 +131,11 @@
# @param [optional Time] timestamp Optional timestamp for the event.
#
# @return [self] returns itself
def add_event(name, attributes: nil, timestamp: nil)
super
- event = Event.new(name: name, attributes: attributes, timestamp: timestamp || Time.now)
+ event = Event.new(name: name, attributes: truncate_attribute_values(attributes), timestamp: timestamp || Time.now)
@mutex.synchronize do
if @ended
OpenTelemetry.logger.warn('Calling add_event on an ended Span.')
else
@@ -314,10 +314,19 @@
def trim_span_attributes(attrs)
return if attrs.nil?
excess = attrs.size - @trace_config.max_attributes_count
excess.times { attrs.shift } if excess.positive?
+ truncate_attribute_values(attrs)
nil
+ end
+
+ def truncate_attribute_values(attrs)
+ return if attrs.nil?
+
+ max_attributes_length = @trace_config.max_attributes_length
+ attrs.each { |key, value| attrs[key] = OpenTelemetry::Common::Utilities.truncate(value, max_attributes_length) } if max_attributes_length
+ attrs
end
def trim_links(links, max_links_count, max_attributes_per_link) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
# Fast path (likely) common cases.
return nil if links.nil?