Skip to content

Commit

Permalink
Add cloud.aws.account_id config setting
Browse files Browse the repository at this point in the history
  • Loading branch information
hmstepanek committed Nov 7, 2024
1 parent 791c0a7 commit 4f2e9b4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions newrelic/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,7 @@ def _process_configuration(section):
_process_setting(section, "ai_monitoring.enabled", "getboolean", None)
_process_setting(section, "ai_monitoring.record_content.enabled", "getboolean", None)
_process_setting(section, "ai_monitoring.streaming.enabled", "getboolean", None)
_process_setting(section, "cloud.aws.account_id", "get", newrelic.core.config._map_aws_account_id)
_process_setting(section, "k8s_operator.enabled", "getboolean", None)
_process_setting(section, "azure_operator.enabled", "getboolean", None)
_process_setting(section, "package_reporting.enabled", "getboolean", None)
Expand Down
28 changes: 28 additions & 0 deletions newrelic/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,23 @@ def emit(self, record):
_logger.addHandler(_NullHandler())


def _map_aws_account_id(s):
# The AWS account id must be a 12 digit number.
# See https://docs.aws.amazon.com/accounts/latest/reference/manage-acct-identifiers.html#awsaccountid.
if s and len(s) == 12:
try:
account_id = int(s)
return account_id
except ValueError:
pass
# Only log a warning if s is set.
if s:
_logger.warning(
"Improper configuration. cloud.aws.account_id = %s will be ignored because it is not a 12 digit number.", s
)
return None


# The Settings objects and the global default settings. We create a
# distinct type for each sub category of settings that the agent knows
# about so that an error when accessing a non-existent setting is more
Expand Down Expand Up @@ -123,6 +140,14 @@ def otlp_host(self, value):
self._otlp_host = value


class CloudSettings(Settings):
pass


class AWSSettings(Settings):
pass


class AttributesSettings(Settings):
pass

Expand Down Expand Up @@ -428,6 +453,8 @@ class EventHarvestConfigHarvestLimitSettings(Settings):
_settings.application_logging.metrics = ApplicationLoggingMetricsSettings()
_settings.application_logging.local_decorating = ApplicationLoggingLocalDecoratingSettings()
_settings.application_logging.metrics = ApplicationLoggingMetricsSettings()
_settings.cloud = CloudSettings()
_settings.cloud.aws = AWSSettings()
_settings.machine_learning = MachineLearningSettings()
_settings.machine_learning.inference_events_value = MachineLearningInferenceEventsValueSettings()
_settings.ai_monitoring = AIMonitoringSettings()
Expand Down Expand Up @@ -950,6 +977,7 @@ def default_otlp_host(host):
_settings.application_logging.local_decorating.enabled = _environ_as_bool(
"NEW_RELIC_APPLICATION_LOGGING_LOCAL_DECORATING_ENABLED", default=False
)
_settings.cloud.aws.account_id = _map_aws_account_id(os.environ.get("NEW_RELIC_CLOUD_AWS_ACCOUNT_ID"))
_settings.machine_learning.enabled = _environ_as_bool("NEW_RELIC_MACHINE_LEARNING_ENABLED", default=False)
_settings.machine_learning.inference_events_value.enabled = _environ_as_bool(
"NEW_RELIC_MACHINE_LEARNING_INFERENCE_EVENT_VALUE_ENABLED", default=False
Expand Down

0 comments on commit 4f2e9b4

Please sign in to comment.