You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
patch upstream ec2 and eks resource detectors (#91)
**Issue:**
The upstream resource detector package is quite outdated since the last
release of v2.0.1. And there is no plan for a new release for now.
https://github.com/open-telemetry/opentelemetry-python-contrib/commits/main/sdk-extension/opentelemetry-sdk-extension-aws
In our distro we want to consume this particular commit where the
timeout for EC2 and EKS resource detectors were significantly shortened
to 5 seconds. The current timeouts are quite long (1000s and 2000s
respectively) and may cause application fail to start in certain cases.
**Description of changes:**
Using the existing mechanism of temporarily patching the upstream
functions, I'm adding patches for the
[`_aws_http_request`](https://github.com/open-telemetry/opentelemetry-python-contrib/blob/9e57fbad8e6bbc730c43b227d91bf24ed0876835/sdk-extension/opentelemetry-sdk-extension-aws/src/opentelemetry/sdk/extension/aws/resource/ec2.py#L32)
methods in the upstream.
**Testing:**
I couldn't come up with a way of writing unit tests to see if the
patching works since the only change in the patched method is the
timeout. Mocking the `urlopen()` to return a custom response from the
patch didn't work as the mock would return the same for the original
method too.
I did test the change with a sample app where I added a log statement
"Hello from the patch_ec2_aws_http_request" to the patch to ensure it
was being applied.
```
(venv) ➜ adotDjangoTest opentelemetry-instrument --traces_exporter console --metrics_exporter none --service_name my_service python manage.py runserver --noreload 8000
Configuration of configurator not loaded because aws_configurator is set by OTEL_PYTHON_CONFIGURATOR
Hello from the patch_ec2_aws_http_request
AwsEcsResourceDetector failed: Missing ECS_CONTAINER_METADATA_URI therefore process is not on ECS.
Failed to get k8s token: [Errno 2] No such file or directory: '/var/run/secrets/kubernetes.io/serviceaccount/token'
AwsEksResourceDetector failed: [Errno 2] No such file or directory: '/var/run/secrets/kubernetes.io/serviceaccount/token'
AwsEc2ResourceDetector failed: <urlopen error [Errno 65] No route to host>
Performing system checks...
System check identified no issues (0 silenced).
You have 18 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.
March 01, 2024 - 17:20:36
Django version 5.0.2, using settings 'adotDjangoTest.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
```
By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice.
0 commit comments