Description
Describe your environment
As of OTel Python 1.4
Steps to reproduce
If you want to use custom ResourceDetector
s, we recommend you use the get_aggregated_resources
method because it will automatically merge your custom ResourceDetector
with the OTELResourceDetector
(used to read ResourceDetector
attributes from the OTEL_RESOURCE_ATTRIBUTES
and OTEL_SERVICE_NAME
environment variables).
However, if you do that, you miss out on the "business metrics" attributes that get created with Resource.create()
Resource.create()
actually uses OTELResourceDetector
too. So if you try to get the bizmetrics by doing get_aggregated_resources([ MyCustomResourceDetector(), Resource.create() ])
, you will get OTELResourceDetector
twice. (Once from Resource.create()
and once from get_aggregated_resources
. See the code here:
What is the expected behavior?
Bizmetrics should be on every span which uses the aggregated Resource from get_aggregated_resources
What is the actual behavior?
Using get_aggregated_resources
as we recommend causes bizmetrics to be missed.
Additional context
The most obvious solutions would be to
- (Option 1) Remove
OTELResourceDetector
fromget_aggregated_resources
's default implementation so users can add eitherOTELResourceDetector
orResource.create()
depending on what they want - (Option 2) Replace
OTELResourceDetector
inget_aggregated_resources
withResource.create()
so spans always get bizmetrics by default
Since we already 1.0+, I recommend Option 2. This will just "Add" attributes and won't break anyone using this method who expects OTELResourceDetector
attributes to be there when they use get_aggregated_resources
. They will just get bizmetric attributes for free.