Skip to content

Commit

Permalink
produce manual_api_events metric when public API is used
Browse files Browse the repository at this point in the history
  • Loading branch information
anmarchenko committed Jul 26, 2024
1 parent 202e792 commit 3e67e2c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
28 changes: 28 additions & 0 deletions lib/datadog/ci.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ class << self
# @return [Datadog::CI::TestSession] the active, running {Datadog::CI::TestSession}.
# @return [nil] if test suite level visibility is disabled or CI mode is disabled.
def start_test_session(service: Utils::Configuration.fetch_service_name("test"), tags: {})
Utils::Telemetry.inc(
Ext::Telemetry::METRIC_MANUAL_API_EVENTS,
1,
{Ext::Telemetry::TAG_EVENT_TYPE => Ext::Telemetry::EventType::SESSION}
)
test_visibility.start_test_session(service: service, tags: tags)
end

Expand Down Expand Up @@ -95,6 +100,12 @@ def active_test_session
# @return [Datadog::CI::TestModule] the active, running {Datadog::CI::TestModule}.
# @return [nil] if test suite level visibility is disabled or CI mode is disabled.
def start_test_module(test_module_name, service: nil, tags: {})
Utils::Telemetry.inc(
Ext::Telemetry::METRIC_MANUAL_API_EVENTS,
1,
{Ext::Telemetry::TAG_EVENT_TYPE => Ext::Telemetry::EventType::MODULE}
)

test_visibility.start_test_module(test_module_name, service: service, tags: tags)
end

Expand Down Expand Up @@ -147,6 +158,12 @@ def active_test_module
# @return [Datadog::CI::TestSuite] the active, running {Datadog::CI::TestSuite}.
# @return [nil] if test suite level visibility is disabled or CI mode is disabled.
def start_test_suite(test_suite_name, service: nil, tags: {})
Utils::Telemetry.inc(
Ext::Telemetry::METRIC_MANUAL_API_EVENTS,
1,
{Ext::Telemetry::TAG_EVENT_TYPE => Ext::Telemetry::EventType::SUITE}
)

test_visibility.start_test_suite(test_suite_name, service: service, tags: tags)
end

Expand Down Expand Up @@ -224,6 +241,12 @@ def active_test_suite(test_suite_name)
# @yieldparam [Datadog::CI::Test] ci_test the newly created and active [Datadog::CI::Test]
# @yieldparam [nil] if CI mode is disabled
def trace_test(test_name, test_suite_name, service: nil, tags: {}, &block)
Utils::Telemetry.inc(
Ext::Telemetry::METRIC_MANUAL_API_EVENTS,
1,
{Ext::Telemetry::TAG_EVENT_TYPE => Ext::Telemetry::EventType::TEST}
)

test_visibility.trace_test(test_name, test_suite_name, service: service, tags: tags, &block)
end

Expand All @@ -250,6 +273,11 @@ def trace_test(test_name, test_suite_name, service: nil, tags: {}, &block)
# @return [Datadog::CI::Test] the active, unfinished {Datadog::CI::Test}.
# @return [nil] if CI mode is disabled.
def start_test(test_name, test_suite_name, service: nil, tags: {})
Utils::Telemetry.inc(
Ext::Telemetry::METRIC_MANUAL_API_EVENTS,
1,
{Ext::Telemetry::TAG_EVENT_TYPE => Ext::Telemetry::EventType::TEST}
)
test_visibility.trace_test(test_name, test_suite_name, service: service, tags: tags)
end

Expand Down
11 changes: 11 additions & 0 deletions spec/datadog/ci_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
RSpec.describe Datadog::CI do
context "with test visibility stubbed" do
include_context "Telemetry spy"
let(:test_visibility) { instance_double(Datadog::CI::TestVisibility::Component) }

before do
Expand All @@ -26,6 +27,8 @@
end

it { is_expected.to be(ci_test) }

it_behaves_like "emits telemetry metric", :inc, "manual_api_events", 1
end

describe "::start_test" do
Expand All @@ -47,6 +50,8 @@
end

it { is_expected.to be(ci_test) }

it_behaves_like "emits telemetry metric", :inc, "manual_api_events", 1
end

describe "::trace" do
Expand Down Expand Up @@ -120,6 +125,8 @@
end

it { is_expected.to be(ci_test_session) }

it_behaves_like "emits telemetry metric", :inc, "manual_api_events", 1
end

context "when service is not provided" do
Expand Down Expand Up @@ -162,6 +169,8 @@
end

it { is_expected.to be(ci_test_module) }

it_behaves_like "emits telemetry metric", :inc, "manual_api_events", 1
end

describe "::active_test_module" do
Expand All @@ -188,6 +197,8 @@
end

it { is_expected.to be(ci_test_suite) }

it_behaves_like "emits telemetry metric", :inc, "manual_api_events", 1
end

describe "::active_test_suite" do
Expand Down

0 comments on commit 3e67e2c

Please sign in to comment.