Skip to content

Commit

Permalink
emit warnings in logs when invalid spans are being skipped in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
anmarchenko committed Dec 5, 2023
1 parent c42591d commit b5938c5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
4 changes: 4 additions & 0 deletions lib/datadog/ci/test_visibility/serializers/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ def time_nano(time)
def duration_nano(duration)
(duration * 1e9).to_i
end

def to_s
"#{self.class.name}(id:#{span_id},name:#{name})"
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/datadog/ci/test_visibility/transport.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def encode_span(trace, span)

encoded
else
Datadog.logger.debug { "Invalid span skipped: #{span}" }
Datadog.logger.warn("Invalid event skipped: #{serializer}")
nil
end
end
Expand Down
14 changes: 13 additions & 1 deletion spec/datadog/ci/test_visibility/transport_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
)
end

before do
allow(Datadog.logger).to receive(:warn)
end

let(:dd_env) { nil }
let(:serializers_factory) { Datadog::CI::TestVisibility::Serializers::Factories::TestLevel }
let(:max_payload_size) { 4 * 1024 * 1024 }
Expand Down Expand Up @@ -84,9 +88,9 @@

context "when some spans are broken" do
let(:expected_events_count) { 3 }
let(:http_span) { spans.find { |span| span.type == "http" } }

before do
http_span = spans.find { |span| span.type == "http" }
http_span.start_time = Time.at(0)
end

Expand All @@ -103,6 +107,14 @@
expect(span_events.count).to eq(1)
end
end

it "logs warning that events were filtered out" do
subject.send_traces(traces)

expect(Datadog.logger).to have_received(:warn).with(
"Invalid event skipped: Datadog::CI::TestVisibility::Serializers::Span(id:#{http_span.id},name:#{http_span.name})"
)
end
end

context "when chunking is used" do
Expand Down

0 comments on commit b5938c5

Please sign in to comment.