Skip to content

Commit

Permalink
Revise cloud detectors (#222)
Browse files Browse the repository at this point in the history
* Bump opentelemetry-sdk-extension-aws dependency to 2.1.0

So that loading the detectors outside the expected platform will not add
warnings.

* distro: disable _gcp resource detector

The _gcp resource detector is currently buggy and when loaded on GCP it
will go into an infinite loop loading all the resource detectors.
  • Loading branch information
xrmx authored Dec 24, 2024
1 parent 5d476a4 commit 6448e51
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 11 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ This distribution sets the following defaults:
- `OTEL_METRICS_EXPORTER`: `otlp`
- `OTEL_LOGS_EXPORTER`: `otlp`
- `OTEL_EXPORTER_OTLP_PROTOCOL`: `grpc`
- `OTEL_EXPERIMENTAL_RESOURCE_DETECTORS`: `process_runtime,os,otel,telemetry_distro,_gcp,aws_ec2,aws_ecs,aws_elastic_beanstalk,azure_app_service,azure_vm`
- `OTEL_EXPERIMENTAL_RESOURCE_DETECTORS`: `process_runtime,os,otel,telemetry_distro,aws_ec2,aws_ecs,aws_elastic_beanstalk,azure_app_service,azure_vm`
- `OTEL_METRICS_EXEMPLAR_FILTER`: `always_off`
- `OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE`: `DELTA`

> [!NOTE]
> `OTEL_EXPERIMENTAL_RESOURCE_DETECTORS` cloud resource detectors are dynamically set. When running in a Kubernetes Pod it will be set to `process_runtime,os,otel,telemetry_distro,_gcp,aws_eks`.
> `OTEL_EXPERIMENTAL_RESOURCE_DETECTORS` cloud resource detectors are dynamically set. When running in a Kubernetes Pod it will be set to `process_runtime,os,otel,telemetry_distro,aws_eks`.
### Distribution specific configuration variables

Expand Down
2 changes: 1 addition & 1 deletion dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ opentelemetry-sdk==1.29.0
# opentelemetry-resource-detector-azure
# opentelemetry-resourcedetector-gcp
# opentelemetry-sdk-extension-aws
opentelemetry-sdk-extension-aws==2.0.2
opentelemetry-sdk-extension-aws==2.1.0
# via elastic-opentelemetry (pyproject.toml)
opentelemetry-semantic-conventions==0.50b0
# via
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ dependencies = [
"opentelemetry-resourcedetector-gcp ~= 1.7.0a0",
"opentelemetry-resource-detector-azure ~= 0.1.5",
"opentelemetry-sdk == 1.29.0",
"opentelemetry-sdk-extension-aws ~= 2.0.2",
"opentelemetry-sdk-extension-aws ~= 2.1.0",
"opentelemetry-semantic-conventions == 0.50b0",
"packaging",
]
Expand Down
5 changes: 2 additions & 3 deletions src/elasticotel/distro/resource_detectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@

AWS_LAMBDA_DETECTORS = ["aws_lambda"]
AZURE_FUNCTIONS_DETECTORS = ["azure_functions"]
GCP_CLOUD_RUN_DETECTORS = ["_gcp"]
KUBERNETES_DETECTORS = ["_gcp", "aws_eks"]
GCP_CLOUD_RUN_DETECTORS = []
KUBERNETES_DETECTORS = ["aws_eks"]
OTHER_CLOUD_DETECTORS = [
"_gcp",
"aws_ec2",
"aws_ecs",
"aws_elastic_beanstalk",
Expand Down
2 changes: 1 addition & 1 deletion tests/distro/test_distro.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def test_default_configuration(self):
self.assertEqual("otlp", os.environ.get(OTEL_LOGS_EXPORTER))
self.assertEqual("grpc", os.environ.get(OTEL_EXPORTER_OTLP_PROTOCOL))
self.assertEqual(
"process_runtime,os,otel,telemetry_distro,_gcp,aws_ec2,aws_ecs,aws_elastic_beanstalk,azure_app_service,azure_vm",
"process_runtime,os,otel,telemetry_distro,aws_ec2,aws_ecs,aws_elastic_beanstalk,azure_app_service,azure_vm",
os.environ.get(OTEL_EXPERIMENTAL_RESOURCE_DETECTORS),
)
self.assertEqual("always_off", os.environ.get(OTEL_METRICS_EXEMPLAR_FILTER))
Expand Down
6 changes: 3 additions & 3 deletions tests/distro/test_resource_detectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ def test_azure_functions(self):
@mock.patch.dict("os.environ", {"K_CONFIGURATION": "cloudrun"}, clear=True)
def test_gcp_cloud_run(self):
resource_detectors = get_cloud_resource_detectors()
self.assertEqual(resource_detectors, ["_gcp"])
self.assertEqual(resource_detectors, [])

@mock.patch.dict("os.environ", {"KUBERNETES_SERVICE_HOST": "k8s"}, clear=True)
def test_kubernetes_pod(self):
resource_detectors = get_cloud_resource_detectors()
self.assertEqual(resource_detectors, ["_gcp", "aws_eks"])
self.assertEqual(resource_detectors, ["aws_eks"])

@mock.patch.dict("os.environ", {}, clear=True)
def test_other_cloud_detectors(self):
resource_detectors = get_cloud_resource_detectors()
self.assertEqual(
resource_detectors,
["_gcp", "aws_ec2", "aws_ecs", "aws_elastic_beanstalk", "azure_app_service", "azure_vm"],
["aws_ec2", "aws_ecs", "aws_elastic_beanstalk", "azure_app_service", "azure_vm"],
)

0 comments on commit 6448e51

Please sign in to comment.