Skip to content

fix(otel): fix beatprocessor to honor when conditions#50555

Merged
mauri870 merged 3 commits intoelastic:mainfrom
mauri870:50549-beat-processor
May 7, 2026
Merged

fix(otel): fix beatprocessor to honor when conditions#50555
mauri870 merged 3 commits intoelastic:mainfrom
mauri870:50549-beat-processor

Conversation

@mauri870
Copy link
Copy Markdown
Member

@mauri870 mauri870 commented May 7, 2026

Proposed commit message

The beat processor instantiated each processor by calling its New constructor directly, bypassing the conditional wrapping that processors.Namespace.Register applies on the standard libbeat path. The when field was unpacked into the config but silently dropped, so processors ran unconditionally.

Wrap each constructor with processors.NewConditional before invoking it so conditionals are honored, matching the behavior of standalone beats.

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have made corresponding change to the default configuration files
  • I have added tests that prove my fix is effective or that my feature works. Where relevant, I have used the stresstest.sh script to run them under stress conditions and race detector to verify their stability.
  • I have added an entry in ./changelog/fragments using the changelog tool.

How to test this PR locally

go test -count=1 -v -run '^TestCreateProcessor$' ./x-pack/otel/processor/beatprocessor/
go test -count=1 -tags=integration -v -run '^TestBeatProcessorWhenCondition$' ./x-pack/filebeat/tests/integration/

./script/stresstest.sh ./x-pack/otel/processor/beatprocessor '^TestCreateProcessor$' -p 4
2m10s: 17012 runs so far, 0 failures, 4 active

./script/stresstest.sh --tags integration ./x-pack/filebeat/tests/integration '^TestBeatProcessorWhenCondition$' -p 2
3m10s: 683 runs so far, 0 failures, 2 active

Related issues

The beat processor instantiated each processor by calling
its New constructor directly, bypassing the conditional wrapping
that processors.Namespace.Register applies on the standard libbeat
path. The `when` field was unpacked into the config but silently
dropped, so processors ran unconditionally.

Wrap each constructor with `processors.NewConditional` before invoking
it so `when` configuration is honored, matching the behavior of
standalone beats.
@mauri870 mauri870 self-assigned this May 7, 2026
@mauri870 mauri870 added Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team bugfix backport-active-all Automated backport with mergify to all the active branches labels May 7, 2026
@botelastic botelastic Bot added needs_team Indicates that the issue/PR needs a Team:* label and removed needs_team Indicates that the issue/PR needs a Team:* label labels May 7, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 7, 2026

🤖 GitHub comments

Just comment with:

  • run docs-build : Re-trigger the docs validation. (use unformatted text in the comment!)
  • /test : Run the Buildkite pipeline.

@mauri870 mauri870 force-pushed the 50549-beat-processor branch from 53f36f7 to ff1a252 Compare May 7, 2026 19:40
@mauri870 mauri870 force-pushed the 50549-beat-processor branch from 125b907 to 305a1ab Compare May 7, 2026 19:44
@mauri870 mauri870 changed the title otel(beatprocessor): honor conditions on inner Beat processors fix(otel): fix beatprocessor to honor when conditions May 7, 2026
@mauri870 mauri870 marked this pull request as ready for review May 7, 2026 19:51
@mauri870 mauri870 requested a review from a team as a code owner May 7, 2026 19:51
@mauri870 mauri870 requested review from AndersonQ and belimawr May 7, 2026 19:51
@infra-vault-gh-plugin-prod
Copy link
Copy Markdown

Pinging @elastic/elastic-agent-data-plane (Team:Elastic-Agent-Data-Plane)

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 7, 2026

Review Change Stack
No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Enterprise

Run ID: 487a5a52-77c2-4f01-918c-3d7743bf2a5a

📥 Commits

Reviewing files that changed from the base of the PR and between 1f65343 and 305a1ab.

📒 Files selected for processing (4)
  • changelog/fragments/1778182489-honor-when-conditions-in-beatprocessor.yaml
  • x-pack/filebeat/tests/integration/otel_test.go
  • x-pack/otel/processor/beatprocessor/processor.go
  • x-pack/otel/processor/beatprocessor/processor_test.go

📝 Walkthrough

Walkthrough

This PR fixes a bug where the OTel Beat processor was ignoring when conditions configured on sub-processors. The implementation refactors createProcessor to wrap processor constructors with OpenTelemetry Collector's processors.NewConditional, which evaluates conditional directives during processor instantiation. Unit tests validate wrapping behavior for positive matches, negative matches, and invalid conditions. An integration test confirms end-to-end behavior by configuring conditional add_fields operations and asserting fields are only added when their respective conditions match event content. A changelog entry documents the fix.

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Linked Issues check ✅ Passed All code changes directly address issue #50549: wrapping Beat processor constructors with processors.NewConditional to honor when conditions.
Out of Scope Changes check ✅ Passed All changes are scoped to fixing the when-conditions issue: processor.go refactoring, tests validating conditional behavior, and changelog entry.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • 🛠️ Update Documentation: Commit on current branch
  • 🛠️ Update Documentation: Create PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@mauri870 mauri870 enabled auto-merge (squash) May 7, 2026 20:57
@mauri870 mauri870 merged commit 7bbe8ee into elastic:main May 7, 2026
50 checks passed
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 7, 2026

@Mergifyio backport 8.19 9.3 9.4

@mergify
Copy link
Copy Markdown
Contributor

mergify Bot commented May 7, 2026

backport 8.19 9.3 9.4

✅ Backports have been created

Details

Cherry-pick of 7bbe8ee has failed:

On branch mergify/bp/8.19/pr-50555
Your branch is up to date with 'origin/8.19'.

You are currently cherry-picking commit 7bbe8ee6d.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	new file:   changelog/fragments/1778182489-honor-when-conditions-in-beatprocessor.yaml
	modified:   x-pack/filebeat/tests/integration/otel_test.go
	modified:   x-pack/otel/processor/beatprocessor/processor_test.go

Unmerged paths:
  (use "git add <file>..." to mark resolution)
	both modified:   x-pack/otel/processor/beatprocessor/processor.go

To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally

Cherry-pick of 7bbe8ee has failed:

On branch mergify/bp/9.3/pr-50555
Your branch is up to date with 'origin/9.3'.

You are currently cherry-picking commit 7bbe8ee6d.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	new file:   changelog/fragments/1778182489-honor-when-conditions-in-beatprocessor.yaml
	modified:   x-pack/filebeat/tests/integration/otel_test.go
	modified:   x-pack/otel/processor/beatprocessor/processor_test.go

Unmerged paths:
  (use "git add <file>..." to mark resolution)
	both modified:   x-pack/otel/processor/beatprocessor/processor.go

To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally

mauri870 added a commit that referenced this pull request May 8, 2026
)

* otel(beatprocessor): honor  conditions on inner Beat processors

The beat processor instantiated each processor by calling
its New constructor directly, bypassing the conditional wrapping
that processors.Namespace.Register applies on the standard libbeat
path. The `when` field was unpacked into the config but silently
dropped, so processors ran unconditionally.

Wrap each constructor with `processors.NewConditional` before invoking
it so `when` configuration is honored, matching the behavior of
standalone beats.

* add changelog

* better wording

(cherry picked from commit 7bbe8ee)

Co-authored-by: Mauri de Souza Meneguzzo <mauri870@gmail.com>
@github-actions github-actions Bot mentioned this pull request May 8, 2026
mauri870 added a commit that referenced this pull request May 8, 2026
…conditions (#50559)

* fix(otel): fix beatprocessor to honor `when` conditions (#50555)

* otel(beatprocessor): honor  conditions on inner Beat processors

The beat processor instantiated each processor by calling
its New constructor directly, bypassing the conditional wrapping
that processors.Namespace.Register applies on the standard libbeat
path. The `when` field was unpacked into the config but silently
dropped, so processors ran unconditionally.

Wrap each constructor with `processors.NewConditional` before invoking
it so `when` configuration is honored, matching the behavior of
standalone beats.

* add changelog

* better wording

(cherry picked from commit 7bbe8ee)

# Conflicts:
#	x-pack/otel/processor/beatprocessor/processor.go

* fix conflicts

---------

Co-authored-by: Mauri de Souza Meneguzzo <mauri870@gmail.com>
mauri870 added a commit that referenced this pull request May 8, 2026
…onditions (#50560)

* fix(otel): fix beatprocessor to honor `when` conditions (#50555)

* otel(beatprocessor): honor  conditions on inner Beat processors

The beat processor instantiated each processor by calling
its New constructor directly, bypassing the conditional wrapping
that processors.Namespace.Register applies on the standard libbeat
path. The `when` field was unpacked into the config but silently
dropped, so processors ran unconditionally.

Wrap each constructor with `processors.NewConditional` before invoking
it so `when` configuration is honored, matching the behavior of
standalone beats.

* add changelog

* better wording

(cherry picked from commit 7bbe8ee)

# Conflicts:
#	x-pack/otel/processor/beatprocessor/processor.go

* fix conflicts

---------

Co-authored-by: Mauri de Souza Meneguzzo <mauri870@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-active-all Automated backport with mergify to all the active branches bugfix Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

beatprocessor OTel component ignores when conditions on processors

3 participants