diff --git a/Dockerfile b/Dockerfile index 8da968fb..cc9e9d70 100644 --- a/Dockerfile +++ b/Dockerfile @@ -73,11 +73,12 @@ RUN find ./python/lib/$runtime/site-packages/ddtrace -name \*.h -delete RUN find ./python/lib/$runtime/site-packages/ddtrace -name \*.hpp -delete RUN find ./python/lib/$runtime/site-packages/ddtrace -name \*.pyx -delete -# Strip debug symbols using strip -g for all .so files in ddtrace. This is to +# Strip debug symbols and symbols that are not needed for relocation +# processing using strip --strip-unneeded for all .so files. This is to # reduce the size when ddtrace is built from sources. The release wheels are # already stripped of debug symbols. We should revisit this when serverless # benchmark uses pre-built wheels instead of building from sources. -RUN find ./python/lib/$runtime/site-packages/ddtrace -name "*.so" -exec strip -g {} \; +RUN find ./python/lib/$runtime/site-packages -name "*.so" -exec strip --strip-unneeded {} \; FROM scratch COPY --from=builder /build/python / diff --git a/datadog_lambda/__init__.py b/datadog_lambda/__init__.py index 2034d3cb..059cead9 100644 --- a/datadog_lambda/__init__.py +++ b/datadog_lambda/__init__.py @@ -1,12 +1,5 @@ +import datadog_lambda.config # noqa: F401 needs to be imported before `ddtrace` from datadog_lambda.cold_start import initialize_cold_start_tracing -import os - - -if os.environ.get("DD_INSTRUMENTATION_TELEMETRY_ENABLED") is None: - # Telemetry is required for Appsec Software Composition Analysis - os.environ["DD_INSTRUMENTATION_TELEMETRY_ENABLED"] = os.environ.get( - "DD_APPSEC_ENABLED", "false" - ) initialize_cold_start_tracing() diff --git a/datadog_lambda/config.py b/datadog_lambda/config.py index aaa1af5e..eda6b582 100644 --- a/datadog_lambda/config.py +++ b/datadog_lambda/config.py @@ -82,12 +82,6 @@ def _resolve_env(self, key, default=None, cast=None, depends_on_tracing=False): logs_injection = _get_env("DD_LOGS_INJECTION", "true", as_bool) merge_xray_traces = _get_env("DD_MERGE_XRAY_TRACES", "false", as_bool) - telemetry_enabled = _get_env( - "DD_INSTRUMENTATION_TELEMETRY_ENABLED", - "false", - as_bool, - depends_on_tracing=True, - ) otel_enabled = _get_env("DD_TRACE_OTEL_ENABLED", "false", as_bool) profiling_enabled = _get_env("DD_PROFILING_ENABLED", "false", as_bool) llmobs_enabled = _get_env("DD_LLMOBS_ENABLED", "false", as_bool) @@ -96,6 +90,7 @@ def _resolve_env(self, key, default=None, cast=None, depends_on_tracing=False): "DD_DATA_STREAMS_ENABLED", "false", as_bool, depends_on_tracing=True ) appsec_enabled = _get_env("DD_APPSEC_ENABLED", "false", as_bool) + sca_enabled = _get_env("DD_APPSEC_SCA_ENABLED", "false", as_bool) is_gov_region = _get_env("AWS_REGION", "", lambda x: x.startswith("us-gov-")) @@ -144,3 +139,11 @@ def _reset(self): "Python Lambda Layer FIPS mode is %s.", "enabled" if config.fips_mode_enabled else "not enabled", ) + + +if ( + "DD_INSTRUMENTATION_TELEMETRY_ENABLED" not in os.environ + and not config.sca_enabled + and not config.appsec_enabled +): + os.environ["DD_INSTRUMENTATION_TELEMETRY_ENABLED"] = "false" diff --git a/datadog_lambda/tracing.py b/datadog_lambda/tracing.py index 4faaed2d..225f5dd8 100644 --- a/datadog_lambda/tracing.py +++ b/datadog_lambda/tracing.py @@ -55,11 +55,6 @@ logger = logging.getLogger(__name__) dd_trace_context = None -if config.telemetry_enabled: - # Enable the telemetry client if the user has opted in - from ddtrace.internal.telemetry import telemetry_writer - - telemetry_writer.enable() propagator = HTTPPropagator() diff --git a/datadog_lambda/version.py b/datadog_lambda/version.py index 2e2e781a..373eef7d 100644 --- a/datadog_lambda/version.py +++ b/datadog_lambda/version.py @@ -1 +1 @@ -__version__ = "8.116.0" +__version__ = "8.117.0.dev0" diff --git a/pyproject.toml b/pyproject.toml index cf7d1805..d135e085 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "datadog_lambda" -version = "8.116.0" +version = "8.117.0.dev0" description = "The Datadog AWS Lambda Library" authors = ["Datadog, Inc. "] license = "Apache-2.0" diff --git a/tests/test_config.py b/tests/test_config.py index 92002439..9c5da63a 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -1,3 +1,6 @@ +import importlib +import sys + import pytest from datadog_lambda.config import config, _get_env, Config @@ -14,6 +17,29 @@ def set_env(key, value): return set_env +def test_config_import_does_not_import_ddtrace(monkeypatch): + import datadog_lambda + + with monkeypatch.context() as mp: + for name in list(sys.modules): + if name == "ddtrace" or name.startswith("ddtrace."): + mp.delitem(sys.modules, name, raising=False) + + class _BlockDdtrace(importlib.abc.MetaPathFinder): + def find_spec(self, fullname, path=None, target=None): + if fullname == "ddtrace" or fullname.startswith("ddtrace."): + raise ImportError("ddtrace must not be imported during this test") + return None + + blocker = _BlockDdtrace() + mp.setattr(sys, "meta_path", [blocker] + sys.meta_path, raising=False) + + mp.delattr(datadog_lambda, "config", raising=False) + mp.delitem(sys.modules, "datadog_lambda.config", raising=False) + importlib.invalidate_caches() + importlib.import_module("datadog_lambda.config") + + def _test_as_bool(env_key, conf_key, default): return ( (env_key, conf_key, None, default), @@ -72,9 +98,6 @@ def _test_as_list(env_key, conf_key, default): *_test_as_bool("DD_INTEGRATION_TEST", "integration_test", default=False), *_test_as_bool("DD_BOTOCORE_ADD_SPAN_POINTERS", "add_span_pointers", default=True), *_test_as_bool("DD_TRACE_OTEL_ENABLED", "otel_enabled", default=False), - *_test_as_bool( - "DD_INSTRUMENTATION_TELEMETRY_ENABLED", "telemetry_enabled", default=False - ), *_test_as_bool("DD_MERGE_XRAY_TRACES", "merge_xray_traces", default=False), *_test_as_bool("DD_PROFILING_ENABLED", "profiling_enabled", default=False), *_test_as_bool("DD_LLMOBS_ENABLED", "llmobs_enabled", default=False), @@ -86,6 +109,8 @@ def _test_as_list(env_key, conf_key, default): ), *_test_as_bool("DD_LOCAL_TEST", "local_test", default=False), *_test_as_bool("DD_DATA_STREAMS_ENABLED", "data_streams_enabled", default=False), + *_test_as_bool("DD_APPSEC_ENABLED", "appsec_enabled", default=False), + *_test_as_bool("DD_APPSEC_SCA_ENABLED", "sca_enabled", default=False), *_test_int( "DD_CAPTURE_LAMBDA_PAYLOAD_MAX_DEPTH", "capture_payload_max_depth", default=10 ), @@ -143,9 +168,6 @@ def test_config_from_environ(env_key, conf_key, env_val, conf_val, setenv): "DD_DECODE_AUTHORIZER_CONTEXT", "decode_authorizer_context", default=True ), *_test_as_bool("DD_DATA_STREAMS_ENABLED", "data_streams_enabled", default=False), - *_test_as_bool( - "DD_INSTRUMENTATION_TELEMETRY_ENABLED", "telemetry_enabled", default=False - ), )