-
Notifications
You must be signed in to change notification settings - Fork 4
/
settings.rb
74 lines (59 loc) · 2.33 KB
/
settings.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# frozen_string_literal: true
require_relative "../ext/settings"
module Datadog
module CI
module Configuration
# Adds CI behavior to ddtrace settings
module Settings
InvalidIntegrationError = Class.new(StandardError)
def self.extended(base)
base = base.singleton_class unless base.is_a?(Class)
add_settings!(base)
end
def self.add_settings!(base)
base.class_eval do
settings :ci do
option :enabled do |o|
o.type :bool
o.env CI::Ext::Settings::ENV_MODE_ENABLED
o.default false
end
option :agentless_mode_enabled do |o|
o.type :bool
o.env CI::Ext::Settings::ENV_AGENTLESS_MODE_ENABLED
o.default false
end
define_method(:instrument) do |integration_name, options = {}, &block|
return unless enabled
integration = fetch_integration(integration_name)
integration.configure(options, &block)
return unless integration.enabled
patch_results = integration.patch
next if patch_results == true
error_message = <<-ERROR
Available?: #{patch_results[:available]}, Loaded?: #{patch_results[:loaded]},
Compatible?: #{patch_results[:compatible]}, Patchable?: #{patch_results[:patchable]}"
ERROR
Datadog.logger.warn("Unable to patch #{integration_name} (#{error_message})")
end
define_method(:[]) do |integration_name|
fetch_integration(integration_name).configuration
end
# TODO: Deprecate in the next major version, as `instrument` better describes this method's purpose
alias_method :use, :instrument
option :trace_flush
option :writer_options do |o|
o.type :hash
o.default({})
end
define_method(:fetch_integration) do |name|
Datadog::CI::Contrib::Integration.registry[name] ||
raise(InvalidIntegrationError, "'#{name}' is not a valid integration.")
end
end
end
end
end
end
end
end