open-telemetry / open-telemetry/opentelemetry-python-contrib
Circular Import Issue Caused by AwsLambdaInstrumentor Manual Instrumentation
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.1k
- Forks
- 1.1k
- Avg merge
- 4d 15h
- Merged PRs (30d)
- 16
Description
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"
]
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with the provided Python 3.11 Lambda snippet, then inspect opentelemetry/instrumentation/aws_lambda/init.py around _instrument and the wrap_function_wrapper call shown in the traceback. Trace how manual instrumentation resolves the handler during module import. Done means the reproduction no longer raises the circular-import error and the existing AWS Lambda instrumentation behavior remains covered by tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, python
- Domain
- backend, observability-sre
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100