Skip to content

Configure jsonSchema2Pojo to not initialize collections#8356

Merged
jack-berg merged 1 commit into
open-telemetry:mainfrom
jack-berg:fix-include-exclude-bug
May 5, 2026
Merged

Configure jsonSchema2Pojo to not initialize collections#8356
jack-berg merged 1 commit into
open-telemetry:mainfrom
jack-berg:fix-include-exclude-bug

Conversation

@jack-berg
Copy link
Copy Markdown
Member

Fixes #8337.

Currently, all collection types in generated pojos initialize to new ArrayList<>(). This prevents us from being able to differentiate between null and empty, which is key to implementing declarative config semantics.

@jack-berg jack-berg requested a review from a team as a code owner May 1, 2026 17:26
Arguments.of(new ViewStreamModel().withAttributeKeys(null), View.builder().build()),
// attribute_keys with only included (no excluded) - reproduces
// https://github.com/open-telemetry/opentelemetry-java/issues/8337
Arguments.of(
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new test case fails without the change to build.gradle.kts.

Refactored these tests to follow the parameterized test pattern used elsewhere in these declarative config factory tests.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 1, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.85%. Comparing base (b87fa99) to head (a9bdc8b).

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #8356      +/-   ##
============================================
+ Coverage     90.82%   90.85%   +0.03%     
- Complexity     7927     7936       +9     
============================================
  Files           895      895              
  Lines         23872    23872              
  Branches       2378     2378              
============================================
+ Hits          21681    21690       +9     
  Misses         1446     1446              
+ Partials        745      736       -9     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Contributor

@breedx-splk breedx-splk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a good change to me. I didn't see explicitly in the tests where the null case would be covered. Is that something that is still lacking after this PR?

Is there any concern about existing code assuming non-null because of prior behavior?

@SylvainJuge
Copy link
Copy Markdown
Contributor

This issue also impacts the rule-based sampler and resource attribute detectors, as they both get empty collections where a null value would be expected if the attribute is not present in the yaml.

While on the java-side, having an null collection feels odd and requires more code on the consumer side, doing that allows to closely match the yaml semantics where we need to know if something is present or not, so this seems to be a good compromise. The downside however is that we have to test more combinations.

For example, from the resource detector in kitchen sink example: https://github.com/open-telemetry/opentelemetry-configuration/blob/main/snippets/Resource_kitchen_sink.yaml

resource:
  # SNIPPET_START
  attributes:
  detection/development:
    attributes:
      included:
        - process.*
      excluded:
        - process.command_args
    detectors:
      - process:

Here removing one of included and excluded would trigger an exception thanks to the checks added in #8266

Same with rule-based sampler, the following configuration currently fails if we remove any of the included or excluded attribute is removed:

tracer_provider:
  processors:
    - simple:
        exporter:
          console:
  sampler:
    composite/development:
      rule_based:
        rules:
          - attribute_patterns:
              key: http.path
              included:
                - /internal/*
              excluded:
                - /internal/special/*

@jack-berg
Copy link
Copy Markdown
Member Author

Is there any concern about existing code assuming non-null because of prior behavior?

I did an analysis of all the cases where declarative config has arrays and all the interpretation logic has null checks already, so this shouldn't be a problem

Arguments.of(
new ViewStreamModel()
.withAttributeKeys(
new IncludeExcludeModel()
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a good change to me. I didn't see explicitly in the tests where the null case would be covered. Is that something that is still lacking after this PR?

@breedx-splk Here's the null case test. Previously, omitting withExcluded would mean it initializes with new ArrayList<>(), now it initializes to null

@jack-berg jack-berg merged commit d60b1d9 into open-telemetry:main May 5, 2026
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Metric View in declarative config need included and excluded Block for attribute_keys

3 participants