opentelemetry-python-contrib
opentelemetry-python-contrib copied to clipboard
Circular Import Issue Caused by AwsLambdaInstrumentor Manual Instrumentation
trafficstars
Environment:
- AWS Lambda runtime: Python 3.11
- Library version: opentelemetry-instrumentation-aws-lambda==0.42b0
Steps to reproduce
from opentelemetry.instrumentation.aws_lambda import AwsLambdaInstrumentor
AwsLambdaInstrumentor().instrument()
def lambda_handler(event, context):
return "OK"
What is the expected behavior?
The AwsLambdaInstrumentor should allow manual instrumentation without causing circular imports, ensuring the proper functioning of the project.
What is the actual behavior? Circular import is triggered
Additional context
{
"errorMessage": "partially initialized module 'test' has no attribute 'lambda_handler' (most likely due to a circular import)",
"errorType": "AttributeError",
"requestId": "",
"stackTrace": [
" File \"/var/lang/lib/python3.11/importlib/init.py\", line 126, in import_module\n return _bootstrap._gcd_import(name[level:], package, level)\n",
" File \"<frozen importlib._bootstrap>\", line 1204, in _gcd_import\n",
" File \"<frozen importlib._bootstrap>\", line 1176, in _find_and_load\n",
" File \"<frozen importlib._bootstrap>\", line 1147, in _find_and_load_unlocked\n",
" File \"<frozen importlib._bootstrap>\", line 690, in _load_unlocked\n",
" File \"<frozen importlib._bootstrap_external>\", line 940, in exec_module\n",
" File \"<frozen importlib._bootstrap>\", line 241, in _call_with_frames_removed\n",
" File \"/var/task/test.py\", line 3, in <module>\n AwsLambdaInstrumentor().instrument()\n",
" File \"/opt/python/opentelemetry/instrumentation/instrumentor.py\", line 108, in instrument\n result = self._instrument( # pylint: disable=assignment-from-no-return\n",
" File \"/opt/python/opentelemetry/instrumentation/aws_lambda/init.py\", line 462, in _instrument\n _instrument(\n",
" File \"/opt/python/opentelemetry/instrumentation/aws_lambda/init.py\", line 403, in _instrument\n wrap_function_wrapper(\n",
" File \"/opt/python/wrapt/wrappers.py\", line 895, in wrap_function_wrapper\n return wrap_object(module, name, FunctionWrapper, (wrapper,))\n",
" File \"/opt/python/wrapt/wrappers.py\", line 841, in wrap_object\n (parent, attribute, original) = resolve_path(module, name)\n",
" File \"/opt/python/wrapt/wrappers.py\", line 829, in resolve_path\n original = lookup_attribute(parent, attribute)\n",
" File \"/opt/python/wrapt/wrappers.py\", line 827, in lookup_attribute\n return getattr(parent, attribute)\n"
]
}