Skip to content

Commit

Permalink
add is_retry tag to event_finished event in telemetry
Browse files Browse the repository at this point in the history
  • Loading branch information
anmarchenko committed Aug 16, 2024
1 parent 840e1e4 commit d27d308
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/datadog/ci/ext/telemetry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ module Telemetry
TAG_IS_UNSUPPORTED_CI = "is_unsupported_ci"
TAG_BROWSER_DRIVER = "browser_driver"
TAG_IS_RUM = "is_rum"
TAG_IS_RETRY = "is_retry"
TAG_LIBRARY = "library"
TAG_ENDPOINT = "endpoint"
TAG_ERROR_TYPE = "error_type"
Expand Down
3 changes: 3 additions & 0 deletions lib/datadog/ci/test_visibility/telemetry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ def self.event_tags_from_span(span)
# codeowner tag
tags[Ext::Telemetry::TAG_HAS_CODEOWNER] = "true" if span.get_tag(Ext::Test::TAG_CODEOWNERS)

# set is_retry tag if span represents a retried test
tags[Ext::Telemetry::TAG_IS_RETRY] = "true" if span.get_tag(Ext::Test::TAG_IS_RETRY)

tags
end

Expand Down
2 changes: 2 additions & 0 deletions sig/datadog/ci/ext/telemetry.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ module Datadog

TAG_IS_RUM: "is_rum"

TAG_IS_RETRY: "is_retry"

TAG_LIBRARY: "library"

TAG_ENDPOINT: "endpoint"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
require_relative "helpers/helper"

max_flaky_test_failures = 4
flaky_test_executions = 0

Before do
Datadog::CI.active_test.set_tag("cucumber_before_hook_executed", "true")
end

After do
Datadog::CI.active_test.set_tag("cucumber_after_hook_executed", "true")
end

AfterStep do
Datadog::CI.active_test.set_tag("cucumber_after_step_hook_executed", "true")
end

Then "datadog" do
Helper.help?
end

Then "failure" do
expect(1 + 1).to eq(3)
end

Then "pending" do
pending("implementation")
end

Then "skip" do
skip_this_scenario
end

Then(/I add (-?\d+) and (-?\d+)/) do |n1, n2|
@res = n1.to_i + n2.to_i
end

Then(/the result should be (-?\d+)/) do |res|
expect(@res).to eq(res.to_i)
end

Then "flaky" do
if flaky_test_executions < max_flaky_test_failures
flaky_test_executions += 1
raise "Flaky test failure"
end
end
30 changes: 30 additions & 0 deletions spec/datadog/ci/test_visibility/telemetry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,36 @@

it { event_finished }
end

context "test span with retry" do
let(:span) do
Datadog::Tracing::SpanOperation.new(
"test_session",
type: Datadog::CI::Ext::AppTypes::TYPE_TEST,
tags: {
Datadog::CI::Ext::Test::TAG_FRAMEWORK => "rspec",
Datadog::CI::Ext::Environment::TAG_PROVIDER_NAME => "gha",
Datadog::CI::Ext::Test::TAG_CODEOWNERS => "@owner",
Datadog::CI::Ext::Test::TAG_IS_RUM_ACTIVE => "true",
Datadog::CI::Ext::Test::TAG_BROWSER_DRIVER => "selenium",
Datadog::CI::Ext::Test::TAG_IS_RETRY => "true"
}
)
end

let(:expected_tags) do
{
Datadog::CI::Ext::Telemetry::TAG_EVENT_TYPE => Datadog::CI::Ext::Telemetry::EventType::TEST,
Datadog::CI::Ext::Telemetry::TAG_TEST_FRAMEWORK => "rspec",
Datadog::CI::Ext::Telemetry::TAG_HAS_CODEOWNER => "true",
Datadog::CI::Ext::Telemetry::TAG_IS_RUM => "true",
Datadog::CI::Ext::Telemetry::TAG_BROWSER_DRIVER => "selenium",
Datadog::CI::Ext::Telemetry::TAG_IS_RETRY => "true"
}
end

it { event_finished }
end
end

describe ".test_session_started" do
Expand Down

0 comments on commit d27d308

Please sign in to comment.