Skip to content

Commit a5ec3f7

Browse files
Use a shorter timeout for AWS EC2 metadata requests (#1089)
* Use a shorter timeout for AWS EC2 metadata requests Fix #1088 According to the docs, the value for `timeout` is in seconds: https://docs.python.org/3/library/urllib.request.html#urllib.request.urlopen. 1000 seconds seems slow and in some cases can block the startup of the program being instrumented (see #1088 as an example), because the request will hang indefinitely in non-AWS environments. Using a much shorter 1 second timeout seems like a reasonable workaround for this. * add changelog entry for timeout change * use 5s timeout for ECS and EKS, update changelog Co-authored-by: Srikanth Chekuri <[email protected]>
1 parent 10659f8 commit a5ec3f7

File tree

3 files changed

+3
-2
lines changed

3 files changed

+3
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2121
([#1064](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1064))
2222
- `opentelemetry-instrumentation-sqlalchemy` will correctly report `otel.library.name`
2323
([#1086](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1086))
24+
- `opentelemetry-sdk-extension-aws` change timeout for AWS EC2 and EKS metadata requests from 1000 seconds and 2000 seconds to 1 second
2425

2526
### Added
2627
- `opentelemetry-instrument` and `opentelemetry-bootstrap` now include a `--version` flag

sdk-extension/opentelemetry-sdk-extension-aws/src/opentelemetry/sdk/extension/aws/resource/ec2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def _aws_http_request(method, path, headers):
3434
Request(
3535
"http://169.254.169.254" + path, headers=headers, method=method
3636
),
37-
timeout=1000,
37+
timeout=5,
3838
) as response:
3939
return response.read().decode("utf-8")
4040

sdk-extension/opentelemetry-sdk-extension-aws/src/opentelemetry/sdk/extension/aws/resource/eks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def _aws_http_request(method, path, cred_value):
3737
headers={"Authorization": cred_value},
3838
method=method,
3939
),
40-
timeout=2000,
40+
timeout=5,
4141
context=ssl.create_default_context(
4242
cafile="/var/run/secrets/kubernetes.io/serviceaccount/ca.crt"
4343
),

0 commit comments

Comments
 (0)