Skip to content

Commit

Permalink
chore: remove deprecated items (#6580)
Browse files Browse the repository at this point in the history
This PR adds a note to upgrade to 2.x in `upgrading.rst` and removes all
deprecated items slated for removal in 2.0.0. This includes:

- `DD_GEVENT_PATCH_ALL`: no special configuration is now necessary to
make `ddtrace-run` work with gevent.
- `DD_AWS_TAG_ALL_PARAMS`: the boto/botocore/aiobotocore integrations no
longer collect all API parameters by default.
- `DD_REMOTECONFIG_POLL_SECONDS`: replaced by
`DD_REMOTE_CONFIG_POLL_INTERVAL_SECONDS`
- ASM deprecated constants including ``APPSEC_ENABLED``,
``APPSEC_JSON``, ``APPSEC_EVENT_RULE_VERSION``,
``APPSEC_EVENT_RULE_ERRORS``,
``APPSEC_EVENT_RULE_LOADED``, ``APPSEC_EVENT_RULE_ERROR_COUNT``,
``APPSEC_WAF_DURATION``, ``APPSEC_WAF_DURATION_EXT``,
``APPSEC_WAF_TIMEOUTS``, ``APPSEC_WAF_VERSION``,
``APPSEC_ORIGIN_VALUE``, ``APPSEC_BLOCKED``,
``IAST_JSON``, ``IAST_ENABLED``, ``IAST_CONTEXT_KEY``. These constants
were meant for private use only and should not affect existing code.
- ``ddtrace.contrib.grpc.constants.GRPC_PORT_KEY``: replaced by
`ddtrace.ext.net.TARGET_PORT`
- ``ddtrace.ext.cassandra.ROW_COUNT``, ``ddtrace.ext.mongo.ROW_COUNT``,
``ddtrace.ext.sql.ROW_COUNT``: replaced by `ddtrace.ext.db.ROWCOUNT`
- `ddtrace.filters.TraceCiVisibilityFilter`: removed as this was for
private use only and does not affect existing code.
- `ddtrace.contrib.starlette.get_resource` and
`ddtrace.contrib.starlette.span_modifier` and
`ddtrace.contrib.fastapi.span_modifier`: the fastapi and starlette
integrations now provide the full route and not just mounted route for
sub-applications by default.
- `ddtrace.contrib.starlette.config['aggregate_resources']` and
`ddtrace.contrib.fastapi.config['aggregate_resources']`: the starlette
and fastapi integrations no longer have the option to aggregate
resources as this occurs by default now.
- `DD_TRACE_OBFUSCATION_QUERY_STRING_PATTERN`: replaced by
`DD_TRACE_OBFUSCATION_QUERY_STRING_REGEXP`.

Additionally, the `pep562` dependency and references to it have been
removed as it is no longer needed after dropping support for Python <
3.7.

Note that `DD_CALL_BASIC_CONFIG` and `DD_LOG_FORMAT` are removed in

- [x] Change(s) are motivated and described in the PR description.
- [x] Testing strategy is described if automated tests are not included
in the PR.
- [x] Risk is outlined (performance impact, potential for breakage,
maintainability, etc).
- [x] Change is maintainable (easy to change, telemetry, documentation).
- [x] [Library release note
guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html)
are followed. If no release note is required, add label
`changelog/no-changelog`.
- [x] Documentation is included (in-code, generated user docs, [public
corp docs](https://github.com/DataDog/documentation/)).
- [x] Backport labels are set (if
[applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting))

- [x] Title is accurate.
- [x] No unnecessary changes are introduced.
- [x] Description motivates each change.
- [x] Avoids breaking
[API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces)
changes unless absolutely necessary.
- [x] Testing strategy adequately addresses listed risk(s).
- [x] Change is maintainable (easy to change, telemetry, documentation).
- [x] Release note makes sense to a user of the library.
- [x] Reviewer has explicitly acknowledged and discussed the performance
implications of this PR as reported in the benchmarks PR comment.
- [x] Backport labels are set in a manner that is consistent with the
[release branch maintenance
policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)
  • Loading branch information
Yun-Kim authored and majorgreys committed Sep 7, 2023
1 parent 98bc9fe commit 0b1dab1
Show file tree
Hide file tree
Showing 65 changed files with 971 additions and 1,863 deletions.
24 changes: 19 additions & 5 deletions ddtrace/_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
from ddtrace.internal.utils.formats import asbool


DD_LOG_FORMAT = "%(asctime)s %(levelname)s [%(name)s] [%(filename)s:%(lineno)d] {}- %(message)s".format(
"[dd.service=%(dd.service)s dd.env=%(dd.env)s dd.version=%(dd.version)s"
" dd.trace_id=%(dd.trace_id)s dd.span_id=%(dd.span_id)s] "
)

DEFAULT_FILE_SIZE_BYTES = 15 << 20 # 15 MB


Expand Down Expand Up @@ -32,14 +37,13 @@ def configure_ddtrace_logger():
"""
ddtrace_logger = logging.getLogger("ddtrace")

ddtrace_logger.addHandler(logging.StreamHandler())
_configure_ddtrace_debug_logger(ddtrace_logger)
_configure_ddtrace_file_logger(ddtrace_logger)


def _configure_ddtrace_debug_logger(logger):
debug_enabled = asbool(os.environ.get("DD_TRACE_DEBUG", "false"))
if debug_enabled:
if asbool(os.environ.get("DD_TRACE_DEBUG", "false")):
logger.setLevel(logging.DEBUG)
logger.debug("debug mode has been enabled for the ddtrace logger")

Expand All @@ -62,11 +66,21 @@ def _configure_ddtrace_file_logger(logger):
ddtrace_file_handler = RotatingFileHandler(
filename=log_path, mode="a", maxBytes=max_file_bytes, backupCount=num_backup
)

log_format = "%(asctime)s %(levelname)s [%(name)s] [%(filename)s:%(lineno)d] - %(message)s"
log_formatter = logging.Formatter(log_format)

ddtrace_file_handler.setLevel(file_log_level_value)
ddtrace_file_handler.setFormatter(log_formatter)
logger.addHandler(ddtrace_file_handler)
logger.debug("ddtrace logs will be routed to %s", log_path)


def _configure_log_injection():
"""
Ensures that logging is patched before we inject trace information into logs.
"""
from ddtrace import patch

patch(logging=True)
ddtrace_logger = logging.getLogger("ddtrace")
for handler in ddtrace_logger.handlers:
handler.setFormatter(logging.Formatter(DD_LOG_FORMAT))
34 changes: 4 additions & 30 deletions ddtrace/bootstrap/sitecustomize.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import warnings # noqa

from ddtrace import config # noqa
from ddtrace._logger import _configure_log_injection
from ddtrace.debugging._config import di_config # noqa
from ddtrace.debugging._config import ed_config # noqa
from ddtrace.internal.compat import PY2 # noqa
Expand All @@ -19,43 +20,16 @@
from ddtrace.internal.runtime.runtime_metrics import RuntimeWorker # noqa
from ddtrace.internal.utils.formats import asbool # noqa
from ddtrace.internal.utils.formats import parse_tags_str # noqa
from ddtrace.tracer import DD_LOG_FORMAT # noqa
from ddtrace.vendor.debtcollector import deprecate # noqa


# Debug mode from the tracer will do the same here, so only need to do this otherwise.
if config.logs_injection:
# immediately patch logging if trace id injected
from ddtrace import patch

patch(logging=True)


# DEV: Once basicConfig is called here, future calls to it cannot be used to
# change the formatter since it applies the formatter to the root handler only
# upon initializing it the first time.
# See https://github.com/python/cpython/blob/112e4afd582515fcdcc0cde5012a4866e5cfda12/Lib/logging/__init__.py#L1550
# Debug mode from the tracer will do a basicConfig so only need to do this otherwise
if not config._debug_mode and config._call_basic_config:
deprecate(
"ddtrace.tracer.logging.basicConfig",
message="`logging.basicConfig()` should be called in a user's application.",
removal_version="2.0.0",
)
if config.logs_injection:
logging.basicConfig(format=DD_LOG_FORMAT)
else:
logging.basicConfig()
_configure_log_injection()


log = get_logger(__name__)


if os.environ.get("DD_GEVENT_PATCH_ALL") is not None:
deprecate(
"The environment variable DD_GEVENT_PATCH_ALL is deprecated and will be removed in a future version. ",
postfix="There is no special configuration necessary to make ddtrace work with gevent if using ddtrace-run. "
"If not using ddtrace-run, import ddtrace.auto before calling gevent.monkey.patch_all().",
removal_version="2.0.0",
)
if "gevent" in sys.modules or "gevent.monkey" in sys.modules:
import gevent.monkey # noqa

Expand Down
35 changes: 0 additions & 35 deletions ddtrace/constants.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,3 @@
from ddtrace.internal.compat import ensure_pep562
from ddtrace.vendor.debtcollector import deprecate


deprecated_names = {
"APPSEC_ENABLED": "_dd.appsec.enabled",
"APPSEC_JSON": "_dd.appsec.json",
"APPSEC_EVENT_RULE_VERSION": "_dd.appsec.event_rules.version",
"APPSEC_EVENT_RULE_ERRORS": "_dd.appsec.event_rules.errors",
"APPSEC_EVENT_RULE_LOADED": "_dd.appsec.event_rules.loaded",
"APPSEC_EVENT_RULE_ERROR_COUNT": "_dd.appsec.event_rules.error_count",
"APPSEC_WAF_DURATION": "_dd.appsec.waf.duration",
"APPSEC_WAF_DURATION_EXT": "_dd.appsec.waf.duration_ext",
"APPSEC_WAF_TIMEOUTS": "_dd.appsec.waf.timeouts",
"APPSEC_WAF_VERSION": "_dd.appsec.waf.version",
"APPSEC_ORIGIN_VALUE": "appsec",
"APPSEC_BLOCKED": "appsec.blocked",
"IAST_JSON": "_dd.iast.json",
"IAST_ENABLED": "_dd.iast.enabled",
"IAST_CONTEXT_KEY": "_iast_data",
}


def __getattr__(name):
if name in deprecated_names:
deprecate(
("%s.%s is deprecated" % (__name__, name)),
removal_version="2.0.0",
)
return deprecated_names[name]
raise AttributeError("'%s' has no attribute '%s'", __name__, name)


SAMPLE_RATE_METRIC_KEY = "_sample_rate"
SAMPLING_PRIORITY_KEY = "_sampling_priority_v1"
ANALYTICS_SAMPLE_RATE_KEY = "_dd1.sr.eausr"
Expand Down Expand Up @@ -77,5 +44,3 @@ def __getattr__(name):
AUTO_KEEP = 1
# Use this to explicitly inform the backend that a trace should be kept and stored.
USER_KEEP = 2

ensure_pep562(__name__)
15 changes: 0 additions & 15 deletions ddtrace/contrib/aiobotocore/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,6 @@
Default: ``False``
.. py:data:: ddtrace.config.aiobotocore['tag_all_params']
**Deprecated**: This retains the deprecated behavior of adding span tags for
all API parameters that are not explicitly excluded by the integration.
These deprecated span tags will be added along with the API parameters
enabled by default.
This configuration is ignored if ``tag_no_parms`` (``DD_AWS_TAG_NO_PARAMS``)
is set to ``True``.
To collect all API parameters, ``ddtrace.config.botocore.tag_all_params =
True`` or by setting the environment variable ``DD_AWS_TAG_ALL_PARAMS=true``.
Default: ``False``
"""
from ...internal.utils.importlib import require_modules

Expand Down
12 changes: 0 additions & 12 deletions ddtrace/contrib/aiobotocore/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from ddtrace import config
from ddtrace.internal.constants import COMPONENT
from ddtrace.internal.utils.version import parse_version
from ddtrace.vendor import debtcollector
from ddtrace.vendor import wrapt

from ...constants import ANALYTICS_SAMPLE_RATE_KEY
Expand Down Expand Up @@ -40,18 +39,10 @@
TRACED_ARGS = {"params", "path", "verb"}


if os.getenv("DD_AWS_TAG_ALL_PARAMS") is not None:
debtcollector.deprecate(
"Using environment variable 'DD_AWS_TAG_ALL_PARAMS' is deprecated",
message="The aiobotocore integration no longer includes all API parameters by default.",
removal_version="2.0.0",
)

config._add(
"aiobotocore",
{
"tag_no_params": asbool(os.getenv("DD_AWS_TAG_NO_PARAMS", default=False)),
"tag_all_params": asbool(os.getenv("DD_AWS_TAG_ALL_PARAMS", default=False)),
},
)

Expand Down Expand Up @@ -152,9 +143,6 @@ async def _wrapped_api_call(original_func, instance, args, kwargs):
operation = None
span.resource = endpoint_name

if not config.aiobotocore["tag_no_params"] and config.aiobotocore["tag_all_params"]:
aws.add_span_arg_tags(span, endpoint_name, args, ARGS_NAME, TRACED_ARGS)

region_name = deep_getattr(instance, "meta.region_name")

meta = {
Expand Down
16 changes: 0 additions & 16 deletions ddtrace/contrib/boto/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,6 @@
True`` or by setting the environment variable ``DD_AWS_TAG_NO_PARAMS=true``.
Default: ``False``
.. py:data:: ddtrace.config.boto['tag_all_params']
**Deprecated**: This retains the deprecated behavior of adding span tags for
all API parameters that are not explicitly excluded by the integration.
These deprecated span tags will be added along with the API parameters
enabled by default.
This configuration is ignored if ``tag_no_parms`` (``DD_AWS_TAG_NO_PARAMS``)
is set to ``True``.
To collect all API parameters, ``ddtrace.config.botocore.tag_all_params =
True`` or by setting the environment variable ``DD_AWS_TAG_ALL_PARAMS=true``.
Default: ``False``
"""
Expand Down
15 changes: 0 additions & 15 deletions ddtrace/contrib/boto/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from ddtrace.internal.constants import COMPONENT
from ddtrace.internal.utils.wrappers import unwrap
from ddtrace.pin import Pin
from ddtrace.vendor import debtcollector
from ddtrace.vendor import wrapt

from ...internal.schema import schematize_cloud_api_operation
Expand All @@ -41,18 +40,10 @@
AWS_AUTH_TRACED_ARGS = {"path", "data", "host"}


if os.getenv("DD_AWS_TAG_ALL_PARAMS") is not None:
debtcollector.deprecate(
"Using environment variable 'DD_AWS_TAG_ALL_PARAMS' is deprecated",
message="The boto integration no longer includes all API parameters by default.",
removal_version="2.0.0",
)

config._add(
"boto",
{
"tag_no_params": asbool(os.getenv("DD_AWS_TAG_NO_PARAMS", default=False)),
"tag_all_params": asbool(os.getenv("DD_AWS_TAG_ALL_PARAMS", default=False)),
},
)

Expand Down Expand Up @@ -117,9 +108,6 @@ def patched_query_request(original_func, instance, args, kwargs):
else:
span.resource = endpoint_name

if not config.boto["tag_no_params"] and config.boto["tag_all_params"]:
aws.add_span_arg_tags(span, endpoint_name, args, AWS_QUERY_ARGS_NAME, AWS_QUERY_TRACED_ARGS)

# Obtaining region name
region_name = _get_instance_region_name(instance)

Expand Down Expand Up @@ -184,9 +172,6 @@ def patched_auth_request(original_func, instance, args, kwargs):
else:
span.resource = endpoint_name

if not config.boto["tag_no_params"] and config.boto["tag_all_params"]:
aws.add_span_arg_tags(span, endpoint_name, args, AWS_AUTH_ARGS_NAME, AWS_AUTH_TRACED_ARGS)

# Obtaining region name
region_name = _get_instance_region_name(instance)

Expand Down
15 changes: 0 additions & 15 deletions ddtrace/contrib/botocore/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,6 @@
Default: ``False``
.. py:data:: ddtrace.config.botocore['tag_all_params']
**Deprecated**: This retains the deprecated behavior of adding span tags for
all API parameters that are not explicitly excluded by the integration.
These deprecated span tags will be added along with the API parameters
enabled by default.
This configuration is ignored if ``tag_no_parms`` (``DD_AWS_TAG_NO_PARAMS``)
is set to ``True``.
To collect all API parameters, ``ddtrace.config.botocore.tag_all_params =
True`` or by setting the environment variable ``DD_AWS_TAG_ALL_PARAMS=true``.
Default: ``False``
.. py:data:: ddtrace.config.botocore['instrument_internals']
Expand Down
11 changes: 0 additions & 11 deletions ddtrace/contrib/botocore/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
from ddtrace import config
from ddtrace.internal.schema.span_attribute_schema import SpanDirection
from ddtrace.settings.config import Config
from ddtrace.vendor import debtcollector
from ddtrace.vendor import wrapt

from ...constants import ANALYTICS_SAMPLE_RATE_KEY
Expand Down Expand Up @@ -66,12 +65,6 @@

log = get_logger(__name__)

if os.getenv("DD_AWS_TAG_ALL_PARAMS") is not None:
debtcollector.deprecate(
"Using environment variable 'DD_AWS_TAG_ALL_PARAMS' is deprecated",
message="The botocore integration no longer includes all API parameters by default.",
removal_version="2.0.0",
)

# Botocore default settings
config._add(
Expand All @@ -81,7 +74,6 @@
"invoke_with_legacy_context": asbool(os.getenv("DD_BOTOCORE_INVOKE_WITH_LEGACY_CONTEXT", default=False)),
"operations": collections.defaultdict(Config._HTTPServerConfig),
"tag_no_params": asbool(os.getenv("DD_AWS_TAG_NO_PARAMS", default=False)),
"tag_all_params": asbool(os.getenv("DD_AWS_TAG_ALL_PARAMS", default=False)),
"instrument_internals": asbool(os.getenv("DD_BOTOCORE_INSTRUMENT_INTERNALS", default=False)),
},
)
Expand Down Expand Up @@ -595,9 +587,6 @@ def patched_api_call(original_func, instance, args, kwargs):
else:
span.resource = endpoint_name

if not config.botocore["tag_no_params"] and config.botocore["tag_all_params"]:
aws.add_span_arg_tags(span, endpoint_name, args, ARGS_NAME, TRACED_ARGS)

region_name = deep_getattr(instance, "meta.region_name")

span.set_tag_str("aws.agent", "botocore")
Expand Down
11 changes: 0 additions & 11 deletions ddtrace/contrib/fastapi/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@
from ddtrace import Pin
from ddtrace import config
from ddtrace.contrib.asgi.middleware import TraceMiddleware
from ddtrace.contrib.starlette.patch import get_resource
from ddtrace.contrib.starlette.patch import traced_handler
from ddtrace.internal.logger import get_logger
from ddtrace.internal.schema import schematize_service_name
from ddtrace.internal.utils.deprecations import DDTraceDeprecationWarning
from ddtrace.internal.utils.wrappers import unwrap as _u
from ddtrace.vendor.debtcollector import removals
from ddtrace.vendor.wrapt import ObjectProxy
from ddtrace.vendor.wrapt import wrap_function_wrapper as _w

Expand All @@ -23,7 +20,6 @@
_default_service=schematize_service_name("fastapi"),
request_span_name="fastapi.request",
distributed_tracing=True,
aggregate_resources=True,
),
)

Expand All @@ -33,13 +29,6 @@ def get_version():
return getattr(fastapi, "__version__", "")


@removals.remove(removal_version="2.0.0", category=DDTraceDeprecationWarning)
def span_modifier(span, scope):
resource = get_resource(scope)
if config.fastapi["aggregate_resources"] and resource:
span.resource = "{} {}".format(scope["method"], resource)


def wrap_middleware_stack(wrapped, instance, args, kwargs):
return TraceMiddleware(app=wrapped(*args, **kwargs), integration_config=config.fastapi)

Expand Down
Loading

0 comments on commit 0b1dab1

Please sign in to comment.