Class: Datadog::Core::Configuration::Settings
- Inherits:
-
Object
- Object
- Datadog::Core::Configuration::Settings
- Extended by:
- Tracing::Configuration::Settings
- Includes:
- Base
- Defined in:
- lib/datadog/core/configuration/settings.rb
Overview
Global configuration settings for the Datadog library. standard:disable Metrics/BlockLength
Instance Method Summary collapse
-
#api_key ⇒ String?
Datadog API key.
-
#env ⇒ String?
The ‘env` tag in Datadog.
-
#get_time_provider ⇒ Proc<Numeric>
The monotonic clock time provider used by Datadog.
-
#service ⇒ String
The ‘service` tag in Datadog.
-
#site ⇒ String?
The Datadog site host to send data to.
-
#tags ⇒ Hash<String,String>
Default tags.
-
#time_now_provider ⇒ Proc<Time>
The time provider used by Datadog.
-
#version ⇒ String?
The ‘version` tag in Datadog.
Methods included from Tracing::Configuration::Settings
Methods included from Base
Instance Method Details
#api_key ⇒ String?
Datadog API key.
For internal use only.
104 105 106 107 |
# File 'lib/datadog/core/configuration/settings.rb', line 104 option :api_key do |o| o.type :string, nilable: true o.env Core::Environment::Ext::ENV_API_KEY end |
#env ⇒ String?
The ‘env` tag in Datadog. Use it to separate out your staging, development, and production environments.
166 167 168 169 170 |
# File 'lib/datadog/core/configuration/settings.rb', line 166 option :env do |o| o.type :string, nilable: true # NOTE: env also gets set as a side effect of tags. See the WORKAROUND note in #initialize for details. o.env Core::Environment::Ext::ENV_ENVIRONMENT end |
#get_time_provider ⇒ Proc<Numeric>
The monotonic clock time provider used by Datadog. This option is internal and is used by ‘datadog-ci` gem to avoid traces’ durations being skewed by timecop.
It must respect the interface of [Datadog::Core::Utils::Time#get_time] method.
For [Timecop](rubygems.org/gems/timecop), for example, ‘->(unit = :float_second) { ::Process.clock_gettime_without_mock(::Process::CLOCK_MONOTONIC, unit) }` allows Datadog features to use the real monotonic time when time is frozen with `Timecop.mock_process_clock = true`.
760 761 762 763 764 765 766 767 768 769 770 771 772 773 |
# File 'lib/datadog/core/configuration/settings.rb', line 760 option :get_time_provider do |o| o.default_proc { |unit = :float_second| ::Process.clock_gettime(::Process::CLOCK_MONOTONIC, unit) } o.type :proc o.after_set do |get_time_provider| Core::Utils::Time.get_time_provider = get_time_provider end o.resetter do |_value| ->(unit = :float_second) { ::Process.clock_gettime(::Process::CLOCK_MONOTONIC, unit) }.tap do |default| Core::Utils::Time.get_time_provider = default end end end |
#service ⇒ String
The ‘service` tag in Datadog. Use it to group related traces into a service.
621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 |
# File 'lib/datadog/core/configuration/settings.rb', line 621 option :service do |o| o.type :string, nilable: true # NOTE: service also gets set as a side effect of tags. See the WORKAROUND note in #initialize for details. # Note: Alias (OTEL_SERVICE_NAME) defined in supported-configurations.json o.env Core::Environment::Ext::ENV_SERVICE o.default Core::Environment::Ext::FALLBACK_SERVICE_NAME # There's a few cases where we don't want to use the fallback service name, so this helper allows us to get a # nil instead so that one can do # nice_service_name = Datadog.configuration.service_without_fallback || nice_service_name_default o.helper(:service_without_fallback) do service_name = service service_name unless service_name.equal?(Core::Environment::Ext::FALLBACK_SERVICE_NAME) end end |
#site ⇒ String?
The Datadog site host to send data to. By default, data is sent to the Datadog US site: ‘app.datadoghq.com`.
If your organization is on another site, you must update this value to the new site.
For internal use only.
648 649 650 651 |
# File 'lib/datadog/core/configuration/settings.rb', line 648 option :site do |o| o.type :string, nilable: true o.env Core::Environment::Ext::ENV_SITE end |
#tags ⇒ Hash<String,String>
Default tags
These tags are used by all Datadog products, when applicable. e.g. trace spans, profiles, etc.
659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 |
# File 'lib/datadog/core/configuration/settings.rb', line 659 option :tags do |o| o.type :hash, nilable: true # Note: Alias (OTEL_RESOURCE_ATTRIBUTES) defined in supported-configurations.json o.env Core::Environment::Ext::ENV_TAGS o.env_parser do |env_value| # Parses a string containing key-value pairs and returns a hash. # Key-value pairs are delimited by ':' OR `=`, and pairs are separated by whitespace, comma, OR BOTH. result = {} unless env_value.nil? || env_value.empty? # falling back to comma as separator sep = env_value.include?(',') ? ',' : ' ' # split by separator env_value.split(sep).each do |tag| tag.strip! next if tag.empty? # tag by : or = (for OpenTelemetry) key, val = tag.split(/[:=]/, 2).map(&:strip) val ||= '' # maps OpenTelemetry semantic attributes to Datadog tags key = case key.downcase when 'deployment.environment' then 'env' when 'service.version' then 'version' when 'service.name' then 'service' else key end result[key] = val unless key.empty? end end result end o.setter do |new_value, old_value| = new_value || {} env_value = env version_value = version service_name = service_without_fallback # Override tags if defined [Core::Environment::Ext::TAG_ENV] = env_value unless env_value.nil? [Core::Environment::Ext::TAG_VERSION] = version_value unless version_value.nil? # Coerce keys to strings = .collect { |k, v| [k.to_s, v] }.to_h # Cross-populate tag values with other settings if env_value.nil? && .key?(Core::Environment::Ext::TAG_ENV) self.env = [Core::Environment::Ext::TAG_ENV] end if version_value.nil? && .key?(Core::Environment::Ext::TAG_VERSION) self.version = [Core::Environment::Ext::TAG_VERSION] end if service_name.nil? && .key?(Core::Environment::Ext::TAG_SERVICE) self.service = [Core::Environment::Ext::TAG_SERVICE] end # Merge with previous tags (old_value || {}).merge() end end |
#time_now_provider ⇒ Proc<Time>
The time provider used by Datadog. It must respect the interface of [Time](ruby-doc.org/core-3.0.1/Time.html).
When testing, it can be helpful to use a different time provider.
For [Timecop](rubygems.org/gems/timecop), for example, ‘->{ Time.now_without_mock_time }` allows Datadog features to use the real wall time when time is frozen.
731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 |
# File 'lib/datadog/core/configuration/settings.rb', line 731 option :time_now_provider do |o| o.default_proc { ::Time.now } o.type :proc o.after_set do |time_provider| Core::Utils::Time.now_provider = time_provider end o.resetter do |_value| # TODO: Resetter needs access to the default value # TODO: to help reduce duplication. -> { ::Time.now }.tap do |default| Core::Utils::Time.now_provider = default end end end |
#version ⇒ String?
The ‘version` tag in Datadog. Use it to enable [Deployment Tracking](docs.datadoghq.com/tracing/deployment_tracking/).
779 780 781 782 783 |
# File 'lib/datadog/core/configuration/settings.rb', line 779 option :version do |o| # NOTE: version also gets set as a side effect of tags. See the WORKAROUND note in #initialize for details. o.type :string, nilable: true o.env Core::Environment::Ext::ENV_VERSION end |