From f78f874f183cfeacb2815f054685b061d69097d7 Mon Sep 17 00:00:00 2001 From: Munir Abdinur Date: Fri, 12 Jul 2024 13:48:15 -0400 Subject: [PATCH] linting fixes --- lib/datadog/tracing/span_event.rb | 15 +++++++++++---- spec/datadog/opentelemetry_spec.rb | 4 ++-- spec/datadog/tracing/span_event_spec.rb | 2 +- .../tracing/transport/serializable_trace_spec.rb | 6 +++--- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/lib/datadog/tracing/span_event.rb b/lib/datadog/tracing/span_event.rb index a347885d394..82515c7e1e7 100644 --- a/lib/datadog/tracing/span_event.rb +++ b/lib/datadog/tracing/span_event.rb @@ -12,7 +12,7 @@ class SpanEvent attr_reader :name # @!attribute [r] attributes - # @return [Hash] + # @return [Hash{String => String, Numeric, Boolean, Array}] attr_reader :attributes # @!attribute [r] time_unix_nano @@ -25,13 +25,20 @@ def initialize( time_unix_nano: nil ) @name = name - @attributes = attributes&.map { |key, val| [key, val.to_s] }&.to_h || {} + @attributes = attributes || {} @time_unix_nano = time_unix_nano || Core::Utils::Time.now.to_f * 1e9 end def to_hash - h = { :name => @name, :time_unix_nano => @time_unix_nano } - h[:attributes] = @attributes unless @attributes.empty? + h = { name: @name, time_unix_nano: @time_unix_nano } + # stringify array values in attributes + unless @attributes.empty? + h[:attributes] = attributes&.map do |key, val| + val = val.to_s if val.is_a?(Array) + [key, val] + end.to_h + end + h end end diff --git a/spec/datadog/opentelemetry_spec.rb b/spec/datadog/opentelemetry_spec.rb index 5016b62817d..f81bde2189e 100644 --- a/spec/datadog/opentelemetry_spec.rb +++ b/spec/datadog/opentelemetry_spec.rb @@ -638,14 +638,14 @@ context 'with name, attributes and timestamp' do let(:event_options) do - { attributes: { 'raised' => false, 'handler' => 'default', 'count' => 1 }, timestamp: 17206369349 } + { attributes: { raised: false, handler: 'default', count: 1 }, timestamp: 17206369349 } end it 'adds one event to the span' do expect(span.events.count).to eq(1) expect(span.events[0].name).to eq('Exception was raised!') expect(span.events[0].time_unix_nano).to eq(17206369349000000000) - expect(span.events[0].attributes).to eq({ 'raised' => 'false', 'handler' => 'default', 'count' => '1' }) + expect(span.events[0].attributes).to eq({ raised: false, handler: 'default', count: 1 }) end end diff --git a/spec/datadog/tracing/span_event_spec.rb b/spec/datadog/tracing/span_event_spec.rb index bbd717ecf22..19638986340 100644 --- a/spec/datadog/tracing/span_event_spec.rb +++ b/spec/datadog/tracing/span_event_spec.rb @@ -51,7 +51,7 @@ let(:attributes) { { 'event.name' => 'test_event', 'event.id' => 1, 'nested' => [true, [2, 3], 'val'] } } it { is_expected.to include( - attributes: { 'event.name' => 'test_event', 'event.id' => '1', 'nested' => '[true, [2, 3], "val"]' } + attributes: { 'event.name' => 'test_event', 'event.id' => 1, 'nested' => '[true, [2, 3], "val"]' } ) } end diff --git a/spec/datadog/tracing/transport/serializable_trace_spec.rb b/spec/datadog/tracing/transport/serializable_trace_spec.rb index fa5b40924b8..c1e63ae9ac5 100644 --- a/spec/datadog/tracing/transport/serializable_trace_spec.rb +++ b/spec/datadog/tracing/transport/serializable_trace_spec.rb @@ -145,7 +145,7 @@ Datadog::Tracing::SpanEvent.new( "Another Event #{i}!", time_unix_nano: 2_000_000_000, - attributes: { 'id' => i, 'required' => i == 1 }, + attributes: { id: i, required: (i == 1) }, ), ], ) @@ -160,9 +160,9 @@ ).to eq( [ '[{"name":"First Event","time_unix_nano":1000000000},{"name":"Another Event 0!","time_unix_nano":2000000000,' \ - '"attributes":{"id":"0","required":"false"}}]', + '"attributes":{"id":0,"required":false}}]', '[{"name":"First Event","time_unix_nano":1000000000},{"name":"Another Event 1!","time_unix_nano":2000000000,' \ - '"attributes":{"id":"1","required":"true"}}]', + '"attributes":{"id":1,"required":true}}]', ] ) end