|
1 | 1 | from ddtrace._trace import trace_handlers # noqa:F401 |
| 2 | +from ddtrace.internal.utils.deprecations import DDTraceDeprecationWarning |
2 | 3 | from ddtrace.internal.utils.importlib import func_name # noqa:F401 |
3 | 4 | from ddtrace.internal.utils.importlib import module_name # noqa:F401 |
4 | 5 | from ddtrace.internal.utils.importlib import require_modules # noqa:F401 |
| 6 | +from ddtrace.vendor.debtcollector import deprecate |
| 7 | + |
| 8 | + |
| 9 | +def __getattr__(name): |
| 10 | + if name in ( |
| 11 | + "aiohttp", |
| 12 | + "asgi", |
| 13 | + "bottle", |
| 14 | + "celery", |
| 15 | + "cherrypy", |
| 16 | + "falcon", |
| 17 | + "flask_cache", |
| 18 | + "pylibmc", |
| 19 | + "pyramid", |
| 20 | + "requests", |
| 21 | + "sqlalchemy", |
| 22 | + "wsgi", |
| 23 | + "trace_utils", |
| 24 | + "internal", |
| 25 | + ): |
| 26 | + # following packages/modules are not deprecated and will not be removed in 3.0 |
| 27 | + pass |
| 28 | + elif name in ("trace_handlers", "func_name", "module_name", "require_modules"): |
| 29 | + # the following attributes are exposed in ddtrace.contrib.__init__ and should be |
| 30 | + # removed in v3.0 |
| 31 | + deprecate( |
| 32 | + ("ddtrace.contrib.%s is deprecated" % name), |
| 33 | + category=DDTraceDeprecationWarning, |
| 34 | + removal_version="3.0.0", |
| 35 | + ) |
| 36 | + elif name in ("aiobotocore", "httplib", "kombu", "snowflake", "sqlalchemy", "tornado", "urllib3"): |
| 37 | + # following integrations are not enabled by default and require a unique deprecation message |
| 38 | + deprecate( |
| 39 | + f"ddtrace.contrib.{name} is deprecated", |
| 40 | + message="Avoid using this package directly. " |
| 41 | + f"Set DD_TRACE_{name.upper()}_ENABLED=true and use ``ddtrace.auto`` or the " |
| 42 | + "``ddtrace-run`` command to enable and configure this integration.", |
| 43 | + category=DDTraceDeprecationWarning, |
| 44 | + removal_version="3.0.0", |
| 45 | + ) |
| 46 | + elif name in ("redis_utils", "trace_utils_redis", "trace_utils_async"): |
| 47 | + deprecate( |
| 48 | + f"The ddtrace.contrib.{name} module is deprecated", |
| 49 | + message="Import from ``ddtrace.contrib.trace_utils`` instead.", |
| 50 | + category=DDTraceDeprecationWarning, |
| 51 | + removal_version="3.0.0", |
| 52 | + ) |
| 53 | + elif name == "flask_login": |
| 54 | + deprecate( |
| 55 | + """The flask_login integration is deprecated and will be deleted. |
| 56 | + We recommend customers to switch to manual instrumentation. |
| 57 | + https://docs.datadoghq.com/security/application_security/threats/add-user-info/?tab=loginsuccess&code-lang=python#adding-business-logic-information-login-success-login-failure-any-business-logic-to-traces |
| 58 | + """, |
| 59 | + message="", |
| 60 | + category=DDTraceDeprecationWarning, |
| 61 | + ) |
| 62 | + else: |
| 63 | + deprecate( |
| 64 | + f"ddtrace.contrib.{name} is deprecated", |
| 65 | + message="Avoid using this package directly. " |
| 66 | + f"Use ``import ddtrace.auto`` or the ``ddtrace-run`` command to enable and configure {name}.", |
| 67 | + category=DDTraceDeprecationWarning, |
| 68 | + removal_version="3.0.0", |
| 69 | + ) |
| 70 | + |
| 71 | + if name in globals(): |
| 72 | + return globals()[name] |
| 73 | + raise AttributeError("%s has no attribute %s", __name__, name) |
0 commit comments