Repository navigation
Mark the outermost GenAI span of traces with a non-GenAI root #7192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
dlvenable
merged 4 commits into
opensearch-project:main
from
ps48:fix/genai-agent-root-marker
Oct 22, 2026
+991
−56
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
3e5a02f
Mark the outermost GenAI span of traces with a non-GenAI root
ps48 5198311
Count each span's token usage once; cover agents calling agents
ps48 96742f1
Mark GenAI roots too; don't mark spans that arrive after their ancestors
ps48 242387f
Address review: atomic per-trace coverage, one index per trace, safer…
ps48 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
...r/src/main/java/org/opensearch/dataprepper/plugins/processor/oteltrace/GenAiCoverage.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| /* | ||
| * Copyright OpenSearch Contributors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * The OpenSearch Contributors require contributions made to | ||
| * this file be licensed under the Apache-2.0 license or a | ||
| * compatible open source license. | ||
| * | ||
| */ | ||
|
|
||
| package org.opensearch.dataprepper.plugins.processor.oteltrace; | ||
|
|
||
| import com.github.benmanes.caffeine.cache.Cache; | ||
| import com.github.benmanes.caffeine.cache.Caffeine; | ||
|
|
||
| import java.time.Duration; | ||
| import java.util.Collection; | ||
| import java.util.Collections; | ||
| import java.util.HashSet; | ||
| import java.util.Set; | ||
|
|
||
| /** | ||
| * Remembers, per trace, the span ids already covered by a GenAI span or an agent root marker (the | ||
| * span itself or one of its ancestors). Spans that arrive after their trace's root has been | ||
| * processed are enriched without their ancestors; this lets the agent root marker tell whether | ||
| * such a span is really outermost. | ||
| */ | ||
| final class GenAiCoverage { | ||
|
|
||
| /** Keeps nothing: every parent outside the batch counts as uncovered. */ | ||
| static final GenAiCoverage NONE = new GenAiCoverage(null); | ||
|
|
||
| private final Cache<String, Set<String>> coveredByTrace; | ||
|
|
||
| private GenAiCoverage(final Cache<String, Set<String>> coveredByTrace) { | ||
| this.coveredByTrace = coveredByTrace; | ||
| } | ||
|
|
||
| static GenAiCoverage create(final long maxSpanIds, final Duration timeToLive) { | ||
| return new GenAiCoverage(Caffeine.newBuilder() | ||
| .maximumWeight(maxSpanIds) | ||
| .<String, Set<String>>weigher((traceId, spanIds) -> spanIds.size()) | ||
| .expireAfterWrite(timeToLive) | ||
| .build()); | ||
| } | ||
|
|
||
| Set<String> covered(final String traceId) { | ||
| if (coveredByTrace == null || traceId == null) { | ||
| return Collections.emptySet(); | ||
| } | ||
| final Set<String> spanIds = coveredByTrace.getIfPresent(traceId); | ||
| return spanIds == null ? Collections.emptySet() : spanIds; | ||
| } | ||
|
|
||
| void record(final String traceId, final Collection<String> spanIds) { | ||
| if (coveredByTrace == null || traceId == null || spanIds.isEmpty()) { | ||
| return; | ||
| } | ||
| coveredByTrace.asMap().merge(traceId, new HashSet<>(spanIds), (existing, added) -> { | ||
| final Set<String> merged = new HashSet<>(existing); | ||
| merged.addAll(added); | ||
| return merged; | ||
| }); | ||
| } | ||
|
|
||
| long estimatedSize() { | ||
| return coveredByTrace == null ? 0 : coveredByTrace.estimatedSize(); | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[AI agent finding #10 — cleanup]
estimatedSize()is dead code; the cache has no gauge and no config knob.Nothing calls this method — it mirrors the gauge pattern used for
traceIdTraceGroupCache/traceIdSpanSetMap(traceGroupCacheCount,spanSetCount), but no gauge is ever registered forgenAiCoverage. Without it, operators can't see the 500k-span-id cache filling or evicting under weight pressure — and eviction produces the same late-span mismarking the cache exists to prevent.Suggestion: register
pluginMetrics.gauge(...)for it like the sibling caches (which appears to have been the intent), and consider makingGENAI_COVERAGE_MAX_SPAN_IDSconfigurable alongsidetrace_group_cache_max_size.