Skip to content

Commit 17d4cb9

Browse files
committed
add comments
1 parent d7575b8 commit 17d4cb9

File tree

1 file changed

+15
-0
lines changed
  • aws-opentelemetry-distro/src/amazon/opentelemetry/distro

1 file changed

+15
-0
lines changed

aws-opentelemetry-distro/src/amazon/opentelemetry/distro/_utils.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,18 @@ def is_agent_observability_enabled() -> bool:
4242

4343

4444
def get_aws_session():
45+
"""Returns a botocore session only if botocore is installed, otherwise None.
46+
47+
We do this to prevent runtime errors for ADOT customers that do not need
48+
any features that require botocore.
49+
"""
4550
if IS_BOTOCORE_INSTALLED:
4651
# pylint: disable=import-outside-toplevel
4752
from botocore.session import Session
4853

4954
session = Session()
55+
# Botocore only looks up AWS_DEFAULT_REGION when creating a session/client
56+
# See: https://docs.aws.amazon.com/sdkref/latest/guide/feature-region.html#feature-region-sdk-compat
5057
region = os.environ.get("AWS_REGION") or os.environ.get("AWS_DEFAULT_REGION")
5158
if region:
5259
session.set_config_variable("region", region)
@@ -55,5 +62,13 @@ def get_aws_session():
5562

5663

5764
def get_aws_region() -> Optional[str]:
65+
"""Get AWS region from environment or botocore session.
66+
67+
Returns the AWS region in the following priority order:
68+
1. AWS_REGION environment variable
69+
2. AWS_DEFAULT_REGION environment variable
70+
3. botocore session's region (if botocore is available)
71+
4. None if no region can be determined
72+
"""
5873
botocore_session = get_aws_session()
5974
return botocore_session.get_config_variable("region") if botocore_session else None

0 commit comments

Comments
 (0)