File tree Expand file tree Collapse file tree 1 file changed +15
-0
lines changed
aws-opentelemetry-distro/src/amazon/opentelemetry/distro Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -42,11 +42,18 @@ def is_agent_observability_enabled() -> bool:
4242
4343
4444def 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
5764def 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
You can’t perform that action at this time.
0 commit comments