Skip to content

Add Elastic Agent identity fields to bodymap logs from OTel-native pipelines - #17463

Draft
swiatekm wants to merge 10 commits into
mainfrom
swiatekm/expose-elastic-agent-identity-agent.id-agent.ver
Draft

swiatekm wants to merge 10 commits into
mainfrom
swiatekm/expose-elastic-agent-identity-agent.id-agent.ver

Conversation

@swiatekm

@swiatekm swiatekm commented Oct 23, 2026 •

Copy link
Copy Markdown
Member

Elastic Agent now injects a transform/_agent-metadata processor at the end of every logs pipeline in the collector config that comes from the policy. The processor writes the agent's identity into the log body for logs in the bodymap mapping mode:

The mapping mode is resolved the way the Elasticsearch exporter does it. The elastic.mapping.mode scope attribute wins, then the X-Elastic-Mapping-Mode client metadata, compared case-insensitively. Logs in other mapping modes are not modified. Pipelines for beat receivers are not touched, because they already set this metadata via a beat processor.

We need a hostname for this to work, and the hostname can change at runtime if the FQDN feature is on, so I added tracking this to the coordinator. Determining the hostname also blocks the coordinator for up to 5s at startup - we've seen similar things happen in beats. If the deadline is exceeded, we collect data without the hostname metadata attached.

Related issues

Risk

  • Low: isolated change, no effect on Fleet connectivity, policy handling, or upgrades
  • Medium: changes existing behavior, but is feature flagged or a failure does not affect Fleet connectivity, policy handling, or upgrades
  • High: touches Fleet connectivity, policy application, upgrade/rollback, installation, or changes defaults for existing users

Rationale

Events from OTel-native receivers configured by Fleet policies (for example akamai_siem and entityanalytics) have no Elastic Agent identity. Packages cannot add it themselves. In bodymap mode the exporter writes only the log body, so resource attributes are dropped. Without these fields, Fleet's final pipeline sets event.agent_id_status to missing, and users cannot tell which agent collected a document.

This is a partial fix for the issue: it covers logs in bodymap mode only. Other mapping modes and signals are not covered.

Rollout and safety

The processor uses error_mode: ignore, so statement errors do not drop data. Downgrade should be safe because no persisted state or on-disk format changes. The diagnostics bundle should already include the merged collector config, which shows the injected processor.

Testing

Tests added in this PR:

  • Unit tests for config injection in internal/pkg/otel/manager/agent_metadata_test.go. They cover the injected processor, idempotency, a missing hostname, no logs pipelines, and buildMergedConfig skipping beat receiver pipelines.
  • Processor behaviour tests in internal/edot/otelcol/agent_metadata_test.go. They run the real transform processor across mapping mode cases (scope attribute, request metadata, precedence, case-insensitivity, string and map bodies).
  • The integration test in testing/integration/ess/otel_test.go now compares agent.id and elastic_agent.* between the fbreceiver and beat documents.

@mergify

mergify Bot commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

This pull request does not have a backport label. Could you fix it @swiatekm? 🙏
To fixup this pull request, you need to add the backport labels for the needed
branches, such as:

  • backport-./d./d is the label that automatically backports to the 8./d branch. /d is the digit
  • backport-active-all is the label that automatically backports to all active branches.
  • backport-active-8 is the label that automatically backports to all active minor branches for the 8 major.
  • backport-active-9 is the label that automatically backports to all active minor branches for the 9 major.

@github-actions

This comment has been minimized.

@swiatekm
swiatekm marked this pull request as ready for review October 26, 2026 18:46
@swiatekm
swiatekm requested a review from a team as a code owner October 26, 2026 18:46
@swiatekm
swiatekm requested a review from macdewee October 26, 2026 18:46
@swiatekm swiatekm added enhancement New feature or request Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team backport-9.6 Automated backport to the 9.6 branch labels Oct 26, 2026
@infra-vault-gh-plugin-prod

Copy link
Copy Markdown

Pinging @elastic/elastic-agent-control-plane (Team:Elastic-Agent-Control-Plane)

Snapshot: agentInfo.Snapshot(),
}
// The hostname the agent reports to Fleet, which honours ELASTIC_AGENT_HOSTNAME and the FQDN feature.
if ecsMeta, err := agentInfo.ECSMetadata(logger); err == nil {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this does a hostname lookup for every call, it might be better to do this once and then pass it in.

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.

It's a hostname lookup when generating otel collector configuration, which I think is roughly what we want? I'll see if I can centralize this more.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Config changes are not that frequent, if we aren't worry about this blocking for 1m (I think that's the timeout) this is fine.

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.

I think the bigger question is actually whether a FQDN change should trigger a config reload, or if it should wait until the next one. Beats processes do the former, effectively, so this should probably be wired into the coordinator, which is the component in charge of when config is reloaded.

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.

I implemented it this way, but it adds some complexity to the coordinator. Notably, we need to know the hostname on the first configuration load, so the call blocking blocks that too. I gave the first call a 5s deadline and otherwise made the whole thing asynchronous.

Possible effects are delaying data collection by 5s if fetching the hostname is slow for some reason. This mostly affects FQDN, which already suffers from similar issues in beats, but it's still a larger change than I would've liked here.

@swiatekm
swiatekm requested a review from cmacknz October 28, 2026 13:22
@github-actions

This comment has been minimized.

firstLookupDone = nil
}
select {
case <-fqdnChanged:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The hostname can change on its own can't it, shouldn't we periodically refresh it? I believe beats will pick up hostname changes, so this means the agent hostname would be out of sync with the one on the events.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is also what the host provider does, not sure there's a way to reuse it here, it seems kind of clunky because it's disabled unless a variable in the policy references.

Possibly another instance of it used here, not tied to vars? It even has the FQDN callback part of this already.

func (c *contextProvider) Run(ctx context.Context, comm corecomp.ContextProviderComm) error {

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.

In an ideal world, we'd have a singleton for this, but you can configure the check interval in the host provider, so the best we can probably do is a shared package containing the update logic. Then the coordinator could just use that. I'll open a new PR for that, it's only tangentially related to this change.

}

statements := []any{
fmt.Sprintf(`set(log.body["agent"], {%s}) where log.body["agent"] == nil`, strings.Join(agent, ", ")),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we still miss agent.id, agent.version and agent.type for Akamai here. The integration already sets agent.name (template), so the agent map exists before this processor runs. We would add elastic_agent.* but skip the missing agent fields too.

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.

In this case, I think Akamai will simply need to stop doing it after this change ships. In general, it's not clear what we should set if some of the fields already exist. There's a chance of producing nonsense.

Comment on lines +35 to +37
if features.IncludeTagsInEvents() {
tags = agentInfo.GetTags()
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The coordinator can change the tags while the otel manager reads them here. I think this can race with AgentInfo.SetTags when include_tags_in_events is enabled. GetTags copies the slice, but it doesn't protect the read of i.tags.

@mergify

mergify Bot commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

This pull request is now in conflicts. Could you fix it? 🙏
To fixup this pull request, you can check out it locally. See documentation: https://help.github.com/articles/checking-out-pull-requests-locally/

git fetch upstream
git checkout -b swiatekm/expose-elastic-agent-identity-agent.id-agent.ver upstream/swiatekm/expose-elastic-agent-identity-agent.id-agent.ver
git merge upstream/main
git push upstream swiatekm/expose-elastic-agent-identity-agent.id-agent.ver

@mergify

mergify Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

This pull request is a draft, so it cannot be queued yet. Mark it as ready for review to get the box back.

@swiatekm
swiatekm force-pushed the swiatekm/expose-elastic-agent-identity-agent.id-agent.ver branch from 5e47808 to 9d55ef4 Compare November 20, 2026 19:59
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

The monitoring connector emits bodymap logs, so the agent metadata
processor now adds agent.* and elastic_agent.* to the monitoring
documents written by the test pipeline.

Assisted-By: Claude Opus 5.5 <noreply@anthropic.com>
Add the agent and elastic_agent sections to bodymap log bodies as a
whole, and only if the body doesn't have them yet, instead of setting
individual fields. Identity set earlier, for example by another Elastic
Agent before forwarding the logs, is kept as is.

In TestHybridAgentE2E, the fbreceiver sets the agent section itself, so
agent.id is ignored again and elastic_agent.* is compared instead.

Assisted-By: Claude Opus 5.5 <noreply@anthropic.com>
Append the agent's tags to the tags of bodymap logs, the way Beats
inputs do with add_tags, and under the same include_tags_in_events
feature flag. Tags are added together with the elastic_agent section,
so logs already handled by an Elastic Agent don't get tags from another
one.

AgentMetadata now embeds client.AgentInfo, and is built from the
manager's agent info.

Assisted-By: Claude Opus 5.5 <noreply@anthropic.com>
The OTel manager adds the hostname from the shared host information as
agent.name to bodymap logs. Watch the host information in the
coordinator, and refresh the component model when the hostname changes,
so the collector configuration uses the new hostname immediately, like
Beats processes do.

Assisted-By: Claude Opus 5.5 <noreply@anthropic.com>
The agent metadata processor test in the EDOT module makes the
elastic-agent-client, collector client and processortest modules direct
dependencies.

Assisted-By: Claude Opus 5.5 <noreply@anthropic.com>
…s on all platforms

staticcheck reports SA4006 for this test on some platforms only, so on
the others nolintlint reported the directive as unused. The lint runs
with --whole-files, so this fails any change to otel_test.go on Windows.

Assisted-By: Claude Opus 5.5 <noreply@anthropic.com>
@swiatekm
swiatekm force-pushed the swiatekm/expose-elastic-agent-identity-agent.id-agent.ver branch from 9d55ef4 to fb89d70 Compare November 23, 2026 14:47
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

Tests must restore the global paths with the pathstest helpers.

Assisted-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

This comment has been minimized.

@github-actions

Copy link
Copy Markdown
Contributor

TL;DR

This failure is most likely a checkout/dependency-state issue (not a PR logic regression): check-ci reports a dirty tree with Modified: [beats go.mod go.sum], and every package job then fails compiling ../../beats/... with inconsistent symbols. Immediate action: run a clean submodule sync/checkout and re-run CI.

Remediation

  • Ensure CI checkout resets Beats submodule + workspace before build:

    • git submodule sync --recursive && git submodule update --init --recursive beats
    • clean workspace (git clean -ffd in superproject/submodule as appropriate).
  • Re-run check-ci first; if clean, re-run one package target (for example linux/amd64 tar.gz) before full matrix.

Investigation details

Root Cause

Configuration/infra state drift is indicated by two linked signals in the same build:

  1. check-ci fails dirty-tree validation with Modified: [beats go.mod go.sum].
  2. All packaging jobs fail while compiling Beats code with incompatible/missing symbols (for example undefined: cfgfile.SetRunnerConfigs, undefined: newWorkloadIdentityCredential, undefined: enforceFIPSFlags).

This pattern is consistent with building against an inconsistent Beats checkout/dependency state during CI.

Evidence

  • Build: https://buildkite.com/elastic/elastic-agent/builds/50696

  • Job/step: check-ci

  • Key log excerpt:

    • Error: some files are not up-to-date... Modified: [beats go.mod go.sum]
  • Job/step: :package: linux/amd64: tar.gz (same pattern across other package jobs)

  • Key log excerpts:

    • ../../beats/metricbeat/beater/metricbeat.go:215:10: undefined: cfgfile.SetRunnerConfigs
    • ../../beats/x-pack/filebeat/input/azureeventhub/auth.go:50:22: undefined: newWorkloadIdentityCredential
    • ../../beats/x-pack/osquerybeat/internal/osqd/osqueryd.go:834:23: undefined: enforceFIPSFlags

Verification

  • Reviewed provided artifacts:

    • /tmp/gh-aw/buildkite-failures.txt
    • /tmp/gh-aw/buildkite-logs/elastic-agent-check-ci.txt
    • package logs under /tmp/gh-aw/buildkite-logs/elastic-agent-package-*.txt
  • No local rerun was performed in this workflow.

Follow-up

  • I checked prior detective comments; the most recent prior comment on this PR reported a different failure mode (integration test failures in build 50667), so this is not a duplicate.
  • I did not find a matching open flaky-test issue for this compile/checkout-state failure pattern.

What is this? | From workflow: Observability Agentic Workflow — Status

Give us feedback! React with 🚀 if perfect, 👍 if helpful, 👎 if not.

@swiatekm
swiatekm marked this pull request as draft November 25, 2026 11:57
@infra-vault-gh-plugin-prod

Copy link
Copy Markdown

💚 Build Succeeded

History

cc @swiatekm

This branch has not been deployed

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

Labels

backport-9.6 Automated backport to the 9.6 branch enhancement New feature or request Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants