datadog-ci 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +30 -0
- data/LICENSE +6 -0
- data/LICENSE-3rdparty.csv +2 -0
- data/LICENSE.Apache +200 -0
- data/LICENSE.BSD3 +24 -0
- data/NOTICE +4 -0
- data/README.md +125 -0
- data/lib/datadog/ci/configuration/components.rb +32 -0
- data/lib/datadog/ci/configuration/settings.rb +51 -0
- data/lib/datadog/ci/contrib/cucumber/configuration/settings.rb +36 -0
- data/lib/datadog/ci/contrib/cucumber/ext.rb +22 -0
- data/lib/datadog/ci/contrib/cucumber/formatter.rb +94 -0
- data/lib/datadog/ci/contrib/cucumber/instrumentation.rb +28 -0
- data/lib/datadog/ci/contrib/cucumber/integration.rb +47 -0
- data/lib/datadog/ci/contrib/cucumber/patcher.rb +27 -0
- data/lib/datadog/ci/contrib/minitest/configuration/settings.rb +36 -0
- data/lib/datadog/ci/contrib/minitest/ext.rb +21 -0
- data/lib/datadog/ci/contrib/minitest/hooks.rb +66 -0
- data/lib/datadog/ci/contrib/minitest/integration.rb +46 -0
- data/lib/datadog/ci/contrib/minitest/patcher.rb +26 -0
- data/lib/datadog/ci/contrib/rspec/configuration/settings.rb +36 -0
- data/lib/datadog/ci/contrib/rspec/example.rb +70 -0
- data/lib/datadog/ci/contrib/rspec/ext.rb +21 -0
- data/lib/datadog/ci/contrib/rspec/integration.rb +50 -0
- data/lib/datadog/ci/contrib/rspec/patcher.rb +27 -0
- data/lib/datadog/ci/ext/app_types.rb +11 -0
- data/lib/datadog/ci/ext/environment/extractor.rb +101 -0
- data/lib/datadog/ci/ext/environment/providers/appveyor.rb +98 -0
- data/lib/datadog/ci/ext/environment/providers/azure.rb +109 -0
- data/lib/datadog/ci/ext/environment/providers/base.rb +115 -0
- data/lib/datadog/ci/ext/environment/providers/bitbucket.rb +69 -0
- data/lib/datadog/ci/ext/environment/providers/bitrise.rb +77 -0
- data/lib/datadog/ci/ext/environment/providers/buddy.rb +69 -0
- data/lib/datadog/ci/ext/environment/providers/buildkite.rb +95 -0
- data/lib/datadog/ci/ext/environment/providers/circleci.rb +82 -0
- data/lib/datadog/ci/ext/environment/providers/codefresh.rb +49 -0
- data/lib/datadog/ci/ext/environment/providers/github_actions.rb +76 -0
- data/lib/datadog/ci/ext/environment/providers/gitlab.rb +119 -0
- data/lib/datadog/ci/ext/environment/providers/jenkins.rb +74 -0
- data/lib/datadog/ci/ext/environment/providers/local_git.rb +170 -0
- data/lib/datadog/ci/ext/environment/providers/teamcity.rb +29 -0
- data/lib/datadog/ci/ext/environment/providers/travis.rb +65 -0
- data/lib/datadog/ci/ext/environment/providers/user_defined_tags.rb +62 -0
- data/lib/datadog/ci/ext/environment/providers.rb +52 -0
- data/lib/datadog/ci/ext/environment.rb +82 -0
- data/lib/datadog/ci/ext/git.rb +37 -0
- data/lib/datadog/ci/ext/settings.rb +12 -0
- data/lib/datadog/ci/ext/test.rb +37 -0
- data/lib/datadog/ci/extensions.rb +19 -0
- data/lib/datadog/ci/flush.rb +38 -0
- data/lib/datadog/ci/test.rb +82 -0
- data/lib/datadog/ci/utils/git.rb +22 -0
- data/lib/datadog/ci/version.rb +28 -0
- data/lib/datadog/ci.rb +24 -0
- data/sig/datadog/ci/configuration/components.rbs +11 -0
- data/sig/datadog/ci/configuration/settings.rbs +14 -0
- data/sig/datadog/ci/contrib/cucumber/configuration/settings.rbs +12 -0
- data/sig/datadog/ci/contrib/cucumber/ext.rbs +25 -0
- data/sig/datadog/ci/contrib/cucumber/formatter.rbs +35 -0
- data/sig/datadog/ci/contrib/cucumber/instrumentation.rbs +16 -0
- data/sig/datadog/ci/contrib/cucumber/integration.rbs +25 -0
- data/sig/datadog/ci/contrib/cucumber/patcher.rbs +15 -0
- data/sig/datadog/ci/contrib/minitest/configuration/settings.rbs +12 -0
- data/sig/datadog/ci/contrib/minitest/ext.rbs +23 -0
- data/sig/datadog/ci/contrib/minitest/hooks.rbs +19 -0
- data/sig/datadog/ci/contrib/minitest/integration.rbs +25 -0
- data/sig/datadog/ci/contrib/minitest/patcher.rbs +15 -0
- data/sig/datadog/ci/contrib/rspec/configuration/settings.rbs +12 -0
- data/sig/datadog/ci/contrib/rspec/example.rbs +20 -0
- data/sig/datadog/ci/contrib/rspec/ext.rbs +23 -0
- data/sig/datadog/ci/contrib/rspec/integration.rbs +25 -0
- data/sig/datadog/ci/contrib/rspec/patcher.rbs +15 -0
- data/sig/datadog/ci/ext/app_types.rbs +9 -0
- data/sig/datadog/ci/ext/environment/extractor.rbs +27 -0
- data/sig/datadog/ci/ext/environment/providers/appveyor.rbs +48 -0
- data/sig/datadog/ci/ext/environment/providers/azure.rbs +56 -0
- data/sig/datadog/ci/ext/environment/providers/base.rbs +69 -0
- data/sig/datadog/ci/ext/environment/providers/bitbucket.rbs +37 -0
- data/sig/datadog/ci/ext/environment/providers/bitrise.rbs +41 -0
- data/sig/datadog/ci/ext/environment/providers/buddy.rbs +37 -0
- data/sig/datadog/ci/ext/environment/providers/buildkite.rbs +45 -0
- data/sig/datadog/ci/ext/environment/providers/circleci.rbs +41 -0
- data/sig/datadog/ci/ext/environment/providers/codefresh.rbs +25 -0
- data/sig/datadog/ci/ext/environment/providers/github_actions.rbs +37 -0
- data/sig/datadog/ci/ext/environment/providers/gitlab.rbs +57 -0
- data/sig/datadog/ci/ext/environment/providers/jenkins.rbs +35 -0
- data/sig/datadog/ci/ext/environment/providers/local_git.rbs +66 -0
- data/sig/datadog/ci/ext/environment/providers/teamcity.rbs +17 -0
- data/sig/datadog/ci/ext/environment/providers/travis.rbs +35 -0
- data/sig/datadog/ci/ext/environment/providers/user_defined_tags.rbs +33 -0
- data/sig/datadog/ci/ext/environment/providers.rbs +13 -0
- data/sig/datadog/ci/ext/environment.rbs +44 -0
- data/sig/datadog/ci/ext/git.rbs +53 -0
- data/sig/datadog/ci/ext/settings.rbs +9 -0
- data/sig/datadog/ci/ext/test.rbs +43 -0
- data/sig/datadog/ci/extensions.rbs +7 -0
- data/sig/datadog/ci/flush.rbs +15 -0
- data/sig/datadog/ci/test.rbs +18 -0
- data/sig/datadog/ci/utils/git.rbs +11 -0
- data/sig/datadog/ci/version.rbs +16 -0
- data/sig/datadog/ci.rbs +7 -0
- metadata +154 -0
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "configuration/settings"
|
4
|
+
require_relative "patcher"
|
5
|
+
|
6
|
+
module Datadog
|
7
|
+
module CI
|
8
|
+
module Contrib
|
9
|
+
module Cucumber
|
10
|
+
# Description of Cucumber integration
|
11
|
+
class Integration
|
12
|
+
include Datadog::Tracing::Contrib::Integration
|
13
|
+
|
14
|
+
MINIMUM_VERSION = Gem::Version.new("3.0.0")
|
15
|
+
|
16
|
+
register_as :cucumber, auto_patch: true
|
17
|
+
|
18
|
+
def self.version
|
19
|
+
Gem.loaded_specs["cucumber"] \
|
20
|
+
&& Gem.loaded_specs["cucumber"].version
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.loaded?
|
24
|
+
!defined?(::Cucumber).nil? && !defined?(::Cucumber::Runtime).nil?
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.compatible?
|
28
|
+
super && version >= MINIMUM_VERSION
|
29
|
+
end
|
30
|
+
|
31
|
+
# test environments should not auto instrument test libraries
|
32
|
+
def auto_instrument?
|
33
|
+
false
|
34
|
+
end
|
35
|
+
|
36
|
+
def new_configuration
|
37
|
+
Configuration::Settings.new
|
38
|
+
end
|
39
|
+
|
40
|
+
def patcher
|
41
|
+
Patcher
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "datadog/tracing/contrib/patcher"
|
4
|
+
require_relative "instrumentation"
|
5
|
+
|
6
|
+
module Datadog
|
7
|
+
module CI
|
8
|
+
module Contrib
|
9
|
+
module Cucumber
|
10
|
+
# Patcher enables patching of 'cucumber' module.
|
11
|
+
module Patcher
|
12
|
+
include Datadog::Tracing::Contrib::Patcher
|
13
|
+
|
14
|
+
module_function
|
15
|
+
|
16
|
+
def target_version
|
17
|
+
Integration.version
|
18
|
+
end
|
19
|
+
|
20
|
+
def patch
|
21
|
+
::Cucumber::Runtime.include(Instrumentation)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "../ext"
|
4
|
+
|
5
|
+
require "datadog/tracing/contrib/configuration/settings"
|
6
|
+
|
7
|
+
module Datadog
|
8
|
+
module CI
|
9
|
+
module Contrib
|
10
|
+
module Minitest
|
11
|
+
module Configuration
|
12
|
+
# Custom settings for the Minitest integration
|
13
|
+
# TODO: mark as `@public_api` when GA
|
14
|
+
class Settings < Datadog::Tracing::Contrib::Configuration::Settings
|
15
|
+
option :enabled do |o|
|
16
|
+
o.type :bool
|
17
|
+
o.env Ext::ENV_ENABLED
|
18
|
+
o.default true
|
19
|
+
end
|
20
|
+
|
21
|
+
option :service_name do |o|
|
22
|
+
o.type :string
|
23
|
+
o.default { Datadog.configuration.service_without_fallback || Ext::SERVICE_NAME }
|
24
|
+
end
|
25
|
+
|
26
|
+
option :operation_name do |o|
|
27
|
+
o.type :string
|
28
|
+
o.env Ext::ENV_OPERATION_NAME
|
29
|
+
o.default Ext::OPERATION_NAME
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Datadog
|
4
|
+
module CI
|
5
|
+
module Contrib
|
6
|
+
module Minitest
|
7
|
+
# Minitest integration constants
|
8
|
+
# TODO: mark as `@public_api` when GA, to protect from resource and tag name changes.
|
9
|
+
module Ext
|
10
|
+
APP = "minitest"
|
11
|
+
ENV_ENABLED = "DD_TRACE_MINITEST_ENABLED"
|
12
|
+
ENV_OPERATION_NAME = "DD_TRACE_MINITEST_OPERATION_NAME"
|
13
|
+
FRAMEWORK = "minitest"
|
14
|
+
OPERATION_NAME = "minitest.test"
|
15
|
+
SERVICE_NAME = "minitest"
|
16
|
+
TEST_TYPE = "test"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Datadog
|
4
|
+
module CI
|
5
|
+
module Contrib
|
6
|
+
module Minitest
|
7
|
+
# Lifecycle hooks to instrument Minitest::Test
|
8
|
+
module Hooks
|
9
|
+
def before_setup
|
10
|
+
super
|
11
|
+
return unless configuration[:enabled]
|
12
|
+
|
13
|
+
test_name = "#{class_name}##{name}"
|
14
|
+
|
15
|
+
path, = method(name).source_location
|
16
|
+
test_suite = Pathname.new(path.to_s).relative_path_from(Pathname.pwd).to_s
|
17
|
+
|
18
|
+
span = CI::Test.trace(
|
19
|
+
configuration[:operation_name],
|
20
|
+
{
|
21
|
+
span_options: {
|
22
|
+
resource: test_name,
|
23
|
+
service: configuration[:service_name]
|
24
|
+
},
|
25
|
+
framework: Ext::FRAMEWORK,
|
26
|
+
framework_version: CI::Contrib::Minitest::Integration.version.to_s,
|
27
|
+
test_name: test_name,
|
28
|
+
test_suite: test_suite,
|
29
|
+
test_type: Ext::TEST_TYPE
|
30
|
+
}
|
31
|
+
)
|
32
|
+
|
33
|
+
Thread.current[:_datadog_test_span] = span
|
34
|
+
end
|
35
|
+
|
36
|
+
def after_teardown
|
37
|
+
span = Thread.current[:_datadog_test_span]
|
38
|
+
return super unless span
|
39
|
+
|
40
|
+
Thread.current[:_datadog_test_span] = nil
|
41
|
+
|
42
|
+
case result_code
|
43
|
+
when "."
|
44
|
+
CI::Test.passed!(span)
|
45
|
+
when "E", "F"
|
46
|
+
CI::Test.failed!(span, failure)
|
47
|
+
when "S"
|
48
|
+
CI::Test.skipped!(span)
|
49
|
+
span.set_tag(CI::Ext::Test::TAG_SKIP_REASON, failure.message)
|
50
|
+
end
|
51
|
+
|
52
|
+
span.finish
|
53
|
+
|
54
|
+
super
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def configuration
|
60
|
+
::Datadog.configuration.ci[:minitest]
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "configuration/settings"
|
4
|
+
require_relative "patcher"
|
5
|
+
|
6
|
+
module Datadog
|
7
|
+
module CI
|
8
|
+
module Contrib
|
9
|
+
module Minitest
|
10
|
+
# Description of Minitest integration
|
11
|
+
class Integration
|
12
|
+
include Datadog::Tracing::Contrib::Integration
|
13
|
+
|
14
|
+
MINIMUM_VERSION = Gem::Version.new("5.0.0")
|
15
|
+
|
16
|
+
register_as :minitest, auto_patch: true
|
17
|
+
|
18
|
+
def self.version
|
19
|
+
Gem.loaded_specs["minitest"] && Gem.loaded_specs["minitest"].version
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.loaded?
|
23
|
+
!defined?(::Minitest).nil?
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.compatible?
|
27
|
+
super && version >= MINIMUM_VERSION
|
28
|
+
end
|
29
|
+
|
30
|
+
# test environments should not auto instrument test libraries
|
31
|
+
def auto_instrument?
|
32
|
+
false
|
33
|
+
end
|
34
|
+
|
35
|
+
def new_configuration
|
36
|
+
Configuration::Settings.new
|
37
|
+
end
|
38
|
+
|
39
|
+
def patcher
|
40
|
+
Patcher
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "hooks"
|
4
|
+
|
5
|
+
module Datadog
|
6
|
+
module CI
|
7
|
+
module Contrib
|
8
|
+
module Minitest
|
9
|
+
# Patcher enables patching of 'minitest' module.
|
10
|
+
module Patcher
|
11
|
+
include Datadog::Tracing::Contrib::Patcher
|
12
|
+
|
13
|
+
module_function
|
14
|
+
|
15
|
+
def target_version
|
16
|
+
Integration.version
|
17
|
+
end
|
18
|
+
|
19
|
+
def patch
|
20
|
+
::Minitest::Test.include(Hooks)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "../ext"
|
4
|
+
|
5
|
+
require "datadog/tracing/contrib/configuration/settings"
|
6
|
+
|
7
|
+
module Datadog
|
8
|
+
module CI
|
9
|
+
module Contrib
|
10
|
+
module RSpec
|
11
|
+
module Configuration
|
12
|
+
# Custom settings for the RSpec integration
|
13
|
+
# TODO: mark as `@public_api` when GA
|
14
|
+
class Settings < Datadog::Tracing::Contrib::Configuration::Settings
|
15
|
+
option :enabled do |o|
|
16
|
+
o.type :bool
|
17
|
+
o.env Ext::ENV_ENABLED
|
18
|
+
o.default true
|
19
|
+
end
|
20
|
+
|
21
|
+
option :service_name do |o|
|
22
|
+
o.type :string
|
23
|
+
o.default { Datadog.configuration.service_without_fallback || Ext::SERVICE_NAME }
|
24
|
+
end
|
25
|
+
|
26
|
+
option :operation_name do |o|
|
27
|
+
o.type :string
|
28
|
+
o.env Ext::ENV_OPERATION_NAME
|
29
|
+
o.default Ext::OPERATION_NAME
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "../../test"
|
4
|
+
|
5
|
+
require_relative "../../ext/app_types"
|
6
|
+
require_relative "../../ext/environment"
|
7
|
+
require_relative "../../ext/test"
|
8
|
+
require_relative "ext"
|
9
|
+
|
10
|
+
module Datadog
|
11
|
+
module CI
|
12
|
+
module Contrib
|
13
|
+
module RSpec
|
14
|
+
# Instrument RSpec::Core::Example
|
15
|
+
module Example
|
16
|
+
def self.included(base)
|
17
|
+
base.prepend(InstanceMethods)
|
18
|
+
end
|
19
|
+
|
20
|
+
# Instance methods for configuration
|
21
|
+
module InstanceMethods
|
22
|
+
def run(example_group_instance, reporter)
|
23
|
+
return super unless configuration[:enabled]
|
24
|
+
|
25
|
+
test_name = full_description.strip
|
26
|
+
if metadata[:description].empty?
|
27
|
+
# for unnamed it blocks this appends something like "example at ./spec/some_spec.rb:10"
|
28
|
+
test_name += " #{description}"
|
29
|
+
end
|
30
|
+
|
31
|
+
CI::Test.trace(
|
32
|
+
configuration[:operation_name],
|
33
|
+
{
|
34
|
+
span_options: {
|
35
|
+
resource: test_name,
|
36
|
+
service: configuration[:service_name]
|
37
|
+
},
|
38
|
+
framework: Ext::FRAMEWORK,
|
39
|
+
framework_version: CI::Contrib::RSpec::Integration.version.to_s,
|
40
|
+
test_name: test_name,
|
41
|
+
test_suite: metadata[:example_group][:file_path],
|
42
|
+
test_type: Ext::TEST_TYPE
|
43
|
+
}
|
44
|
+
) do |span|
|
45
|
+
result = super
|
46
|
+
|
47
|
+
case execution_result.status
|
48
|
+
when :passed
|
49
|
+
CI::Test.passed!(span)
|
50
|
+
when :failed
|
51
|
+
CI::Test.failed!(span, execution_result.exception)
|
52
|
+
else
|
53
|
+
CI::Test.skipped!(span, execution_result.exception) if execution_result.example_skipped?
|
54
|
+
end
|
55
|
+
|
56
|
+
result
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
def configuration
|
63
|
+
Datadog.configuration.ci[:rspec]
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Datadog
|
4
|
+
module CI
|
5
|
+
module Contrib
|
6
|
+
module RSpec
|
7
|
+
# RSpec integration constants
|
8
|
+
# TODO: mark as `@public_api` when GA, to protect from resource and tag name changes.
|
9
|
+
module Ext
|
10
|
+
APP = "rspec"
|
11
|
+
ENV_ENABLED = "DD_TRACE_RSPEC_ENABLED"
|
12
|
+
ENV_OPERATION_NAME = "DD_TRACE_RSPEC_OPERATION_NAME"
|
13
|
+
FRAMEWORK = "rspec"
|
14
|
+
OPERATION_NAME = "rspec.example"
|
15
|
+
SERVICE_NAME = "rspec"
|
16
|
+
TEST_TYPE = "test"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "datadog/tracing/contrib/integration"
|
4
|
+
|
5
|
+
require_relative "configuration/settings"
|
6
|
+
require_relative "patcher"
|
7
|
+
|
8
|
+
module Datadog
|
9
|
+
module CI
|
10
|
+
module Contrib
|
11
|
+
module RSpec
|
12
|
+
# Description of RSpec integration
|
13
|
+
class Integration
|
14
|
+
include Datadog::Tracing::Contrib::Integration
|
15
|
+
|
16
|
+
MINIMUM_VERSION = Gem::Version.new("3.0.0")
|
17
|
+
|
18
|
+
register_as :rspec, auto_patch: true
|
19
|
+
|
20
|
+
def self.version
|
21
|
+
Gem.loaded_specs["rspec-core"] \
|
22
|
+
&& Gem.loaded_specs["rspec-core"].version
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.loaded?
|
26
|
+
!defined?(::RSpec).nil? && !defined?(::RSpec::Core).nil? && \
|
27
|
+
!defined?(::RSpec::Core::Example).nil?
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.compatible?
|
31
|
+
super && version >= MINIMUM_VERSION
|
32
|
+
end
|
33
|
+
|
34
|
+
# test environments should not auto instrument test libraries
|
35
|
+
def auto_instrument?
|
36
|
+
false
|
37
|
+
end
|
38
|
+
|
39
|
+
def new_configuration
|
40
|
+
Configuration::Settings.new
|
41
|
+
end
|
42
|
+
|
43
|
+
def patcher
|
44
|
+
Patcher
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "datadog/tracing/contrib/patcher"
|
4
|
+
require_relative "example"
|
5
|
+
|
6
|
+
module Datadog
|
7
|
+
module CI
|
8
|
+
module Contrib
|
9
|
+
module RSpec
|
10
|
+
# Patcher enables patching of 'rspec' module.
|
11
|
+
module Patcher
|
12
|
+
include Datadog::Tracing::Contrib::Patcher
|
13
|
+
|
14
|
+
module_function
|
15
|
+
|
16
|
+
def target_version
|
17
|
+
Integration.version
|
18
|
+
end
|
19
|
+
|
20
|
+
def patch
|
21
|
+
::RSpec::Core::Example.include(Example)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "../environment"
|
4
|
+
require_relative "../git"
|
5
|
+
require_relative "../../utils/git"
|
6
|
+
require_relative "providers"
|
7
|
+
|
8
|
+
module Datadog
|
9
|
+
module CI
|
10
|
+
module Ext
|
11
|
+
module Environment
|
12
|
+
# Provider is a specific CI provider like Azure Pipelines, Github Actions, Gitlab CI, etc
|
13
|
+
# Extractor is responsible for detecting where pipeline is being executed based on environment vars
|
14
|
+
# and return the specific extractor that is able to return environment- and git-specific tags
|
15
|
+
class Extractor
|
16
|
+
def initialize(env, provider_klass: nil)
|
17
|
+
@env = env
|
18
|
+
@provider = provider_klass ? provider_klass.new(env) : Providers.for_environment(env)
|
19
|
+
end
|
20
|
+
|
21
|
+
def tags
|
22
|
+
return @tags if defined?(@tags)
|
23
|
+
|
24
|
+
@tags = {
|
25
|
+
Environment::TAG_JOB_NAME => @provider.job_name,
|
26
|
+
Environment::TAG_JOB_URL => @provider.job_url,
|
27
|
+
Environment::TAG_PIPELINE_ID => @provider.pipeline_id,
|
28
|
+
Environment::TAG_PIPELINE_NAME => @provider.pipeline_name,
|
29
|
+
Environment::TAG_PIPELINE_NUMBER => @provider.pipeline_number,
|
30
|
+
Environment::TAG_PIPELINE_URL => @provider.pipeline_url,
|
31
|
+
Environment::TAG_PROVIDER_NAME => @provider.provider_name,
|
32
|
+
Environment::TAG_STAGE_NAME => @provider.stage_name,
|
33
|
+
Environment::TAG_WORKSPACE_PATH => @provider.workspace_path,
|
34
|
+
Environment::TAG_NODE_LABELS => @provider.node_labels,
|
35
|
+
Environment::TAG_NODE_NAME => @provider.node_name,
|
36
|
+
Environment::TAG_CI_ENV_VARS => @provider.ci_env_vars,
|
37
|
+
|
38
|
+
Git::TAG_BRANCH => @provider.git_branch,
|
39
|
+
Git::TAG_REPOSITORY_URL => @provider.git_repository_url,
|
40
|
+
Git::TAG_TAG => @provider.git_tag,
|
41
|
+
Git::TAG_COMMIT_AUTHOR_DATE => @provider.git_commit_author_date,
|
42
|
+
Git::TAG_COMMIT_AUTHOR_EMAIL => @provider.git_commit_author_email,
|
43
|
+
Git::TAG_COMMIT_AUTHOR_NAME => @provider.git_commit_author_name,
|
44
|
+
Git::TAG_COMMIT_COMMITTER_DATE => @provider.git_commit_committer_date,
|
45
|
+
Git::TAG_COMMIT_COMMITTER_EMAIL => @provider.git_commit_committer_email,
|
46
|
+
Git::TAG_COMMIT_COMMITTER_NAME => @provider.git_commit_committer_name,
|
47
|
+
Git::TAG_COMMIT_MESSAGE => @provider.git_commit_message,
|
48
|
+
Git::TAG_COMMIT_SHA => @provider.git_commit_sha
|
49
|
+
}
|
50
|
+
|
51
|
+
# Normalize Git references and filter sensitive data
|
52
|
+
normalize_git!
|
53
|
+
# Expand ~
|
54
|
+
expand_workspace!
|
55
|
+
|
56
|
+
# remove empty tags
|
57
|
+
@tags.reject! do |_, v|
|
58
|
+
# setting type of v here to untyped because steep does not
|
59
|
+
# understand `v.nil? || something`
|
60
|
+
|
61
|
+
# @type var v: untyped
|
62
|
+
v.nil? || v.strip.empty?
|
63
|
+
end
|
64
|
+
|
65
|
+
@tags
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
def normalize_git!
|
71
|
+
branch_ref = @tags[Git::TAG_BRANCH]
|
72
|
+
if Datadog::CI::Utils::Git.is_git_tag?(branch_ref)
|
73
|
+
@tags[Git::TAG_TAG] = branch_ref
|
74
|
+
@tags.delete(Git::TAG_BRANCH)
|
75
|
+
end
|
76
|
+
|
77
|
+
@tags[Git::TAG_TAG] = Datadog::CI::Utils::Git.normalize_ref(@tags[Git::TAG_TAG])
|
78
|
+
@tags[Git::TAG_BRANCH] = Datadog::CI::Utils::Git.normalize_ref(@tags[Git::TAG_BRANCH])
|
79
|
+
@tags[Git::TAG_REPOSITORY_URL] = filter_sensitive_info(
|
80
|
+
@tags[Git::TAG_REPOSITORY_URL]
|
81
|
+
)
|
82
|
+
end
|
83
|
+
|
84
|
+
def expand_workspace!
|
85
|
+
workspace_path = @tags[TAG_WORKSPACE_PATH]
|
86
|
+
|
87
|
+
if !workspace_path.nil? && (workspace_path == "~" || workspace_path.start_with?("~/"))
|
88
|
+
@tags[TAG_WORKSPACE_PATH] = File.expand_path(workspace_path)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def filter_sensitive_info(url)
|
93
|
+
return nil if url.nil?
|
94
|
+
|
95
|
+
url.gsub(%r{(https?://)[^/]*@}, '\1')
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "base"
|
4
|
+
|
5
|
+
module Datadog
|
6
|
+
module CI
|
7
|
+
module Ext
|
8
|
+
module Environment
|
9
|
+
module Providers
|
10
|
+
# Appveyor: https://www.appveyor.com/
|
11
|
+
# Environment variables docs: https://www.appveyor.com/docs/environment-variables/
|
12
|
+
class Appveyor < Base
|
13
|
+
def provider_name
|
14
|
+
"appveyor"
|
15
|
+
end
|
16
|
+
|
17
|
+
def pipeline_url
|
18
|
+
url
|
19
|
+
end
|
20
|
+
|
21
|
+
def job_url
|
22
|
+
url
|
23
|
+
end
|
24
|
+
|
25
|
+
def workspace_path
|
26
|
+
env["APPVEYOR_BUILD_FOLDER"]
|
27
|
+
end
|
28
|
+
|
29
|
+
def pipeline_id
|
30
|
+
env["APPVEYOR_BUILD_ID"]
|
31
|
+
end
|
32
|
+
|
33
|
+
def pipeline_name
|
34
|
+
env["APPVEYOR_REPO_NAME"]
|
35
|
+
end
|
36
|
+
|
37
|
+
def pipeline_number
|
38
|
+
env["APPVEYOR_BUILD_NUMBER"]
|
39
|
+
end
|
40
|
+
|
41
|
+
def git_repository_url
|
42
|
+
return nil unless github_repo_provider?
|
43
|
+
|
44
|
+
"https://github.com/#{env["APPVEYOR_REPO_NAME"]}.git"
|
45
|
+
end
|
46
|
+
|
47
|
+
def git_commit_sha
|
48
|
+
return nil unless github_repo_provider?
|
49
|
+
|
50
|
+
env["APPVEYOR_REPO_COMMIT"]
|
51
|
+
end
|
52
|
+
|
53
|
+
def git_branch
|
54
|
+
return nil unless github_repo_provider?
|
55
|
+
|
56
|
+
env["APPVEYOR_PULL_REQUEST_HEAD_REPO_BRANCH"] || env["APPVEYOR_REPO_BRANCH"]
|
57
|
+
end
|
58
|
+
|
59
|
+
def git_tag
|
60
|
+
return nil unless github_repo_provider?
|
61
|
+
|
62
|
+
env["APPVEYOR_REPO_TAG_NAME"]
|
63
|
+
end
|
64
|
+
|
65
|
+
def git_commit_author_name
|
66
|
+
env["APPVEYOR_REPO_COMMIT_AUTHOR"]
|
67
|
+
end
|
68
|
+
|
69
|
+
def git_commit_author_email
|
70
|
+
env["APPVEYOR_REPO_COMMIT_AUTHOR_EMAIL"]
|
71
|
+
end
|
72
|
+
|
73
|
+
def git_commit_message
|
74
|
+
commit_message = env["APPVEYOR_REPO_COMMIT_MESSAGE"]
|
75
|
+
if commit_message
|
76
|
+
extended = env["APPVEYOR_REPO_COMMIT_MESSAGE_EXTENDED"]
|
77
|
+
commit_message = "#{commit_message}\n#{extended}" if extended
|
78
|
+
end
|
79
|
+
commit_message
|
80
|
+
end
|
81
|
+
|
82
|
+
private
|
83
|
+
|
84
|
+
def github_repo_provider?
|
85
|
+
return @github_repo_provider if defined?(@github_repo_provider)
|
86
|
+
|
87
|
+
@github_repo_provider = env["APPVEYOR_REPO_PROVIDER"] == "github"
|
88
|
+
end
|
89
|
+
|
90
|
+
def url
|
91
|
+
@url ||= "https://ci.appveyor.com/project/#{env["APPVEYOR_REPO_NAME"]}/builds/#{env["APPVEYOR_BUILD_ID"]}"
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|