Skip to content

Commit

Permalink
Use a shorter timeout for AWS EC2 metadata requests (#1089)
Browse files Browse the repository at this point in the history
* 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 <srikanth.chekuri92@gmail.com>
  • Loading branch information
jemisonf and srikanthccv committed May 24, 2022
1 parent 10659f8 commit a5ec3f7
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
([#1064](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1064))
- `opentelemetry-instrumentation-sqlalchemy` will correctly report `otel.library.name`
([#1086](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1086))
- `opentelemetry-sdk-extension-aws` change timeout for AWS EC2 and EKS metadata requests from 1000 seconds and 2000 seconds to 1 second

### Added
- `opentelemetry-instrument` and `opentelemetry-bootstrap` now include a `--version` flag
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def _aws_http_request(method, path, headers):
Request(
"http://169.254.169.254" + path, headers=headers, method=method
),
timeout=1000,
timeout=5,
) as response:
return response.read().decode("utf-8")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def _aws_http_request(method, path, cred_value):
headers={"Authorization": cred_value},
method=method,
),
timeout=2000,
timeout=5,
context=ssl.create_default_context(
cafile="/var/run/secrets/kubernetes.io/serviceaccount/ca.crt"
),
Expand Down

0 comments on commit a5ec3f7

Please sign in to comment.