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 <srikanth.chekuri92@gmail.com>
This commit is contained in:
Fischer Jemison 2022-05-24 07:48:43 -05:00 committed by GitHub
parent 10659f8970
commit a5ec3f7f55
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 3 additions and 2 deletions

View File

@ -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

View File

@ -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")

View File

@ -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"
),