Skip to content

Commit 6746027

Browse files
committed
Move config consolidation into global settings
1 parent 669f51e commit 6746027

File tree

2 files changed

+47
-24
lines changed

2 files changed

+47
-24
lines changed

newrelic/config.py

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,47 @@ def _process_setting(section, option, getter, mapper):
319319
_raise_configuration_error(section, option)
320320

321321

322+
def _process_dt_setting(section, option_p1, option_p2, getter):
323+
try:
324+
# The type of a value is dictated by the getter
325+
# function supplied.
326+
327+
value1 = getattr(_config_object, getter)(section, option_p1)
328+
value2 = getattr(_config_object, getter)(section, option_p2)
329+
330+
# Now need to apply the option from the
331+
# configuration file to the internal settings
332+
# object. Walk the object path and assign it.
333+
334+
target = _settings
335+
fields = option_p1.split(".", 1)
336+
337+
while True:
338+
if len(fields) == 1:
339+
value = value1 or value2 or "default"
340+
setattr(target, fields[0], value)
341+
break
342+
target = getattr(target, fields[0])
343+
fields = fields[1].split(".", 1)
344+
345+
# Cache the configuration so can be dumped out to
346+
# log file when whole main configuration has been
347+
# processed. This ensures that the log file and log
348+
# level entries have been set.
349+
350+
_cache_object.append((option_p1, value1))
351+
_cache_object.append((option_p2, value2))
352+
353+
except configparser.NoSectionError:
354+
pass
355+
356+
except configparser.NoOptionError:
357+
pass
358+
359+
except Exception:
360+
_raise_configuration_error(section, option)
361+
362+
322363
# Processing of all the settings for specified section except
323364
# for log file and log level which are applied separately to
324365
# ensure they are set as soon as possible.
@@ -405,11 +446,9 @@ def _process_configuration(section):
405446
_process_setting(section, "distributed_tracing.enabled", "getboolean", None)
406447
_process_setting(section, "distributed_tracing.exclude_newrelic_header", "getboolean", None)
407448
_process_setting(section, "distributed_tracing.sampler.adaptive_sampling_target", "getint", None)
408-
_process_setting(section, "distributed_tracing.sampler.remote_parent_sampled", "get", None)
409-
_process_setting(section, "distributed_tracing.sampler.remote_parent_not_sampled", "get", None)
449+
_process_dt_setting(section, "distributed_tracing.sampler.full_granularity.remote_parent_sampled", "distributed_tracing.sampler.remote_parent_sampled", "get")
450+
_process_dt_setting(section, "distributed_tracing.sampler.full_granularity.remote_parent_not_sampled", "distributed_tracing.sampler.remote_parent_not_sampled", "get")
410451
_process_setting(section, "distributed_tracing.sampler.full_granularity.enabled", "getboolean", None)
411-
_process_setting(section, "distributed_tracing.sampler.full_granularity.remote_parent_sampled", "get", None)
412-
_process_setting(section, "distributed_tracing.sampler.full_granularity.remote_parent_not_sampled", "get", None)
413452
_process_setting(section, "distributed_tracing.sampler.partial_granularity.enabled", "getboolean", None)
414453
_process_setting(section, "distributed_tracing.sampler.partial_granularity.type", "get", None)
415454
_process_setting(section, "distributed_tracing.sampler.partial_granularity.remote_parent_sampled", "get", None)

newrelic/core/config.py

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -849,20 +849,18 @@ def default_otlp_host(host):
849849
_settings.distributed_tracing.sampler.adaptive_sampling_target = _environ_as_int(
850850
"NEW_RELIC_DISTRIBUTED_TRACING_SAMPLER_ADAPTIVE_SAMPLING_TARGET", default=10
851851
)
852-
_settings.distributed_tracing.sampler.remote_parent_sampled = os.environ.get(
853-
"NEW_RELIC_DISTRIBUTED_TRACING_SAMPLER_REMOTE_PARENT_SAMPLED", "default"
854-
)
855-
_settings.distributed_tracing.sampler.remote_parent_not_sampled = os.environ.get(
856-
"NEW_RELIC_DISTRIBUTED_TRACING_SAMPLER_REMOTE_PARENT_NOT_SAMPLED", "default"
857-
)
858852
_settings.distributed_tracing.sampler.full_granularity.enabled = _environ_as_bool(
859853
"NEW_RELIC_DISTRIBUTED_TRACING_SAMPLER_FULL_GRANULARITY_ENABLED", default=True
860854
)
861855
_settings.distributed_tracing.sampler.full_granularity.remote_parent_sampled = os.environ.get(
862856
"NEW_RELIC_DISTRIBUTED_TRACING_SAMPLER_FULL_GRANULARITY_REMOTE_PARENT_SAMPLED", None
857+
) or os.environ.get(
858+
"NEW_RELIC_DISTRIBUTED_TRACING_SAMPLER_REMOTE_PARENT_SAMPLED", "default"
863859
)
864860
_settings.distributed_tracing.sampler.full_granularity.remote_parent_not_sampled = os.environ.get(
865861
"NEW_RELIC_DISTRIBUTED_TRACING_SAMPLER_FULL_GRANULARITY_REMOTE_PARENT_NOT_SAMPLED", None
862+
) or os.environ.get(
863+
"NEW_RELIC_DISTRIBUTED_TRACING_SAMPLER_REMOTE_PARENT_NOT_SAMPLED", "default"
866864
)
867865
_settings.distributed_tracing.sampler.partial_granularity.enabled = _environ_as_bool(
868866
"NEW_RELIC_DISTRIBUTED_TRACING_SAMPLER_PARTIAL_GRANULARITY_ENABLED", default=False
@@ -1408,20 +1406,6 @@ def finalize_application_settings(server_side_config=None, settings=_settings):
14081406

14091407

14101408
def simplify_distributed_tracing_sampler_granularity_settings(settings):
1411-
# Full granularity settings may appear under:
1412-
# * `distributed_tracing.sampler`
1413-
# * `distributed_tracing.sampler.full_granularity`
1414-
# The `distributed_tracing.sampler.full_granularity` path takes precedence.
1415-
# To simplify logic in the code that uses these settings, store the values that
1416-
# should be used at the `distributed_tracing.sampler.full_granularity` path.
1417-
if not settings.distributed_tracing.sampler.full_granularity.remote_parent_sampled:
1418-
settings.distributed_tracing.sampler.full_granularity.remote_parent_sampled = (
1419-
settings.distributed_tracing.sampler.remote_parent_sampled
1420-
)
1421-
if not settings.distributed_tracing.sampler.full_granularity.remote_parent_not_sampled:
1422-
settings.distributed_tracing.sampler.full_granularity.remote_parent_not_sampled = (
1423-
settings.distributed_tracing.sampler.remote_parent_not_sampled
1424-
)
14251409
# Partial granularity tracing is not available in infinite tracing mode.
14261410
if settings.infinite_tracing.enabled and settings.distributed_tracing.sampler.partial_granularity.enabled:
14271411
_logger.warning(

0 commit comments

Comments
 (0)