Skip to content

Commit 51805bc

Browse files
authored
Merge pull request #1732 from newrelic/remove-lambdas-in-config
Remove Lambdas in Configuration Files
1 parent 89476a4 commit 51805bc

1 file changed

Lines changed: 17 additions & 19 deletions

File tree

newrelic/config.py

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import threading
2121
import time
2222
import traceback
23+
import warnings
2324
from datetime import datetime, timezone
2425
from pathlib import Path
2526

@@ -42,7 +43,7 @@
4243
import newrelic.core.agent
4344
import newrelic.core.config
4445
from newrelic.common.log_file import initialize_logging
45-
from newrelic.common.object_names import callable_name, expand_builtin_exception_name
46+
from newrelic.common.object_names import expand_builtin_exception_name
4647
from newrelic.common.opentelemetry_tracers import (
4748
ALL_LIBRARY_TRACERS_TO_NR_HOOKS,
4849
OPENTELEMETRY_ONLY_TRACERS_TO_NR_HOOKS,
@@ -72,6 +73,12 @@ def trace(self, message, *args, **kws):
7273

7374
DEPRECATED_MODULES = {"aioredis": datetime(2022, 2, 22, 0, 0, tzinfo=timezone.utc)}
7475

76+
LAMBDA_IN_CONFIG_WARNING_MESSAGE = "Using lambdas in configuration files has been removed for security reasons. If dynamic naming is required, consider defining your custom callables in your code rather than configuration, and supplying them as arguments to our decorator or wrapper APIs. (See our API documentation for more information: https://docs.newrelic.com/docs/apm/agents/python-agent/python-agent-api/guide-using-python-agent-api#dynamically-name-segments-and-segment-attributes)"
77+
78+
79+
def _lambda_in_config_warning():
80+
warnings.warn(LAMBDA_IN_CONFIG_WARNING_MESSAGE, DeprecationWarning, stacklevel=2)
81+
7582

7683
def _map_aws_account_id(s):
7784
return newrelic.core.config._map_aws_account_id(s, _logger)
@@ -1522,8 +1529,7 @@ def _process_background_task_configuration():
15221529
group = _config_object.get(section, "group")
15231530

15241531
if name and name.startswith("lambda "):
1525-
callable_vars = {"callable_name": callable_name}
1526-
name = eval(name, callable_vars) # noqa: S307
1532+
_lambda_in_config_warning()
15271533

15281534
_logger.debug("register background-task %s", ((module, object_path, application, name, group),))
15291535

@@ -1572,8 +1578,7 @@ def _process_database_trace_configuration():
15721578
sql = _config_object.get(section, "sql")
15731579

15741580
if sql.startswith("lambda "):
1575-
callable_vars = {"callable_name": callable_name}
1576-
sql = eval(sql, callable_vars) # noqa: S307
1581+
_lambda_in_config_warning()
15771582

15781583
_logger.debug("register database-trace %s", ((module, object_path, sql),))
15791584

@@ -1627,12 +1632,10 @@ def _process_external_trace_configuration():
16271632
method = _config_object.get(section, "method")
16281633

16291634
if url.startswith("lambda "):
1630-
callable_vars = {"callable_name": callable_name}
1631-
url = eval(url, callable_vars) # noqa: S307
1635+
_lambda_in_config_warning()
16321636

16331637
if method and method.startswith("lambda "):
1634-
callable_vars = {"callable_name": callable_name}
1635-
method = eval(method, callable_vars) # noqa: S307
1638+
_lambda_in_config_warning()
16361639

16371640
_logger.debug("register external-trace %s", ((module, object_path, library, url, method),))
16381641

@@ -1699,8 +1702,7 @@ def _process_function_trace_configuration():
16991702
rollup = _config_object.get(section, "rollup")
17001703

17011704
if name and name.startswith("lambda "):
1702-
callable_vars = {"callable_name": callable_name}
1703-
name = eval(name, callable_vars) # noqa: S307
1705+
_lambda_in_config_warning()
17041706

17051707
_logger.debug(
17061708
"register function-trace %s", ((module, object_path, name, group, label, params, terminal, rollup),)
@@ -1757,8 +1759,7 @@ def _process_generator_trace_configuration():
17571759
group = _config_object.get(section, "group")
17581760

17591761
if name and name.startswith("lambda "):
1760-
callable_vars = {"callable_name": callable_name}
1761-
name = eval(name, callable_vars) # noqa: S307
1762+
_lambda_in_config_warning()
17621763

17631764
_logger.debug("register generator-trace %s", ((module, object_path, name, group),))
17641765

@@ -1816,8 +1817,7 @@ def _process_profile_trace_configuration():
18161817
depth = _config_object.get(section, "depth")
18171818

18181819
if name and name.startswith("lambda "):
1819-
callable_vars = {"callable_name": callable_name}
1820-
name = eval(name, callable_vars) # noqa: S307
1820+
_lambda_in_config_warning()
18211821

18221822
_logger.debug("register profile-trace %s", ((module, object_path, name, group, depth),))
18231823

@@ -1866,8 +1866,7 @@ def _process_memcache_trace_configuration():
18661866
command = _config_object.get(section, "command")
18671867

18681868
if command.startswith("lambda "):
1869-
callable_vars = {"callable_name": callable_name}
1870-
command = eval(command, callable_vars) # noqa: S307
1869+
_lambda_in_config_warning()
18711870

18721871
_logger.debug("register memcache-trace %s", (module, object_path, command))
18731872

@@ -1926,8 +1925,7 @@ def _process_transaction_name_configuration():
19261925
priority = _config_object.getint(section, "priority")
19271926

19281927
if name and name.startswith("lambda "):
1929-
callable_vars = {"callable_name": callable_name}
1930-
name = eval(name, callable_vars) # noqa: S307
1928+
_lambda_in_config_warning()
19311929

19321930
_logger.debug("register transaction-name %s", ((module, object_path, name, group, priority),))
19331931

0 commit comments

Comments
 (0)