Skip to content

Commit

Permalink
send logical test session in the metadata payload for all test levels
Browse files Browse the repository at this point in the history
  • Loading branch information
anmarchenko committed Sep 20, 2024
1 parent 59f9323 commit 6f756b8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
15 changes: 12 additions & 3 deletions lib/datadog/ci/test_visibility/transport.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@ def encode_events(traces)
end

def encode_span(trace, span)
serializer = serializers_factory.serializer(trace, span, options: {itr_correlation_id: itr&.correlation_id})
serializer = serializers_factory.serializer(
trace,
span,
options: {itr_correlation_id: test_optimisation&.correlation_id}
)

if serializer.valid?
encoded = encoder.encode(serializer)
return nil if event_too_large?(span, encoded)
Expand Down Expand Up @@ -101,15 +106,19 @@ def write_payload_header(packer)
packer.write_map_header(1)

packer.write(Ext::Test::METADATA_TAG_TEST_SESSION_NAME)
packer.write("dummy")
packer.write(test_visibility&.logical_test_session_name)
end

packer.write("events")
end

def itr
def test_optimisation
@test_optimisation ||= Datadog::CI.send(:test_optimisation)
end

def test_visibility
@test_visibility ||= Datadog::CI.send(:test_visibility)
end
end
end
end
Expand Down
5 changes: 4 additions & 1 deletion sig/datadog/ci/test_visibility/transport.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ module Datadog

@dd_env: String?
@serializers_factory: singleton(Datadog::CI::TestVisibility::Serializers::Factories::TestLevel) | singleton(Datadog::CI::TestVisibility::Serializers::Factories::TestSuiteLevel)

@test_optimisation: Datadog::CI::TestOptimisation::Component?
@test_visibility: Datadog::CI::TestVisibility::Component?

def initialize: (
api: Datadog::CI::Transport::Api::Base,
Expand All @@ -21,7 +23,8 @@ module Datadog
def send_payload: (String encoded_payload) -> Datadog::CI::Transport::Adapters::Net::Response
def encode_events: (Array[Datadog::Tracing::TraceSegment] traces) -> ::Array[String]
def encode_span: (Datadog::Tracing::TraceSegment trace, Datadog::Tracing::Span span) -> String?
def itr: () -> Datadog::CI::TestOptimisation::Component?
def test_optimisation: () -> Datadog::CI::TestOptimisation::Component?
def test_visibility: () -> Datadog::CI::TestVisibility::Component?
end
end
end
Expand Down
3 changes: 2 additions & 1 deletion spec/datadog/ci/test_visibility/transport_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
include_context "Telemetry spy"
include_context "CI mode activated" do
let(:integration_name) { :rspec }
let(:logical_test_session_name) { "logical_test_session_name" }
end

subject(:transport) do
Expand Down Expand Up @@ -50,7 +51,7 @@

Datadog::CI::Ext::AppTypes::CI_SPAN_TYPES.each do |type|
type_metadata = payload["metadata"][type]
expect(type_metadata).to include("test_session.name" => "dummy")
expect(type_metadata).to include("test_session.name" => logical_test_session_name)
end

events = payload["events"]
Expand Down

0 comments on commit 6f756b8

Please sign in to comment.