Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

opentelemetry-instrumentation-aws-lambda: code does not handle lack of expected environment variables #2744

Closed
Kyle-sandeman-mrdfood opened this issue Jul 26, 2024 · 6 comments · Fixed by #2750
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@Kyle-sandeman-mrdfood
Copy link

Describe your environment

OS: Docker (python3.12)
Python version: (e.g., Python 3.12.1)
Package version: (e.g., 0.48.0)

What happened?

Please note that my application is NOT a Lambda or related in any way. I only have this package because it is a default in the bootstrap.

Instrumenting of aws-lambda failed
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/opentelemetry/instrumentation/auto_instrumentation/_load.py", line 87, in _load_instrumentors
    distro.load_instrumentor(entry_point, skip_dep_check=True)
  File "/usr/local/lib/python3.12/site-packages/opentelemetry/instrumentation/distro.py", line 64, in load_instrumentor
    instrumentor().instrument(**kwargs)
  File "/usr/local/lib/python3.12/site-packages/opentelemetry/instrumentation/instrumentor.py", line 114, in instrument
    result = self._instrument(  # pylint: disable=assignment-from-no-return
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/opentelemetry/instrumentation/aws_lambda/__init__.py", line 429, in _instrument
    ) = lambda_handler.rsplit(".", 1)
        ^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'rsplit'
Failed to auto initialize opentelemetry
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/opentelemetry/instrumentation/auto_instrumentation/sitecustomize.py", line 39, in initialize
    _load_instrumentors(distro)
  File "/usr/local/lib/python3.12/site-packages/opentelemetry/instrumentation/auto_instrumentation/_load.py", line 91, in _load_instrumentors
    raise exc
  File "/usr/local/lib/python3.12/site-packages/opentelemetry/instrumentation/auto_instrumentation/_load.py", line 87, in _load_instrumentors
    distro.load_instrumentor(entry_point, skip_dep_check=True)
  File "/usr/local/lib/python3.12/site-packages/opentelemetry/instrumentation/distro.py", line 64, in load_instrumentor
    instrumentor().instrument(**kwargs)
  File "/usr/local/lib/python3.12/site-packages/opentelemetry/instrumentation/instrumentor.py", line 114, in instrument
    result = self._instrument(  # pylint: disable=assignment-from-no-return
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/opentelemetry/instrumentation/aws_lambda/__init__.py", line 429, in _instrument
    ) = lambda_handler.rsplit(".", 1)
        ^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'rsplit'

Steps to Reproduce

pip install opentelemetry-distro opentelemetry-exporter-otlp-proto-grpc opentelemetry-propagator-jaeger opentelemetry-instrumentation-aws-lambda

One could instead run opentelemetry-bootstrap -a install, I presume.

opentelemetry-instrument python -c "print('test')"

Expected Result

test

Actual Result

<error message from description>
test

Additional context

While this does not affect the application itself, it may affect whether tracing gets set up properly.

Would you like to implement a fix?

None

@Kyle-sandeman-mrdfood Kyle-sandeman-mrdfood added the bug Something isn't working label Jul 26, 2024
@emdneto emdneto added the help wanted Extra attention is needed label Jul 26, 2024
@shijiadong2022
Copy link
Contributor

I'd like to work on this and submit a PR later

@maeddes
Copy link

maeddes commented Jul 29, 2024

I was seeing the same behaviour even without explicitly installing the opentelemetry-instrumentation-aws-lambda package via pip

It got installed after I ran opentelemetry-bootstrap -a install.

However as I don't have any AWS Lambda dependencies (like Kyle) I was able to remove it using pip uninstall opentelemetry-instrumentation-aws-lambda after the bootstrap step and things worked fine.

It's certainly not the solution, but works as a temporary workaround at least for me.

@mlorenzana
Copy link

I think in general you should just not install the aws-lambda instrumentation, or if you need to use the bootstrap command, simply add aws-lambda to OTEL_PYTHON_DISABLED_INSTRUMENTATIONS environment variable:

https://opentelemetry.io/docs/zero-code/python/configuration/#disabling-specific-instrumentations

Here is the link to the entry point where you can see what name to add to that env var:

aws-lambda = "opentelemetry.instrumentation.aws_lambda:AwsLambdaInstrumentor"

@Kyle-sandeman-mrdfood
Copy link
Author

Preface: I should've been more clear in the issue that I ran into the problem by using the bootstrap

@mlorenzana While that suffices as a workaround, I don't think it is the right approach.
The AWS lamdba users should opt-in, as opposed to requiring everyone else to opt-out. (I say this as someone that uses AWS Lambda, although unrelated to this issue.)

Additionally, say another default instrumentation gets added for e.g. Google Cloud functions or such, should everyone using opentelemetry be required to add that to the disabled instrumentation list?

@emdneto
Copy link
Member

emdneto commented Jul 30, 2024

@Kyle-sandeman-mrdfood I'll bring this discussion to the next SIG so we can vote to remove the aws-lambda from the defaults. Meanwhile, could you please take a look at the PR that will address part of the issue #2750 ?

@Kyle-sandeman-mrdfood
Copy link
Author

@emdneto the PR is merged, but indeed the code is more defensive 👍
Thanks @lzchen!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
5 participants