From a5ec3f7f55494cb80b4b53c652e31c465b8d5e80 Mon Sep 17 00:00:00 2001 From: Fischer Jemison Date: Tue, 24 May 2022 07:48:43 -0500 Subject: [PATCH] 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 --- CHANGELOG.md | 1 + .../src/opentelemetry/sdk/extension/aws/resource/ec2.py | 2 +- .../src/opentelemetry/sdk/extension/aws/resource/eks.py | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6fa2badae212..b58dbeb92c3e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/sdk-extension/opentelemetry-sdk-extension-aws/src/opentelemetry/sdk/extension/aws/resource/ec2.py b/sdk-extension/opentelemetry-sdk-extension-aws/src/opentelemetry/sdk/extension/aws/resource/ec2.py index 17e892e91d54..b0cfeeb31225 100644 --- a/sdk-extension/opentelemetry-sdk-extension-aws/src/opentelemetry/sdk/extension/aws/resource/ec2.py +++ b/sdk-extension/opentelemetry-sdk-extension-aws/src/opentelemetry/sdk/extension/aws/resource/ec2.py @@ -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") diff --git a/sdk-extension/opentelemetry-sdk-extension-aws/src/opentelemetry/sdk/extension/aws/resource/eks.py b/sdk-extension/opentelemetry-sdk-extension-aws/src/opentelemetry/sdk/extension/aws/resource/eks.py index 69d17da1f07f..c712e9875fd8 100644 --- a/sdk-extension/opentelemetry-sdk-extension-aws/src/opentelemetry/sdk/extension/aws/resource/eks.py +++ b/sdk-extension/opentelemetry-sdk-extension-aws/src/opentelemetry/sdk/extension/aws/resource/eks.py @@ -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" ),