|
| 1 | +import sys |
| 2 | + |
1 | 3 | import pytest |
2 | 4 |
|
3 | 5 | from ddtrace.internal.serverless import in_azure_function |
@@ -103,3 +105,65 @@ def find_spec(self, fullname, *args): |
103 | 105 | assert stdout.decode() == "" |
104 | 106 | assert stderr.decode() == "" |
105 | 107 | 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