Skip to content

Commit

Permalink
Allow get aggregated resources to remove defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanielRN committed Aug 13, 2021
1 parent a12c3a0 commit 47a45a1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 19 deletions.
4 changes: 2 additions & 2 deletions opentelemetry-sdk/src/opentelemetry/sdk/resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ def get_aggregated_resources(
:param timeout: Number of seconds to wait for each detector to return
:return:
"""
detectors_merged_resource = initial_resource or _EMPTY_RESOURCE
detectors_merged_resource = initial_resource or Resource.create()

with concurrent.futures.ThreadPoolExecutor(max_workers=4) as executor:
futures = [executor.submit(detector.detect) for detector in detectors]
Expand All @@ -312,4 +312,4 @@ def get_aggregated_resources(
detected_resource
)

return Resource.create().merge(detectors_merged_resource)
return detectors_merged_resource
26 changes: 9 additions & 17 deletions opentelemetry-sdk/tests/resources/test_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,18 +239,16 @@ def test_aggregated_resources_no_detectors(self):
),
)

def test_aggregated_resources_with_static_resource(self):
def test_aggregated_resources_with_default_destroying_static_resource(
self,
):
static_resource = resources.Resource({"static_key": "static_value"})

self.assertEqual(
resources.get_aggregated_resources(
[], initial_resource=static_resource
),
resources._DEFAULT_RESOURCE.merge(
resources.Resource(
{resources.SERVICE_NAME: "unknown_service"}, ""
)
).merge(static_resource),
static_resource,
)

resource_detector = mock.Mock(spec=resources.ResourceDetector)
Expand All @@ -261,17 +259,11 @@ def test_aggregated_resources_with_static_resource(self):
resources.get_aggregated_resources(
[resource_detector], initial_resource=static_resource
),
resources._DEFAULT_RESOURCE.merge(
resources.Resource(
{resources.SERVICE_NAME: "unknown_service"}, ""
)
).merge(
resources.Resource(
{
"static_key": "try_to_overwrite_existing_value",
"key": "value",
}
)
resources.Resource(
{
"static_key": "try_to_overwrite_existing_value",
"key": "value",
}
),
)

Expand Down

0 comments on commit 47a45a1

Please sign in to comment.