Skip to content

Commit

Permalink
provide source file and source start tags from rspec instrumentation
Browse files Browse the repository at this point in the history
  • Loading branch information
anmarchenko committed Jan 4, 2024
1 parent b308a62 commit 998ff23
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
5 changes: 4 additions & 1 deletion lib/datadog/ci/contrib/rspec/example.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require_relative "../../ext/test"
require_relative "../../utils/git"
require_relative "ext"

module Datadog
Expand Down Expand Up @@ -30,7 +31,9 @@ def run(example_group_instance, reporter)
tags: {
CI::Ext::Test::TAG_FRAMEWORK => Ext::FRAMEWORK,
CI::Ext::Test::TAG_FRAMEWORK_VERSION => CI::Contrib::RSpec::Integration.version.to_s,
CI::Ext::Test::TAG_TYPE => CI::Ext::Test::TEST_TYPE
CI::Ext::Test::TAG_TYPE => CI::Ext::Test::TEST_TYPE,
CI::Ext::Test::TAG_SOURCE_FILE => Utils::Git.relative_to_root(metadata[:file_path]),
CI::Ext::Test::TAG_SOURCE_START => metadata[:line_number].to_s
},
service: configuration[:service_name]
) do |test_span|
Expand Down
1 change: 0 additions & 1 deletion lib/datadog/ci/ext/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ module Test
TAG_COMMAND = "test.command"
TAG_SOURCE_FILE = "test.source.file"
TAG_SOURCE_START = "test.source.start"
TAG_SOURCE_END = "test.source.end"

TEST_TYPE = "test"

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

TAG_SOURCE_START: String

TAG_SOURCE_END: String

TAG_TEST_SESSION_ID: String

TAG_TEST_MODULE_ID: String
Expand Down
25 changes: 25 additions & 0 deletions spec/datadog/ci/contrib/rspec/instrumentation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ def with_new_rspec_environment
Datadog::CI::Contrib::RSpec::Integration.version.to_s
)
expect(first_test_span.get_tag(Datadog::CI::Ext::Test::TAG_STATUS)).to eq(Datadog::CI::Ext::Test::Status::PASS)

expect(first_test_span.get_tag(Datadog::CI::Ext::Test::TAG_SOURCE_FILE)).to eq(
"spec/datadog/ci/contrib/rspec/instrumentation_spec.rb"
)
expect(first_test_span.get_tag(Datadog::CI::Ext::Test::TAG_SOURCE_START)).to eq("26")
end

it "creates spans for several examples" do
Expand Down Expand Up @@ -198,6 +203,26 @@ def expect_failure
end
end

context "with git root changed" do
before do
expect(Datadog::CI::Utils::Git).to receive(:root).and_return("#{Dir.pwd}/spec")
end

it "provides source file path relative to git root" do
with_new_rspec_environment do
RSpec.describe "some test" do
it "foo" do
# DO NOTHING
end
end.tap(&:run)
end

expect(first_test_span.get_tag(Datadog::CI::Ext::Test::TAG_SOURCE_FILE)).to eq(
"datadog/ci/contrib/rspec/instrumentation_spec.rb"
)
end
end

context "with rspec runner" do
def devnull
File.new("/dev/null", "w")
Expand Down

0 comments on commit 998ff23

Please sign in to comment.