lib/opentelemetry/sdk/trace/span.rb in opentelemetry-sdk-1.1.0 vs lib/opentelemetry/sdk/trace/span.rb in opentelemetry-sdk-1.2.0
- old
+ new
@@ -21,12 +21,18 @@
private_constant :DEFAULT_STATUS, :EMPTY_ATTRIBUTES
# The following readers are intended for the use of SpanProcessors and
# should not be considered part of the public interface for instrumentation.
- attr_reader :name, :status, :kind, :parent_span_id, :start_timestamp, :end_timestamp, :links, :resource, :instrumentation_library
+ attr_reader :name, :status, :kind, :parent_span_id, :start_timestamp, :end_timestamp, :links, :resource, :instrumentation_scope
+ # Returns an InstrumentationScope struct, which is backwards compatible with InstrumentationLibrary.
+ # @deprecated Please use instrumentation_scope instead.
+ #
+ # @return InstrumentationScope
+ alias instrumentation_library instrumentation_scope
+
# Return a frozen copy of the current attributes. This is intended for
# use of SpanProcessors and should not be considered part of the public
# interface for instrumentation.
#
# @return [Hash{String => String, Numeric, Boolean, Array<String, Numeric, Boolean>}] may be nil.
@@ -129,11 +135,11 @@
# values may be (array of) string, boolean or numeric type.
# @param [optional Time] timestamp Optional timestamp for the event.
#
# @return [self] returns itself
def add_event(name, attributes: nil, timestamp: nil)
- event = Event.new(name, truncate_attribute_values(attributes), relative_timestamp(timestamp))
+ event = Event.new(name, truncate_attribute_values(attributes, @span_limits.event_attribute_length_limit), relative_timestamp(timestamp))
@mutex.synchronize do
if @ended
OpenTelemetry.logger.warn('Calling add_event on an ended Span.')
else
@@ -265,29 +271,29 @@
@end_timestamp,
@attributes,
@links,
@events,
@resource,
- @instrumentation_library,
+ @instrumentation_scope,
context.span_id,
context.trace_id,
context.trace_flags,
context.tracestate
)
end
# @api private
- def initialize(context, parent_context, parent_span, name, kind, parent_span_id, span_limits, span_processors, attributes, links, start_timestamp, resource, instrumentation_library) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
+ def initialize(context, parent_context, parent_span, name, kind, parent_span_id, span_limits, span_processors, attributes, links, start_timestamp, resource, instrumentation_scope) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
super(span_context: context)
@mutex = Mutex.new
@name = name
@kind = kind
@parent_span_id = parent_span_id.freeze || OpenTelemetry::Trace::INVALID_SPAN_ID
@span_limits = span_limits
@span_processors = span_processors
@resource = resource
- @instrumentation_library = instrumentation_library
+ @instrumentation_scope = instrumentation_scope
@ended = false
@status = DEFAULT_STATUS
@total_recorded_events = 0
@total_recorded_links = links&.size || 0
@total_recorded_attributes = attributes&.size || 0
@@ -341,25 +347,23 @@
def trim_span_attributes(attrs)
return if attrs.nil?
excess = attrs.size - @span_limits.attribute_count_limit
excess.times { attrs.shift } if excess.positive?
- truncate_attribute_values(attrs)
+ truncate_attribute_values(attrs, @span_limits.attribute_length_limit)
nil
end
- def truncate_attribute_values(attrs)
+ def truncate_attribute_values(attrs, attribute_length_limit)
return EMPTY_ATTRIBUTES if attrs.nil?
-
- attribute_length_limit = @span_limits.attribute_length_limit
return attrs if attribute_length_limit.nil?
attrs.transform_values! { |value| OpenTelemetry::Common::Utilities.truncate_attribute_value(value, attribute_length_limit) }
attrs
end
- def trim_links(links, link_count_limit, link_attribute_count_limit) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
+ def trim_links(links, link_count_limit, link_attribute_count_limit) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
# Fast path (likely) common cases.
return nil if links.nil?
if links.size <= link_count_limit &&
links.all? { |link| link.span_context.valid? && link.attributes.size <= link_attribute_count_limit && Internal.valid_attributes?(name, 'link', link.attributes) }
@@ -377,10 +381,10 @@
excess.times { attrs.shift } if excess.positive?
OpenTelemetry::Trace::Link.new(link.span_context, attrs)
end.freeze
end
- def append_event(events, event) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
+ def append_event(events, event) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
event_count_limit = @span_limits.event_count_limit
event_attribute_count_limit = @span_limits.event_attribute_count_limit
valid_attributes = Internal.valid_attributes?(name, 'event', event.attributes)
# Fast path (likely) common case.