Skip to content

import aws_xray_sdk.core attempts to establish session #273

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

Open
lorengordon opened this issue Feb 26, 2021 · 5 comments
Open

import aws_xray_sdk.core attempts to establish session #273

lorengordon opened this issue Feb 26, 2021 · 5 comments

Comments

@lorengordon
Copy link

It feels a little odd for a library to establish a session on import. Is that truly necessary, or would it be possible to gate that setup on an explicit call to an xray class/method?

I only discovered the session is being setup because I happened to have an incorrect/null AWS_PROFILE configured locally, while testing a logging config using the aws-lambda-powertools-python library. I opened an issue there, but it seemed more appropriate for the xray team.

$ AWS_PROFILE=profiletypo python -c 'import aws_xray_sdk.core'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/loren/.local/lib/python3.6/site-packages/aws_xray_sdk/core/__init__.py", line 10, in <module>
    xray_recorder = AsyncAWSXRayRecorder()
  File "/home/loren/.local/lib/python3.6/site-packages/aws_xray_sdk/core/recorder.py", line 66, in __init__
    self._sampler = DefaultSampler()
  File "/home/loren/.local/lib/python3.6/site-packages/aws_xray_sdk/core/sampling/sampler.py", line 25, in __init__
    self._connector = ServiceConnector()
  File "/home/loren/.local/lib/python3.6/site-packages/aws_xray_sdk/core/sampling/connector.py", line 23, in __init__
    self._xray_client = self._create_xray_client()
  File "/home/loren/.local/lib/python3.6/site-packages/aws_xray_sdk/core/sampling/connector.py", line 164, in _create_xray_client
    aws_access_key_id='', aws_secret_access_key=''
  File "/home/loren/.local/lib/python3.6/site-packages/botocore/session.py", line 802, in create_client
    verify = self.get_config_variable('ca_bundle')
  File "/home/loren/.local/lib/python3.6/site-packages/botocore/session.py", line 241, in get_config_variable
    logical_name)
  File "/home/loren/.local/lib/python3.6/site-packages/botocore/configprovider.py", line 313, in get_config_variable
    return provider.provide()
  File "/home/loren/.local/lib/python3.6/site-packages/botocore/configprovider.py", line 410, in provide
    value = provider.provide()
  File "/home/loren/.local/lib/python3.6/site-packages/botocore/configprovider.py", line 471, in provide
    scoped_config = self._session.get_scoped_config()
  File "/home/loren/.local/lib/python3.6/site-packages/botocore/session.py", line 340, in get_scoped_config
    raise ProfileNotFound(profile=profile_name)
botocore.exceptions.ProfileNotFound: The config profile () could not be found
@heitorlessa
Copy link

image

Adding to @lorengordon comments on Python import profile using Python Tuna to find out where the slower calls are -- X-Ray SDK accounts for 75% of Lambda function import time in this hello world example

@lorengordon
Copy link
Author

Nice! And that botocore.session is almost 50%! 👀

@bhautikpip
Copy link
Contributor

Hi @lorengordon,

Thanks for opening an issue. I think this initialization code resulting in creating xray_client using botocore sessions. Currently as per my understanding this initialization code is to handle special lambda case but I think this is a fair ask and I will tag this as a feature request. However, In the mean time feel free to contribute towards this issue if you have some suggestions already.

@stale
Copy link

stale bot commented Jan 8, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs in next 7 days. Thank you for your contributions.

@stale stale bot added the stale label Jan 8, 2022
@lorengordon
Copy link
Author

Bad stale bot

@stale stale bot removed the stale label Jan 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants