Lazy load boto client when using datadogpy for metrics.#558
Merged
purple4reina merged 2 commits intomainfrom Mar 18, 2025
Merged
Lazy load boto client when using datadogpy for metrics.#558purple4reina merged 2 commits intomainfrom
purple4reina merged 2 commits intomainfrom
Conversation
cc91977 to
6943a60
Compare
6943a60 to
3db64ea
Compare
Contributor
Author
|
I tested this by setting a |
72a6537 to
f8f7d9a
Compare
hghotra
approved these changes
Mar 18, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Lazy load boto3 and botocore libraries to use only when required.
Motivation
Faster cold starts when using datadogpy for sending metrics.
Testing Guidelines
Additional Notes
Original method for creating boto3 client
But
boto3.clientcode is just (see https://github.com/boto/boto3/blob/2b18684afe102cfd28f9ddc873d7862209d1da69/boto3/__init__.py#L92)where
_get_default_session()is defined as (see https://github.com/boto/boto3/blob/2b18684afe102cfd28f9ddc873d7862209d1da69/boto3/__init__.py#L34)The
clientmethod on aSessionis just (see https://github.com/boto/boto3/blob/2b18684afe102cfd28f9ddc873d7862209d1da69/boto3/session.py#L215)Where
self._sessionis an instance ofbotocore.session.Session(usingbotocore.session.get_sessionsee https://github.com/boto/boto3/blob/2b18684afe102cfd28f9ddc873d7862209d1da69/boto3/session.py#L62)Long story short, we can avoid importing all of boto3!!
Types of Changes
Check all that apply