Skip to content

Commit

Permalink
linting fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mabdinur committed Jul 12, 2024
1 parent 6d71a35 commit f78f874
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
15 changes: 11 additions & 4 deletions lib/datadog/tracing/span_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class SpanEvent
attr_reader :name

# @!attribute [r] attributes
# @return [Hash<String,String>]
# @return [Hash{String => String, Numeric, Boolean, Array<String, Numeric, Boolean>}]
attr_reader :attributes

# @!attribute [r] time_unix_nano
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions spec/datadog/opentelemetry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion spec/datadog/tracing/span_event_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions spec/datadog/tracing/transport/serializable_trace_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) },
),
],
)
Expand All @@ -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
Expand Down

0 comments on commit f78f874

Please sign in to comment.