Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Resource aggregator method is missing Default Resource Bizmetric Attributes #1996

Closed
@NathanielRN

Description

@NathanielRN

Describe your environment

As of OTel Python 1.4

Steps to reproduce

If you want to use custom ResourceDetectors, 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()

_DEFAULT_RESOURCE = Resource(
{
TELEMETRY_SDK_LANGUAGE: "python",
TELEMETRY_SDK_NAME: "opentelemetry",
TELEMETRY_SDK_VERSION: _OPENTELEMETRY_SDK_VERSION,
}
)

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:

resource = _DEFAULT_RESOURCE.merge(
OTELResourceDetector().detect()
).merge(Resource(attributes, schema_url))

detectors = [OTELResourceDetector()] + detectors

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 from get_aggregated_resources's default implementation so users can add either OTELResourceDetector or Resource.create() depending on what they want
  • (Option 2) Replace OTELResourceDetector in get_aggregated_resources with Resource.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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions