-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
introduce concurrency-safe Span class and inherit service name from t…
…he active test session in #trace_test
- Loading branch information
1 parent
750b30a
commit 076d24c
Showing
11 changed files
with
234 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative "span" | ||
|
||
module Datadog | ||
module CI | ||
# Represents a single part of a test run that can be safely shared between threads. | ||
# Examples of shared objects are: TestSession, TestModule, TestSpan. | ||
# | ||
# @public_api | ||
class ConcurrentSpan < Span | ||
def initialize(tracer_span) | ||
super | ||
|
||
@mutex = Mutex.new | ||
end | ||
|
||
# Sets the status of the span to "pass". This method is thread-safe. | ||
# @return [void] | ||
def passed! | ||
synchronize { super } | ||
end | ||
|
||
# Sets the status of the span to "fail". This method is thread-safe. | ||
# @param [Exception] exception the exception that caused the test to fail. | ||
# @return [void] | ||
def failed!(exception: nil) | ||
synchronize { super } | ||
end | ||
|
||
# Sets the status of the span to "skip". This method is thread-safe. | ||
# @param [Exception] exception the exception that caused the test to fail. | ||
# @param [String] reason the reason why the test was skipped. | ||
# @return [void] | ||
def skipped!(exception: nil, reason: nil) | ||
synchronize { super } | ||
end | ||
|
||
# Gets tag value by key. This method is thread-safe. | ||
# @param [String] key the key of the tag. | ||
# @return [String] the value of the tag. | ||
def get_tag(key) | ||
synchronize { super } | ||
end | ||
|
||
# Sets tag value by key. This method is thread-safe. | ||
# @param [String] key the key of the tag. | ||
# @param [String] value the value of the tag. | ||
# @return [void] | ||
def set_tag(key, value) | ||
synchronize { super } | ||
end | ||
|
||
# Sets metric value by key. This method is thread-safe. | ||
# @param [String] key the key of the metric. | ||
# @param [Numeric] value the value of the metric. | ||
# @return [void] | ||
def set_metric(key, value) | ||
synchronize { super } | ||
end | ||
|
||
# Finishes the span. This method is thread-safe. | ||
# @return [void] | ||
def finish | ||
synchronize { super } | ||
end | ||
|
||
# Sets multiple tags at once. This method is thread-safe. | ||
# @param [Hash[String, String]] tags the tags to set. | ||
# @return [void] | ||
def set_tags(tags) | ||
synchronize { super } | ||
end | ||
|
||
def set_environment_runtime_tags | ||
synchronize { super } | ||
end | ||
|
||
def set_default_tags | ||
synchronize { super } | ||
end | ||
|
||
def synchronize | ||
@mutex.synchronize { yield } | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module Datadog | ||
module CI | ||
class ConcurrentSpan < Span | ||
@mutex: Thread::Mutex | ||
|
||
def initialize: (Datadog::Tracing::SpanOperation tracer_span) -> void | ||
def passed!: () -> void | ||
def failed!: (?exception: untyped?) -> void | ||
def skipped!: (?exception: untyped?, ?reason: String?) -> void | ||
def get_tag: (String key) -> untyped? | ||
def set_tag: (String key, untyped? value) -> void | ||
def set_metric: (String key, untyped value) -> void | ||
def finish: () -> void | ||
def set_tags: (Hash[untyped, untyped] tags) -> void | ||
|
||
def set_environment_runtime_tags: () -> void | ||
|
||
def set_default_tags: () -> void | ||
|
||
def synchronize: () { () -> untyped } -> untyped | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
module Datadog | ||
module CI | ||
class TestSession < Span | ||
@mutex: Thread::Mutex | ||
class TestSession < ConcurrentSpan | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters