diff --git a/sdk/lib/opentelemetry/sdk/internal.rb b/sdk/lib/opentelemetry/sdk/internal.rb index 9c9068b93..fae806960 100644 --- a/sdk/lib/opentelemetry/sdk/internal.rb +++ b/sdk/lib/opentelemetry/sdk/internal.rb @@ -49,17 +49,17 @@ def valid_value?(value) end def valid_attributes?(owner, kind, attrs) - attrs.nil? || attrs.all? do |k, v| + attrs.nil? || attrs.each do |k, v| if !valid_key?(k) OpenTelemetry.handle_error(message: "invalid #{kind} attribute key type #{k.class} on span '#{owner}'") - false + return false elsif !valid_value?(v) OpenTelemetry.handle_error(message: "invalid #{kind} attribute value type #{v.class} for key '#{k}' on span '#{owner}'") - false - else - true + return false end end + + true end end end diff --git a/sdk/lib/opentelemetry/sdk/trace/span.rb b/sdk/lib/opentelemetry/sdk/trace/span.rb index b706b70d2..3221b8ccd 100644 --- a/sdk/lib/opentelemetry/sdk/trace/span.rb +++ b/sdk/lib/opentelemetry/sdk/trace/span.rb @@ -282,7 +282,7 @@ def to_span_data 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_scope) # rubocop:disable 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/MethodLength, Metrics/PerceivedComplexity super(span_context: context) @mutex = Mutex.new @name = name @@ -297,7 +297,7 @@ def initialize(context, parent_context, parent_span, name, kind, parent_span_id, @total_recorded_events = 0 @total_recorded_links = links&.size || 0 @total_recorded_attributes = attributes&.size || 0 - @attributes = attributes.nil? ? nil : Hash[attributes] # We need a mutable copy of attributes. + @attributes = attributes trim_span_attributes(@attributes) @events = nil @links = trim_links(links, span_limits.link_count_limit, span_limits.link_attribute_count_limit) @@ -317,7 +317,7 @@ def initialize(context, parent_context, parent_span, name, kind, parent_span_id, # SpanData. @monotonic_start_timestamp = monotonic_now @realtime_start_timestamp = if parent_span.recording? - relative_realtime(parent_span.realtime_start_timestamp, parent_span.monotonic_start_timestamp) + relative_realtime(parent_span.realtime_start_timestamp, parent_span.monotonic_start_timestamp, @monotonic_start_timestamp) else realtime_now end @@ -419,15 +419,15 @@ def append_event(events, event) # rubocop:disable Metrics/CyclomaticComplexity, def relative_timestamp(timestamp) return time_in_nanoseconds(timestamp) unless timestamp.nil? - relative_realtime(realtime_start_timestamp, monotonic_start_timestamp) + relative_realtime(realtime_start_timestamp, monotonic_start_timestamp, monotonic_now) end def time_in_nanoseconds(timestamp) (timestamp.to_r * 1_000_000_000).to_i end - def relative_realtime(realtime_base, monotonic_base) - realtime_base + (monotonic_now - monotonic_base) + def relative_realtime(realtime_base, monotonic_base, now) + realtime_base + (now - monotonic_base) end def realtime_now diff --git a/sdk/lib/opentelemetry/sdk/trace/tracer_provider.rb b/sdk/lib/opentelemetry/sdk/trace/tracer_provider.rb index 790c6ba0f..10a8ed8ae 100644 --- a/sdk/lib/opentelemetry/sdk/trace/tracer_provider.rb +++ b/sdk/lib/opentelemetry/sdk/trace/tracer_provider.rb @@ -141,7 +141,7 @@ def internal_start_span(name, kind, attributes, links, start_timestamp, parent_c if result.recording? && !@stopped trace_flags = result.sampled? ? OpenTelemetry::Trace::TraceFlags::SAMPLED : OpenTelemetry::Trace::TraceFlags::DEFAULT context = OpenTelemetry::Trace::SpanContext.new(trace_id: trace_id, span_id: span_id, trace_flags: trace_flags, tracestate: result.tracestate) - attributes = attributes&.merge(result.attributes) || result.attributes + attributes = attributes&.merge(result.attributes) || result.attributes.dup Span.new( context, parent_context,