Skip to content
Draft
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
87 changes: 48 additions & 39 deletions docs/GettingStarted.md

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions lib/datadog/appsec/configuration/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,25 @@ def self.add_settings!(base)
o.default :recommended
end

# Can be a Hash with `:pass` and `:monitor` keys, or an Array of strings
# Env var accepts both the usual format for arrays (comma-separated) and JSON (array and hash)
# @default `DD_APPSEC_IP_PASSLIST` environment variable, otherwise `[]`
# @return [Array[String], Hash[Symbol, Array[String]]]
option :ip_passlist do |o|
o.env 'DD_APPSEC_IP_PASSLIST'
o.default []
o.env_parser do |env_value|
next if env_value.nil?

stripped = env_value.strip
next [] if stripped.empty?

if stripped.start_with?('{', '[')
Datadog::Core::Configuration::Option.parse_json_env(stripped)
else
stripped.split(',').map(&:strip).reject(&:empty?)
end
end

o.setter do |value|
next value if value.nil? || value.empty?
Expand All @@ -95,6 +112,7 @@ def self.add_settings!(base)

option :ip_denylist do |o|
o.type :array
o.env 'DD_APPSEC_IP_DENYLIST'
o.default []

o.setter do |value|
Expand All @@ -111,6 +129,7 @@ def self.add_settings!(base)

option :user_id_denylist do |o|
o.type :array
o.env 'DD_APPSEC_USER_ID_DENYLIST'
o.default []

o.setter do |value|
Expand Down
2 changes: 2 additions & 0 deletions lib/datadog/core/configuration/ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ module Agent
ENV_DEFAULT_PORT = 'DD_TRACE_AGENT_PORT'
ENV_DEFAULT_TIMEOUT_SECONDS = 'DD_TRACE_AGENT_TIMEOUT_SECONDS'
ENV_DEFAULT_URL = 'DD_TRACE_AGENT_URL'
ENV_DEFAULT_USE_SSL = 'DD_TRACE_AGENT_USE_SSL'
ENV_DEFAULT_UDS_PATH = 'DD_TRACE_AGENT_UDS_PATH'

module HTTP
ADAPTER = :net_http
Expand Down
8 changes: 8 additions & 0 deletions lib/datadog/core/configuration/option.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ def <=>(other)
LIST = [REMOTE_CONFIGURATION, PROGRAMMATIC, FLEET_STABLE, ENVIRONMENT, LOCAL_STABLE, DEFAULT].sort.reverse.freeze
end

def self.parse_json_env(value, symbolize_names: true)
return if value.nil?

JSON.parse(value, symbolize_names: symbolize_names)
rescue JSON::ParserError => e
raise ArgumentError, e.message
end

def initialize(definition, context)
@definition = definition
@context = context
Expand Down
70 changes: 60 additions & 10 deletions lib/datadog/core/configuration/settings.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# frozen_string_literal: true

require 'json'
require 'logger'
require 'uri'

require_relative 'base'
require_relative 'ext'
Expand All @@ -23,6 +25,15 @@ module Configuration
class Settings
include Base

LOGGER_LEVELS = {
'debug' => ::Logger::DEBUG,
'info' => ::Logger::INFO,
'warn' => ::Logger::WARN,
'error' => ::Logger::ERROR,
'fatal' => ::Logger::FATAL,
'unknown' => ::Logger::UNKNOWN,
}.freeze

# @!visibility private
def initialize(*_)
super
Expand Down Expand Up @@ -66,10 +77,13 @@ def initialize(*_)

# Agent APM SSL.
# @see https://docs.datadoghq.com/getting_started/tracing/#datadog-apm
# @default defined as part of `DD_TRACE_AGENT_URL` environment variable, otherwise `false`
# @default `DD_TRACE_AGENT_USE_SSL` environment variable, otherwise `false`
# Only applies to http connections.
# @return [Boolean,nil]
option :use_ssl
option :use_ssl do |o|
o.type :bool, nilable: true
o.env Configuration::Ext::Agent::ENV_DEFAULT_USE_SSL
end

# Agent APM Timeout.
# @see https://docs.datadoghq.com/getting_started/tracing/#datadog-apm
Expand All @@ -78,11 +92,14 @@ def initialize(*_)
option :timeout_seconds

# Agent unix domain socket path.
# @default defined in `DD_TRACE_AGENT_URL` environment variable, otherwise '/var/run/datadog/apm.socket'
# @default `DD_TRACE_AGENT_UDS_PATH` environment variable, otherwise `nil`
# Agent connects via HTTP by default, but will use UDS if this is set or if unix scheme defined in
# DD_TRACE_AGENT_URL.
# @return [String,nil]
option :uds_path
option :uds_path do |o|
o.type :string, nilable: true
o.env Configuration::Ext::Agent::ENV_DEFAULT_UDS_PATH
end

# TODO: add declarative statsd configuration. Currently only usable via an environment variable.
# Statsd configuration for agent access.
Expand Down Expand Up @@ -229,8 +246,17 @@ def initialize(*_)
# Log level for `Datadog.logger`.
# @see Logger::Severity
# @return Logger::Severity
# TODO: Add environment variable for this `DD_TRACE_LOG_LEVEL`
option :level, default: ::Logger::INFO
option :level do |o|
o.env 'DD_TRACE_LOG_LEVEL'
o.default ::Logger::INFO
o.type :int
o.env_parser do |value|
if value
normalized = value.strip.downcase
LOGGER_LEVELS.key?(normalized) ? LOGGER_LEVELS[normalized] : nil
end
end
end
end

# Datadog Profiler-specific configurations.
Expand All @@ -250,6 +276,10 @@ def initialize(*_)

# @public_api
settings :exporter do
# Transport object to use for sending profiling data to the Datadog Agent.
# If not provided, a default transport will be used.
# @default `nil`
# @return [Object,nil]
option :transport
end

Expand Down Expand Up @@ -300,6 +330,7 @@ def initialize(*_)
# grouping and categorization of stack traces.
option :code_provenance_enabled do |o|
o.type :bool
o.env Profiling::Ext::ENV_CODE_PROVENANCE_ENABLED
o.default true
end

Expand All @@ -323,6 +354,7 @@ def initialize(*_)
# @default false
option :allocation_counting_enabled do |o|
o.type :bool
o.env Profiling::Ext::ENV_ALLOCATION_COUNTING_ENABLED
o.default false
end

Expand Down Expand Up @@ -533,6 +565,7 @@ def initialize(*_)
# @default 10_000_000 (10ms)
option :waiting_for_gvl_threshold_ns do |o|
o.type :int
o.env Profiling::Ext::ENV_WAITING_FOR_GVL_THRESHOLD_NS
o.default 10_000_000
end

Expand Down Expand Up @@ -615,10 +648,10 @@ def initialize(*_)
#
# @warn This setting is experimental and may be removed or changed in future versions.
#
# # No config via environment variable yet
# @default 10
option :experimental_cpu_sampling_interval_ms do |o|
o.type :int
o.env Profiling::Ext::ENV_EXPERIMENTAL_CPU_INTERVAL_MS
o.default 10
end

Expand Down Expand Up @@ -665,7 +698,18 @@ def initialize(*_)
o.default false
end

option :opts, default: {}, type: :hash
option :opts do |o|
o.type :hash
o.env 'DD_RUNTIME_METRICS_OPTS'
o.default({})
o.env_parser do |value|
Datadog::Core::Configuration::Option.parse_json_env(value)
end
end

# The StatsD client (Ruby Object) to use for sending runtime metrics.
# @default `nil`
# @return [Object,nil]
option :statsd
end

Expand Down Expand Up @@ -878,6 +922,7 @@ def initialize(*_)
# @!visibility private
option :agentless_enabled do |o|
o.type :bool
o.env Core::Telemetry::Ext::ENV_AGENTLESS_ENABLED
o.default false
end

Expand Down Expand Up @@ -981,6 +1026,7 @@ def initialize(*_)
# @!visibility private
option :shutdown_timeout_seconds do |o|
o.type :float
o.env Core::Telemetry::Ext::ENV_SHUTDOWN_TIMEOUT_SECONDS
o.default 1.0
end

Expand All @@ -1001,6 +1047,7 @@ def initialize(*_)
# @return [Boolean]
option :debug do |o|
o.type :bool
o.env Core::Telemetry::Ext::ENV_DEBUG
o.default false
end
end
Expand Down Expand Up @@ -1058,9 +1105,12 @@ def initialize(*_)
# DD_SERVICE does not match the correct integration for which remote
# configuration applies.
#
# @default `nil`.
# @default `DD_REMOTE_CONFIG_SERVICE_NAME` environment variable, otherwise `nil`.
# @return [String,nil]
option :service
option :service do |o|
o.type :string, nilable: true
o.env Core::Remote::Ext::ENV_SERVICE
end
Comment on lines +1108 to +1113

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we actually don't need this one, and should probably deprecate it, rather than introduce a new environment variable.

end

settings :crashtracking do
Expand Down
Loading
Loading