Skip to content

Commit 1047aac

Browse files
committed
Test to ensure that all imports in datadog-lambda-python still valid.
1 parent bc47ed9 commit 1047aac

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

tests/internal/test_serverless.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,56 @@ def find_spec(self, fullname, *args):
103103
assert stdout.decode() == ""
104104
assert stderr.decode() == ""
105105
assert status == 0
106+
107+
108+
@pytest.mark.parametrize(
109+
"from_,import_",
110+
[
111+
("ddtrace", "__version__"),
112+
("ddtrace", "patch"),
113+
("ddtrace", "patch_all"),
114+
("ddtrace._trace._span_pointer", "_SpanPointerDescription"),
115+
("ddtrace._trace._span_pointer", "_SpanPointerDirection"),
116+
("ddtrace._trace.utils_botocore.span_pointers.dynamodb", "_aws_dynamodb_item_span_pointer_description"),
117+
("ddtrace._trace.utils_botocore.span_pointers.s3", "_aws_s3_object_span_pointer_description"),
118+
("ddtrace.contrib.internal.trace_utils", "_get_request_header_client_ip"),
119+
("ddtrace.data_streams", "set_consume_checkpoint"),
120+
("ddtrace.debugging._exception.replay", "SpanExceptionHandler"),
121+
("ddtrace.debugging._uploader", "SignalUploader"),
122+
("ddtrace.internal", "core"),
123+
("ddtrace.internal._exceptions", "BlockingException"),
124+
("ddtrace.internal.appsec.product", "start"),
125+
("ddtrace.internal.telemetry", "telemetry_writer"),
126+
("ddtrace.internal.utils", "get_blocked"),
127+
("ddtrace.internal.utils", "http"),
128+
("ddtrace.llmobs", "LLMObs"),
129+
("ddtrace.opentelemetry", "TracerProvider"),
130+
("ddtrace.profiling", "profiler"),
131+
("ddtrace.propagation.http", "HTTPPropagator"),
132+
("ddtrace.trace", "Context, Span, tracer"),
133+
("ddtrace.trace", "Span"),
134+
("ddtrace.trace", "tracer"),
135+
],
136+
)
137+
def test_serverless_imports(from_, import_, run_python_code_in_subprocess):
138+
# datadog-lambda-python imports a bunch of packages from ddtrace. This
139+
# test ensures that none of those imports break. If this test fails, then
140+
# either you will need to retain the import that was removed or you must
141+
# update datadog-lambda-python to support the new import path.
142+
import os
143+
144+
env = os.environ.copy()
145+
env.update(
146+
{
147+
"AWS_LAMBDA_FUNCTION_NAME": "foobar",
148+
"DD_INSTRUMENTATION_TELEMETRY_ENABLED": "False",
149+
"DD_API_SECURITY_ENABLED": "False",
150+
}
151+
)
152+
153+
code = f"from {from_} import {import_}"
154+
155+
stderr, stdout, status, _ = run_python_code_in_subprocess(code, env=env)
156+
assert stdout.decode() == ""
157+
assert stderr.decode() == ""
158+
assert status == 0

0 commit comments

Comments
 (0)