Skip to content

[CONFIGURATION] Complete resource detection support in SdkBuilder #4411

Description

@dbarker

Background

SdkBuilder::SetResource currently does not support building configured resource detectors and filtering attributes. This issue is to track completion of that feature.

The yaml schema defines the resource: detection/development field in schema/resource.yaml#L12.

The SDK configuration component implements this model with ResourceConfiguration which has four fields:

  • detection (a list of named detectors plus an IncludeExclude attribute filter)
  • attributes_list (a key=value,... string)
  • attributes (a typed key-value map)
  • schema_url

Parsing of the model from YAML is complete and the Registry has slots for the four named detector
builders (container, host, process, service) and extension detectors. The remaining work is to implement the detector creation, attribute filtering, and resource merge.

Required behavior

Detector dispatch

The YAML path is resource.detection/development.detectors. Each entry names a detector:

resource:
  detection/development:
    attributes:
      included: ["process.*"]
      excluded: ["process.command_args"]
    detectors:
      - process:
      - container:
      - service:
      - host:
      - my_custom_detector:

The four built-in names are container, host, process, and service. Any other name is an
extension detector looked up by name in the registry. If a builder is not registered for the named detector then the SdkBuilder should fail with an error log (currently handled by throwing an exception).

See ResourceDetectorConfigurationVisitor use the same pattern as SpanExporterBuilder in sdk_builder.cc.

Attribute filter

After running all configured detectors, the merged detected resource must be filtered using
detection.attributes before being incorporated into the final resource:

  • If included is absent, all attribute keys pass.
  • excluded is applied after included; a key matched by excluded is dropped even if it also matched included.
  • Patterns use * (any sequence) and ? (any single character) wildcards and the implementation should leverage sdk::common::WildcardMatch.

The filter applies only to detected attributes. attributes_list and attributes are never filtered.

Merge priority order

Per the resource SDK merge spec,
the updating resource's value wins on key conflict. The four sources, lowest-priority first:

  1. Resource::GetDefault() provides a Resource with the telemetry.sdk.* attributes only
  2. Detected resource from the registered detectors after the detection.attributes filter
  3. attributes_list from the model (comma-separated key=value string)
  4. attributes from the model (typed map + schema_url)

Note: Resource::Create internally runs GetDefault() and OTELResourceDetector, which pulls attributes from the environment variable. It cannot be used in SdkBuilder.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedGood for taking. Extra help will be provided by maintainersspec-complianceNot compliant to OpenTelemetry specstriage/acceptedIndicates an issue or PR is ready to be actively worked on.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions