|
20 | 20 | import threading |
21 | 21 | import time |
22 | 22 | import traceback |
| 23 | +import warnings |
23 | 24 | from datetime import datetime, timezone |
24 | 25 | from pathlib import Path |
25 | 26 |
|
|
42 | 43 | import newrelic.core.agent |
43 | 44 | import newrelic.core.config |
44 | 45 | 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 |
46 | 47 | from newrelic.common.opentelemetry_tracers import ( |
47 | 48 | ALL_LIBRARY_TRACERS_TO_NR_HOOKS, |
48 | 49 | OPENTELEMETRY_ONLY_TRACERS_TO_NR_HOOKS, |
@@ -72,6 +73,12 @@ def trace(self, message, *args, **kws): |
72 | 73 |
|
73 | 74 | DEPRECATED_MODULES = {"aioredis": datetime(2022, 2, 22, 0, 0, tzinfo=timezone.utc)} |
74 | 75 |
|
| 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 | + |
75 | 82 |
|
76 | 83 | def _map_aws_account_id(s): |
77 | 84 | return newrelic.core.config._map_aws_account_id(s, _logger) |
@@ -1522,8 +1529,7 @@ def _process_background_task_configuration(): |
1522 | 1529 | group = _config_object.get(section, "group") |
1523 | 1530 |
|
1524 | 1531 | 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() |
1527 | 1533 |
|
1528 | 1534 | _logger.debug("register background-task %s", ((module, object_path, application, name, group),)) |
1529 | 1535 |
|
@@ -1572,8 +1578,7 @@ def _process_database_trace_configuration(): |
1572 | 1578 | sql = _config_object.get(section, "sql") |
1573 | 1579 |
|
1574 | 1580 | if sql.startswith("lambda "): |
1575 | | - callable_vars = {"callable_name": callable_name} |
1576 | | - sql = eval(sql, callable_vars) # noqa: S307 |
| 1581 | + _lambda_in_config_warning() |
1577 | 1582 |
|
1578 | 1583 | _logger.debug("register database-trace %s", ((module, object_path, sql),)) |
1579 | 1584 |
|
@@ -1627,12 +1632,10 @@ def _process_external_trace_configuration(): |
1627 | 1632 | method = _config_object.get(section, "method") |
1628 | 1633 |
|
1629 | 1634 | if url.startswith("lambda "): |
1630 | | - callable_vars = {"callable_name": callable_name} |
1631 | | - url = eval(url, callable_vars) # noqa: S307 |
| 1635 | + _lambda_in_config_warning() |
1632 | 1636 |
|
1633 | 1637 | 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() |
1636 | 1639 |
|
1637 | 1640 | _logger.debug("register external-trace %s", ((module, object_path, library, url, method),)) |
1638 | 1641 |
|
@@ -1699,8 +1702,7 @@ def _process_function_trace_configuration(): |
1699 | 1702 | rollup = _config_object.get(section, "rollup") |
1700 | 1703 |
|
1701 | 1704 | 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() |
1704 | 1706 |
|
1705 | 1707 | _logger.debug( |
1706 | 1708 | "register function-trace %s", ((module, object_path, name, group, label, params, terminal, rollup),) |
@@ -1757,8 +1759,7 @@ def _process_generator_trace_configuration(): |
1757 | 1759 | group = _config_object.get(section, "group") |
1758 | 1760 |
|
1759 | 1761 | 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() |
1762 | 1763 |
|
1763 | 1764 | _logger.debug("register generator-trace %s", ((module, object_path, name, group),)) |
1764 | 1765 |
|
@@ -1816,8 +1817,7 @@ def _process_profile_trace_configuration(): |
1816 | 1817 | depth = _config_object.get(section, "depth") |
1817 | 1818 |
|
1818 | 1819 | 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() |
1821 | 1821 |
|
1822 | 1822 | _logger.debug("register profile-trace %s", ((module, object_path, name, group, depth),)) |
1823 | 1823 |
|
@@ -1866,8 +1866,7 @@ def _process_memcache_trace_configuration(): |
1866 | 1866 | command = _config_object.get(section, "command") |
1867 | 1867 |
|
1868 | 1868 | if command.startswith("lambda "): |
1869 | | - callable_vars = {"callable_name": callable_name} |
1870 | | - command = eval(command, callable_vars) # noqa: S307 |
| 1869 | + _lambda_in_config_warning() |
1871 | 1870 |
|
1872 | 1871 | _logger.debug("register memcache-trace %s", (module, object_path, command)) |
1873 | 1872 |
|
@@ -1926,8 +1925,7 @@ def _process_transaction_name_configuration(): |
1926 | 1925 | priority = _config_object.getint(section, "priority") |
1927 | 1926 |
|
1928 | 1927 | 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() |
1931 | 1929 |
|
1932 | 1930 | _logger.debug("register transaction-name %s", ((module, object_path, name, group, priority),)) |
1933 | 1931 |
|
|
0 commit comments