Skip to content

Commit 8b48e5b

Browse files
authored
chore(serverless): test to ensure that all imports in datadog-lambda-python still valid (#14746)
## Description <!-- Provide an overview of the change and motivation for the change --> Customer reported that a class name changed in the most recent version of ddtrace which was then causing errors when attempting to import `datadog_lambda`. See DataDog/datadog-lambda-python#661 and #14653. ## Testing <!-- Describe your testing strategy or note what tests are included --> ## Risks <!-- Note any risks associated with this change, or "None" if no risks --> It's just some tests, so risk is low. ## Additional Notes <!-- Any other information that would be helpful for reviewers --> Added additional tests on the `datadog_lambda` side as well, including running our unit tests twice a day. See DataDog/datadog-lambda-python#662.
1 parent 59f8667 commit 8b48e5b

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

tests/internal/test_serverless.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import sys
2+
13
import pytest
24

35
from ddtrace.internal.serverless import in_azure_function
@@ -103,3 +105,65 @@ def find_spec(self, fullname, *args):
103105
assert stdout.decode() == ""
104106
assert stderr.decode() == ""
105107
assert status == 0
108+
109+
110+
@pytest.mark.parametrize(
111+
"from_,import_",
112+
[
113+
("ddtrace", "__version__"),
114+
("ddtrace", "patch"),
115+
("ddtrace", "patch_all"),
116+
("ddtrace._trace._span_pointer", "_SpanPointerDescription"),
117+
("ddtrace._trace._span_pointer", "_SpanPointerDirection"),
118+
("ddtrace._trace.utils_botocore.span_pointers.dynamodb", "_aws_dynamodb_item_span_pointer_description"),
119+
("ddtrace._trace.utils_botocore.span_pointers.s3", "_aws_s3_object_span_pointer_description"),
120+
("ddtrace.contrib.internal.trace_utils", "_get_request_header_client_ip"),
121+
("ddtrace.data_streams", "set_consume_checkpoint"),
122+
("ddtrace.debugging._exception.replay", "SpanExceptionHandler"),
123+
("ddtrace.debugging._uploader", "SignalUploader"),
124+
("ddtrace.internal", "core"),
125+
("ddtrace.internal._exceptions", "BlockingException"),
126+
("ddtrace.internal.appsec.product", "start"),
127+
("ddtrace.internal.telemetry", "telemetry_writer"),
128+
("ddtrace.internal.utils", "get_blocked"),
129+
("ddtrace.internal.utils", "http"),
130+
("ddtrace.llmobs", "LLMObs"),
131+
("ddtrace.opentelemetry", "TracerProvider"),
132+
pytest.param(
133+
"ddtrace.profiling",
134+
"profiler",
135+
# when 3.14 is officially supported, this xfail can be removed.
136+
marks=pytest.mark.xfail(
137+
reason="throws AttributeError: module 'asyncio.events' has no attribute 'BaseDefaultEventLoopPolicy'",
138+
condition=sys.version_info >= (3, 14),
139+
strict=True,
140+
),
141+
),
142+
("ddtrace.propagation.http", "HTTPPropagator"),
143+
("ddtrace.trace", "Context, Span, tracer"),
144+
("ddtrace.trace", "Span"),
145+
("ddtrace.trace", "tracer"),
146+
],
147+
)
148+
def test_serverless_imports(from_, import_, run_python_code_in_subprocess):
149+
# datadog-lambda-python imports a bunch of packages from ddtrace. This
150+
# test ensures that none of those imports break. If this test fails, then
151+
# either you will need to retain the import that was removed or you must
152+
# update datadog-lambda-python to support the new import path.
153+
import os
154+
155+
env = os.environ.copy()
156+
env.update(
157+
{
158+
"AWS_LAMBDA_FUNCTION_NAME": "foobar",
159+
"DD_INSTRUMENTATION_TELEMETRY_ENABLED": "False",
160+
"DD_API_SECURITY_ENABLED": "False",
161+
}
162+
)
163+
164+
code = f"from {from_} import {import_}"
165+
166+
stderr, stdout, status, _ = run_python_code_in_subprocess(code, env=env)
167+
assert stdout.decode() == ""
168+
assert stderr.decode() == ""
169+
assert status == 0

0 commit comments

Comments
 (0)