Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CIVIS-8333] get rid of span_type in tracer-related models #107

Merged
merged 1 commit into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions lib/datadog/ci.rb
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def start_test(test_name, test_suite_name, service: nil, tags: {})
# ```
# Remember that in this case, calling {Datadog::CI::Span#finish} is mandatory.
#
# @param [String] span_type custom, user-defined span type (for example "step" or "query").
# @param [String] type custom, user-defined span type (for example "step" or "query").
# @param [String] span_name the resource this span refers, or `test` if it's missing
# @param [Hash<String,String>] tags extra tags which should be added to the span.
# @return [Object] If a block is provided, returns the result of the block execution.
Expand All @@ -290,8 +290,8 @@ def start_test(test_name, test_suite_name, service: nil, tags: {})
# @yield Optional block where newly created {Datadog::CI::Span} captures the execution.
# @yieldparam [Datadog::CI::Span] ci_span the newly created and active [Datadog::CI::Span]
# @yieldparam [Datadog::CI::NullSpan] ci_span null object if CI visibility is disabled
def trace(span_type, span_name, tags: {}, &block)
recorder.trace(span_type, span_name, tags: tags, &block)
def trace(type, span_name, tags: {}, &block)
recorder.trace(type, span_name, tags: tags, &block)
end

# The active, unfinished custom span if it matches given type.
Expand All @@ -314,12 +314,12 @@ def trace(span_type, span_name, tags: {}, &block)
# step_span.finish()
# ```
#
# @param [String] span_type type of the span to retrieve (for example "step" or "query") that was provided to {.trace}
# @param [String] type type of the span to retrieve (for example "step" or "query") that was provided to {.trace}
# @return [Datadog::CI::Span] the active span
# @return [nil] if no span is active, or if the active span is not a custom span with given type
def active_span(span_type)
def active_span(type)
span = recorder.active_span
span if span && span.span_type == span_type
span if span && span.type == type
end

# The active, unfinished test span.
Expand Down
2 changes: 1 addition & 1 deletion lib/datadog/ci/null_span.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def name
def service
end

def span_type
def type
end

def passed!
Expand Down
2 changes: 1 addition & 1 deletion lib/datadog/ci/span.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def service
end

# @return [String] the type of the span (for example "test" or type that was provided to [Datadog::CI.trace]).
def span_type
def type
tracer_span.type
end

Expand Down
2 changes: 1 addition & 1 deletion lib/datadog/ci/test_visibility/null_recorder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def trace_test(test_name, test_suite_name, service: nil, tags: {}, &block)
skip_tracing(block)
end

def trace(span_type, span_name, tags: {}, &block)
def trace(type, span_name, tags: {}, &block)
skip_tracing(block)
end

Expand Down
8 changes: 4 additions & 4 deletions lib/datadog/ci/test_visibility/recorder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ def trace_test(test_name, test_suite_name, service: nil, tags: {}, &block)
end
end

def trace(span_type, span_name, tags: {}, &block)
def trace(type, span_name, tags: {}, &block)
span_options = build_span_options(
nil, # service name is completely optional for custom spans
span_type,
type,
{resource: span_name}
)

Expand Down Expand Up @@ -224,9 +224,9 @@ def build_span(tracer_span, tags)
span
end

def build_span_options(service, span_type, other_options = {})
def build_span_options(service, type, other_options = {})
other_options[:service] = service || @global_context.service
other_options[:type] = span_type
other_options[:type] = type

other_options
end
Expand Down
9 changes: 5 additions & 4 deletions lib/datadog/ci/test_visibility/serializers/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def to_msgpack(packer = nil)

packer.write_map_header(3)

write_field(packer, "type")
write_field(packer, "type", "event_type")
write_field(packer, "version")

packer.write("content")
Expand Down Expand Up @@ -119,9 +119,6 @@ def test_suite_id
to_integer(@span.get_tag(Ext::Test::TAG_TEST_SUITE_ID))
end

def type
end

def version
1
end
Expand All @@ -130,6 +127,10 @@ def span_type
@span.type
end

def event_type
"span"
end

def name
@span.name
end
Expand Down
2 changes: 1 addition & 1 deletion lib/datadog/ci/test_visibility/serializers/span.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def content_map_size
CONTENT_MAP_SIZE
end

def type
def event_type
"span"
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def content_map_size
CONTENT_MAP_SIZE
end

def type
def event_type
Ext::AppTypes::TYPE_TEST_MODULE
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def content_map_size
CONTENT_MAP_SIZE
end

def type
def event_type
Ext::AppTypes::TYPE_TEST_SESSION
end

Expand Down
2 changes: 1 addition & 1 deletion lib/datadog/ci/test_visibility/serializers/test_suite.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def content_map_size
CONTENT_MAP_SIZE
end

def type
def event_type
Ext::AppTypes::TYPE_TEST_SUITE
end

Expand Down
2 changes: 1 addition & 1 deletion lib/datadog/ci/test_visibility/serializers/test_v1.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def content_map_size
CONTENT_MAP_SIZE
end

def type
def event_type
Ext::AppTypes::TYPE_TEST
end

Expand Down
4 changes: 2 additions & 2 deletions sig/datadog/ci.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module Datadog

def self.start_test_suite: (String test_suite_name, ?service: String?, ?tags: Hash[untyped, untyped]) -> Datadog::CI::Span

def self.trace: (String span_type, String span_name, ?tags: Hash[untyped, untyped]) ?{ (Datadog::CI::Span span) -> untyped } -> untyped
def self.trace: (String type, String span_name, ?tags: Hash[untyped, untyped]) ?{ (Datadog::CI::Span span) -> untyped } -> untyped

def self.active_test_session: () -> Datadog::CI::TestSession?

Expand All @@ -20,7 +20,7 @@ module Datadog

def self.active_test_suite: (String test_suite_name) -> Datadog::CI::TestSuite?

def self.active_span: (String span_type) -> Datadog::CI::Span?
def self.active_span: (String type) -> Datadog::CI::Span?

def self.deactivate_test: (Datadog::CI::Test test) -> void

Expand Down
2 changes: 1 addition & 1 deletion sig/datadog/ci/null_span.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module Datadog

def service: () -> nil

def span_type: () -> nil
def type: () -> nil

def passed!: () -> nil

Expand Down
2 changes: 1 addition & 1 deletion sig/datadog/ci/span.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module Datadog

def finish: () -> void

def span_type: () -> String
def type: () -> String

def set_environment_runtime_tags: () -> void

Expand Down
2 changes: 1 addition & 1 deletion sig/datadog/ci/test_visibility/null_recorder.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module Datadog

def trace_test: (String span_name, String test_suite_name, ?service: String?, ?tags: Hash[untyped, untyped]) ?{ (Datadog::CI::Span span) -> untyped } -> untyped

def trace: (String span_type, String span_name, ?tags: Hash[untyped, untyped]) ?{ (Datadog::CI::Span span) -> untyped } -> untyped
def trace: (String type, String span_name, ?tags: Hash[untyped, untyped]) ?{ (Datadog::CI::Span span) -> untyped } -> untyped

def start_test_session: (?service: String?, ?tags: Hash[untyped, untyped]) -> Datadog::CI::Span

Expand Down
4 changes: 2 additions & 2 deletions sig/datadog/ci/test_visibility/recorder.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module Datadog

def trace_test: (String span_name, String test_suite_name, ?service: String?, ?tags: Hash[untyped, untyped]) ?{ (Datadog::CI::Span span) -> untyped } -> untyped

def trace: (String span_type, String span_name, ?tags: Hash[untyped, untyped]) ?{ (Datadog::CI::Span span) -> untyped } -> untyped
def trace: (String type, String span_name, ?tags: Hash[untyped, untyped]) ?{ (Datadog::CI::Span span) -> untyped } -> untyped

def start_test_session: (?service: String?, ?tags: Hash[untyped, untyped]) -> Datadog::CI::Span

Expand Down Expand Up @@ -60,7 +60,7 @@ module Datadog

def build_span: (Datadog::Tracing::SpanOperation tracer_span, Hash[untyped, untyped] tags) -> Datadog::CI::Span

def build_span_options: (String? service_name, String span_type, ?Hash[Symbol, untyped] other_options) -> Hash[Symbol, untyped]
def build_span_options: (String? service_name, String type, ?Hash[Symbol, untyped] other_options) -> Hash[Symbol, untyped]

def set_initial_tags: (Datadog::CI::Span ci_span, Hash[untyped, untyped] tags) -> void

Expand Down
6 changes: 3 additions & 3 deletions sig/datadog/ci/test_visibility/serializers/base.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ module Datadog

def test_suite_id: () -> Integer?

def type: () -> nil

def version: () -> 1

def span_type: () -> String
def type: () -> String

def event_type: () -> String

def name: () -> String

Expand Down
4 changes: 2 additions & 2 deletions spec/datadog/ci/null_span_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@
end
end

describe "#span_type" do
describe "#type" do
it "returns nil" do
expect(span.span_type).to be_nil
expect(span.type).to be_nil
end
end
end
4 changes: 2 additions & 2 deletions spec/datadog/ci/span_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,9 @@
end
end

describe "#span_type" do
describe "#type" do
it "returns 'test'" do
expect(span.span_type).to eq("test")
expect(span.type).to eq("test")
end
end

Expand Down
22 changes: 11 additions & 11 deletions spec/datadog/ci/test_visibility/recorder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,21 +87,21 @@
end

describe "#trace" do
let(:span_type) { "step" }
let(:type) { "step" }
let(:span_name) { "my test step" }
let(:tags) { {"test.framework" => "my-framework", "my.tag" => "my_value"} }

context "when given a block" do
before do
recorder.trace(span_type, span_name, tags: tags) do |span|
recorder.trace(type, span_name, tags: tags) do |span|
span.set_metric("my.metric", 42)
end
end
subject { span }

it "traces the block" do
expect(subject.resource).to eq(span_name)
expect(subject.type).to eq(span_type)
expect(subject.type).to eq(type)
end
end
end
Expand All @@ -111,21 +111,21 @@
include_context "CI mode activated"

describe "#trace" do
let(:span_type) { "step" }
let(:type) { "step" }
let(:span_name) { "my test step" }
let(:tags) { {"test.framework" => "my-framework", "my.tag" => "my_value"} }

context "when given a block" do
before do
recorder.trace(span_type, span_name, tags: tags) do |span|
recorder.trace(type, span_name, tags: tags) do |span|
span.set_metric("my.metric", 42)
end
end
subject { span }

it "traces the block" do
expect(subject.resource).to eq(span_name)
expect(subject.type).to eq(span_type)
expect(subject.type).to eq(type)
end

it "sets the custom metric correctly" do
Expand Down Expand Up @@ -158,7 +158,7 @@
subject.finish

expect(span.resource).to eq(span_name)
expect(span.type).to eq(span_type)
expect(span.type).to eq(type)
end

it_behaves_like "span with environment tags"
Expand Down Expand Up @@ -189,7 +189,7 @@
expect(subject.name).to eq(test_name)
expect(subject.service).to eq(test_service)
expect(subject.tracer_span.name).to eq(test_name)
expect(subject.span_type).to eq(Datadog::CI::Ext::AppTypes::TYPE_TEST)
expect(subject.type).to eq(Datadog::CI::Ext::AppTypes::TYPE_TEST)
end

it "sets the provided tags correctly" do
Expand Down Expand Up @@ -359,7 +359,7 @@
expect(subject).to be_kind_of(Datadog::CI::TestSession)
expect(subject.name).to eq(test_command)
expect(subject.service).to eq(service)
expect(subject.span_type).to eq(Datadog::CI::Ext::AppTypes::TYPE_TEST_SESSION)
expect(subject.type).to eq(Datadog::CI::Ext::AppTypes::TYPE_TEST_SESSION)
end

it "sets the test session id" do
Expand Down Expand Up @@ -395,7 +395,7 @@
expect(subject).to be_kind_of(Datadog::CI::TestModule)
expect(subject.name).to eq(module_name)
expect(subject.service).to eq(service)
expect(subject.span_type).to eq(Datadog::CI::Ext::AppTypes::TYPE_TEST_MODULE)
expect(subject.type).to eq(Datadog::CI::Ext::AppTypes::TYPE_TEST_MODULE)
end

it "sets the test module id" do
Expand Down Expand Up @@ -483,7 +483,7 @@
expect(subject).to be_kind_of(Datadog::CI::TestSuite)
expect(subject.name).to eq(suite_name)
expect(subject.service).to eq(session_service)
expect(subject.span_type).to eq(Datadog::CI::Ext::AppTypes::TYPE_TEST_SUITE)
expect(subject.type).to eq(Datadog::CI::Ext::AppTypes::TYPE_TEST_SUITE)
end

it "sets the provided tags correctly while inheriting some tags from the session" do
Expand Down
Loading