Skip to content

Commit

Permalink
Merge pull request #74 from DataDog/anmarchenko/single_trace_per_test
Browse files Browse the repository at this point in the history
Datadog::CI.trace_test always starts a new trace
  • Loading branch information
anmarchenko authored Nov 29, 2023
2 parents 8d8cead + a14f853 commit a5dd26f
Show file tree
Hide file tree
Showing 15 changed files with 439 additions and 376 deletions.
7 changes: 5 additions & 2 deletions lib/datadog/ci/recorder.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require "datadog/tracing"
require "datadog/tracing/trace_digest"

require "rbconfig"

Expand Down Expand Up @@ -62,7 +63,9 @@ def trace_test(test_name, service_name: nil, operation_name: "test", tags: {}, &
span_options = {
resource: test_name,
service: service_name,
span_type: Ext::AppTypes::TYPE_TEST
span_type: Ext::AppTypes::TYPE_TEST,
# this option is needed to force a new trace to be created
continue_from: Datadog::Tracing::TraceDigest.new
}

tags[Ext::Test::TAG_NAME] = test_name
Expand Down Expand Up @@ -120,7 +123,7 @@ def active_test_session
@global_context.active_test_session
end

# TODO: does it make sense to have a paramter here?
# TODO: does it make sense to have a parameter here?
def deactivate_test(test)
@local_context.deactivate_test!(test)
end
Expand Down
19 changes: 2 additions & 17 deletions lib/datadog/ci/test_visibility/serializers/test_v2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,11 @@ module CI
module TestVisibility
module Serializers
class TestV2 < TestV1
CONTENT_FIELDS = [
"trace_id", "span_id",
"name", "resource", "service",
"error", "start", "duration",
"meta", "metrics", "test_session_id",
"type" => "span_type"
].freeze
CONTENT_FIELDS = (["test_session_id"] + TestV1::CONTENT_FIELDS).freeze

CONTENT_MAP_SIZE = calculate_content_map_size(CONTENT_FIELDS)

REQUIRED_FIELDS = [
"test_session_id",
"trace_id",
"span_id",
"error",
"name",
"resource",
"start",
"duration"
].freeze
REQUIRED_FIELDS = (["test_session_id"] + TestV1::REQUIRED_FIELDS).freeze

def content_fields
CONTENT_FIELDS
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 @@ -81,7 +81,7 @@ def encode_traces(traces)
if spans.respond_to?(:filter_map)
spans.filter_map { |span| encode_span(trace, span) }
else
trace.spans.map { |span| encode_span(trace, span) }.reject(&:nil?)
spans.map { |span| encode_span(trace, span) }.reject(&:nil?)
end
end
end
Expand Down
Loading

0 comments on commit a5dd26f

Please sign in to comment.