diff --git a/lib/datadog/ci/test_visibility/serializers/base.rb b/lib/datadog/ci/test_visibility/serializers/base.rb index b32ddc26..24fe9777 100644 --- a/lib/datadog/ci/test_visibility/serializers/base.rb +++ b/lib/datadog/ci/test_visibility/serializers/base.rb @@ -28,11 +28,12 @@ class Base "duration" ].freeze - attr_reader :trace, :span, :meta + attr_reader :trace, :span, :meta, :options - def initialize(trace, span) + def initialize(trace, span, options: {}) @trace = trace @span = span + @options = options @meta = @span.meta.reject { |key, _| Ext::Test::TRANSIENT_TAGS.include?(key) } diff --git a/lib/datadog/ci/test_visibility/serializers/factories/test_level.rb b/lib/datadog/ci/test_visibility/serializers/factories/test_level.rb index aca2bdb3..30309d78 100644 --- a/lib/datadog/ci/test_visibility/serializers/factories/test_level.rb +++ b/lib/datadog/ci/test_visibility/serializers/factories/test_level.rb @@ -14,12 +14,12 @@ module Factories module TestLevel module_function - def serializer(trace, span) + def serializer(trace, span, options: {}) case span.type when Datadog::CI::Ext::AppTypes::TYPE_TEST - Serializers::TestV1.new(trace, span) + Serializers::TestV1.new(trace, span, options: options) else - Serializers::Span.new(trace, span) + Serializers::Span.new(trace, span, options: options) end end end diff --git a/lib/datadog/ci/test_visibility/serializers/factories/test_suite_level.rb b/lib/datadog/ci/test_visibility/serializers/factories/test_suite_level.rb index f6f4c181..f03f0a1b 100644 --- a/lib/datadog/ci/test_visibility/serializers/factories/test_suite_level.rb +++ b/lib/datadog/ci/test_visibility/serializers/factories/test_suite_level.rb @@ -15,18 +15,18 @@ module Factories module TestSuiteLevel module_function - def serializer(trace, span) + def serializer(trace, span, options: {}) case span.type when Datadog::CI::Ext::AppTypes::TYPE_TEST - Serializers::TestV2.new(trace, span) + Serializers::TestV2.new(trace, span, options: options) when Datadog::CI::Ext::AppTypes::TYPE_TEST_SESSION - Serializers::TestSession.new(trace, span) + Serializers::TestSession.new(trace, span, options: options) when Datadog::CI::Ext::AppTypes::TYPE_TEST_MODULE - Serializers::TestModule.new(trace, span) + Serializers::TestModule.new(trace, span, options: options) when Datadog::CI::Ext::AppTypes::TYPE_TEST_SUITE - Serializers::TestSuite.new(trace, span) + Serializers::TestSuite.new(trace, span, options: options) else - Serializers::Span.new(trace, span) + Serializers::Span.new(trace, span, options: options) end end end diff --git a/sig/datadog/ci/test_visibility/serializers/base.rbs b/sig/datadog/ci/test_visibility/serializers/base.rbs index a6281b0b..d5a76e41 100644 --- a/sig/datadog/ci/test_visibility/serializers/base.rbs +++ b/sig/datadog/ci/test_visibility/serializers/base.rbs @@ -10,18 +10,24 @@ module Datadog CONTENT_FIELDS: Array[String | Hash[String, String]] REQUIRED_FIELDS: Array[String] - @content_fields_count: Integer - @start: Integer - @duration: Integer + @trace: Datadog::Tracing::TraceSegment + @span: Datadog::Tracing::Span + @options: Hash[Symbol, untyped] + @meta: Hash[untyped, untyped] @errors: Hash[String, Set[String]] @validated: bool + @content_fields_count: Integer + @start: Integer + @duration: Integer + attr_reader trace: Datadog::Tracing::TraceSegment attr_reader span: Datadog::Tracing::Span attr_reader meta: Hash[untyped, untyped] + attr_reader options: Hash[Symbol, untyped] - def initialize: (Datadog::Tracing::TraceSegment trace, Datadog::Tracing::Span span) -> void + def initialize: (Datadog::Tracing::TraceSegment trace, Datadog::Tracing::Span span, ?options: Hash[Symbol, untyped]) -> void def to_msgpack: (?untyped? packer) -> untyped diff --git a/sig/datadog/ci/test_visibility/serializers/factories/test_level.rbs b/sig/datadog/ci/test_visibility/serializers/factories/test_level.rbs index ac7b6c13..4cebc8e4 100644 --- a/sig/datadog/ci/test_visibility/serializers/factories/test_level.rbs +++ b/sig/datadog/ci/test_visibility/serializers/factories/test_level.rbs @@ -4,7 +4,7 @@ module Datadog module Serializers module Factories module TestLevel - def self?.serializer: (Datadog::Tracing::TraceSegment trace, Datadog::Tracing::Span span) -> Datadog::CI::TestVisibility::Serializers::Base + def self?.serializer: (Datadog::Tracing::TraceSegment trace, Datadog::Tracing::Span span, ?options: Hash[Symbol, untyped]) -> Datadog::CI::TestVisibility::Serializers::Base end end end diff --git a/sig/datadog/ci/test_visibility/serializers/factories/test_suite_level.rbs b/sig/datadog/ci/test_visibility/serializers/factories/test_suite_level.rbs index 8ebc424f..af2dbc06 100644 --- a/sig/datadog/ci/test_visibility/serializers/factories/test_suite_level.rbs +++ b/sig/datadog/ci/test_visibility/serializers/factories/test_suite_level.rbs @@ -4,7 +4,7 @@ module Datadog module Serializers module Factories module TestSuiteLevel - def self?.serializer: (Datadog::Tracing::TraceSegment trace, Datadog::Tracing::Span span) -> Datadog::CI::TestVisibility::Serializers::Base + def self?.serializer: (Datadog::Tracing::TraceSegment trace, Datadog::Tracing::Span span, ?options: Hash[Symbol, untyped]) -> Datadog::CI::TestVisibility::Serializers::Base end end end diff --git a/spec/datadog/ci/test_visibility/serializers/factories/test_suite_level_spec.rb b/spec/datadog/ci/test_visibility/serializers/factories/test_suite_level_spec.rb index c2ab81e9..42d155be 100644 --- a/spec/datadog/ci/test_visibility/serializers/factories/test_suite_level_spec.rb +++ b/spec/datadog/ci/test_visibility/serializers/factories/test_suite_level_spec.rb @@ -12,32 +12,45 @@ produce_test_session_trace(with_http_span: true) end - subject { described_class.serializer(trace_for_span(ci_span), ci_span) } - - describe ".convert_trace_to_serializable_events" do - context "with a session span" do - let(:ci_span) { test_session_span } - it { is_expected.to be_kind_of(Datadog::CI::TestVisibility::Serializers::TestSession) } - end - - context "with a module span" do - let(:ci_span) { test_module_span } - it { is_expected.to be_kind_of(Datadog::CI::TestVisibility::Serializers::TestModule) } - end - - context "with a suite span" do - let(:ci_span) { first_test_suite_span } - it { is_expected.to be_kind_of(Datadog::CI::TestVisibility::Serializers::TestSuite) } + context "without options" do + subject { described_class.serializer(trace_for_span(ci_span), ci_span) } + + describe ".convert_trace_to_serializable_events" do + context "with a session span" do + let(:ci_span) { test_session_span } + it { is_expected.to be_kind_of(Datadog::CI::TestVisibility::Serializers::TestSession) } + end + + context "with a module span" do + let(:ci_span) { test_module_span } + it { is_expected.to be_kind_of(Datadog::CI::TestVisibility::Serializers::TestModule) } + end + + context "with a suite span" do + let(:ci_span) { first_test_suite_span } + it { is_expected.to be_kind_of(Datadog::CI::TestVisibility::Serializers::TestSuite) } + end + + context "with a test span" do + let(:ci_span) { first_test_span } + it { is_expected.to be_kind_of(Datadog::CI::TestVisibility::Serializers::TestV2) } + end + + context "with a http request span" do + let(:ci_span) { first_custom_span } + it { is_expected.to be_kind_of(Datadog::CI::TestVisibility::Serializers::Span) } + end end + end - context "with a test span" do - let(:ci_span) { first_test_span } - it { is_expected.to be_kind_of(Datadog::CI::TestVisibility::Serializers::TestV2) } - end + context "with options" do + let(:ci_span) { first_test_span } + subject { described_class.serializer(trace_for_span(ci_span), ci_span, options: {custom: "option"}) } - context "with a http request span" do - let(:ci_span) { first_custom_span } - it { is_expected.to be_kind_of(Datadog::CI::TestVisibility::Serializers::Span) } + describe ".serializer" do + it "passes options to the serializer" do + expect(subject.options).to eq({custom: "option"}) + end end end end