-
Notifications
You must be signed in to change notification settings - Fork 381
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2932 from bravehager/bravehager/minitest
Showing
17 changed files
with
718 additions
and
1 deletion.
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
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,33 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative '../../../../tracing/contrib/configuration/settings' | ||
require_relative '../ext' | ||
|
||
module Datadog | ||
module CI | ||
module Contrib | ||
module Minitest | ||
module Configuration | ||
# Custom settings for the Minitest integration | ||
# TODO: mark as `@public_api` when GA | ||
class Settings < Datadog::Tracing::Contrib::Configuration::Settings | ||
option :enabled do |o| | ||
o.default { env_to_bool(Ext::ENV_ENABLED, true) } | ||
o.lazy | ||
end | ||
|
||
option :service_name do |o| | ||
o.default { Datadog.configuration.service_without_fallback || Ext::SERVICE_NAME } | ||
o.lazy | ||
end | ||
|
||
option :operation_name do |o| | ||
o.default { ENV.key?(Ext::ENV_OPERATION_NAME) ? ENV[Ext::ENV_OPERATION_NAME] : Ext::OPERATION_NAME } | ||
o.lazy | ||
end | ||
end | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# frozen_string_literal: true | ||
|
||
module Datadog | ||
module CI | ||
module Contrib | ||
module Minitest | ||
# Minitest integration constants | ||
# TODO: mark as `@public_api` when GA, to protect from resource and tag name changes. | ||
module Ext | ||
APP = 'minitest' | ||
ENV_ENABLED = 'DD_TRACE_MINITEST_ENABLED' | ||
ENV_OPERATION_NAME = 'DD_TRACE_MINITEST_OPERATION_NAME' | ||
FRAMEWORK = 'minitest' | ||
OPERATION_NAME = 'minitest.test' | ||
SERVICE_NAME = 'minitest' | ||
TEST_TYPE = 'test' | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative '../../../tracing/contrib/integration' | ||
|
||
require_relative 'configuration/settings' | ||
require_relative 'patcher' | ||
|
||
module Datadog | ||
module CI | ||
module Contrib | ||
module Minitest | ||
# Description of Minitest integration | ||
class Integration | ||
include Datadog::Tracing::Contrib::Integration | ||
|
||
MINIMUM_VERSION = Gem::Version.new('5.0.0') | ||
|
||
register_as :minitest, auto_patch: true | ||
|
||
def self.version | ||
Gem.loaded_specs['minitest'] \ | ||
&& Gem.loaded_specs['minitest'].version | ||
end | ||
|
||
def self.loaded? | ||
!defined?(::Minitest).nil? | ||
end | ||
|
||
def self.compatible? | ||
super && version >= MINIMUM_VERSION | ||
end | ||
|
||
# test environments should not auto instrument test libraries | ||
def auto_instrument? | ||
false | ||
end | ||
|
||
def new_configuration | ||
Configuration::Settings.new | ||
end | ||
|
||
def patcher | ||
Patcher | ||
end | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative '../../../tracing/contrib/patcher' | ||
require_relative 'test_helper' | ||
|
||
module Datadog | ||
module CI | ||
module Contrib | ||
module Minitest | ||
# Patcher enables patching of 'minitest' module. | ||
module Patcher | ||
include Datadog::Tracing::Contrib::Patcher | ||
|
||
module_function | ||
|
||
def target_version | ||
Integration.version | ||
end | ||
|
||
def patch | ||
::Minitest::Test.include(TestHelper) | ||
end | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative 'ext' | ||
|
||
module Datadog | ||
module CI | ||
module Contrib | ||
module Minitest | ||
# Instrument Minitest::Test | ||
module TestHelper | ||
def before_setup | ||
super | ||
return unless configuration[:enabled] | ||
|
||
test_name = "#{class_name}##{name}" | ||
|
||
path, = method(name).source_location | ||
test_suite = Pathname.new(path).relative_path_from(Pathname.pwd).to_s | ||
|
||
span = CI::Test.trace( | ||
configuration[:operation_name], | ||
{ | ||
span_options: { | ||
resource: test_name, | ||
service: configuration[:service_name], | ||
}, | ||
framework: Ext::FRAMEWORK, | ||
framework_version: CI::Contrib::Minitest::Integration.version.to_s, | ||
test_name: test_name, | ||
test_suite: test_suite, | ||
test_type: Ext::TEST_TYPE, | ||
}, | ||
) | ||
|
||
Thread.current[:_datadog_test_span] = span | ||
end | ||
|
||
def after_teardown | ||
span = Thread.current[:_datadog_test_span] | ||
return super unless span | ||
|
||
Thread.current[:_datadog_test_span] = nil | ||
|
||
case result_code | ||
when '.' | ||
CI::Test.passed!(span) | ||
when 'E', 'F' | ||
CI::Test.failed!(span, failure) | ||
when 'S' | ||
CI::Test.skipped!(span) | ||
span.set_tag(CI::Ext::Test::TAG_SKIP_REASON, failure.message) | ||
end | ||
|
||
span.finish | ||
|
||
super | ||
end | ||
|
||
private | ||
|
||
def configuration | ||
::Datadog.configuration.ci[:minitest] | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
12 changes: 12 additions & 0 deletions
12
sig/datadog/ci/contrib/minitest/configuration/settings.rbs
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,12 @@ | ||
module Datadog | ||
module CI | ||
module Contrib | ||
module Minitest | ||
module Configuration | ||
class Settings < Datadog::Tracing::Contrib::Configuration::Settings | ||
end | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module Datadog | ||
module CI | ||
module Contrib | ||
module Minitest | ||
module Ext | ||
APP: "minitest" | ||
|
||
ENV_ENABLED: "DD_TRACE_MINITEST_ENABLED" | ||
|
||
ENV_OPERATION_NAME: "DD_TRACE_MINITEST_OPERATION_NAME" | ||
|
||
FRAMEWORK: "minitest" | ||
|
||
OPERATION_NAME: "minitest.test" | ||
|
||
SERVICE_NAME: "minitest" | ||
|
||
TEST_TYPE: "test" | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
module Datadog | ||
module CI | ||
module Contrib | ||
module Minitest | ||
class Integration | ||
include Datadog::Tracing::Contrib::Integration | ||
|
||
MINIMUM_VERSION: untyped | ||
|
||
def self.version: () -> untyped | ||
|
||
def self.loaded?: () -> untyped | ||
|
||
def self.compatible?: () -> untyped | ||
def auto_instrument?: () -> false | ||
|
||
def new_configuration: () -> untyped | ||
|
||
def patcher: () -> untyped | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.