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:
42
42
43
43
44
44
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
+ """
45
50
if IS_BOTOCORE_INSTALLED :
46
51
# pylint: disable=import-outside-toplevel
47
52
from botocore .session import Session
48
53
49
54
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
50
57
region = os .environ .get ("AWS_REGION" ) or os .environ .get ("AWS_DEFAULT_REGION" )
51
58
if region :
52
59
session .set_config_variable ("region" , region )
@@ -55,5 +62,13 @@ def get_aws_session():
55
62
56
63
57
64
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
+ """
58
73
botocore_session = get_aws_session ()
59
74
return botocore_session .get_config_variable ("region" ) if botocore_session else None
You can’t perform that action at this time.
0 commit comments