﻿# TruLens span groups: localize a metric to a logical hop instead of pooling a trace

Use TruLens span groups to distinguish logical retrieval or agent segments, accounting for nested group membership and the difference from conversation-level evaluation.

Author: Retrivium editorial team
Updated: 2026-11-04
Canonical URL: https://retrivium.ai/journal/fg2-trulens-span-groups-logical-hop-localization/
Language: en

## Define the segment you want to diagnose

A multi-step retrieval trace may contain several operations of the same type. Pooling them can hide which logical step supplied poor evidence, while judging each span separately can fragment a meaningful stage. TruLens [span groups](https://www.trulens.org/component_guides/instrumentation/span_groups/) provide labels for localizing evaluation to such segments. Define the intended unit before adding labels: a retrieval hop, source family or deliberately compared strategy, rather than whichever function boundary happens to be easiest to instrument.

## Keep grouping separate from metric selection

The group determines a local evaluation scope; the metric still needs appropriate selectors and an implementation. The [selector guide](https://www.trulens.org/component_guides/evaluation/feedback_selectors/selecting_components/) explains how span attributes become arguments. Inspect which evidence the metric receives within each group. Merely tagging spans does not prove the resulting judgment tests the desired relationship between query, retrieved material and answer. A correctly named group can still contain incomplete or incorrectly selected evidence.

## Account for nested membership

The documented grouping context merges labels when groups are nested. That means memberships can overlap rather than form a disjoint partition of the trace. Do not sum per-group counts or costs as if each underlying operation appeared only once. Preserve membership lists during diagnostics and check whether a retry should belong to its parent stage, its own diagnostic category or both. The interpretation depends on the authored grouping contract, not simply on the number of displayed groups.

## Distinguish segments from conversations

The [conversation evaluation guide](https://www.trulens.org/component_guides/instrumentation/conversation_evaluation/) describes a different scope that combines ordered records across turns. Span groups localize operations within an execution; conversation identity links a broader interaction. Choose the scope matching the capability claim. A good result for an individual retrieval hop does not establish that the complete conversation satisfied the user's evolving requirements, just as a coherent final transcript can conceal a weak intermediate evidence-gathering step.

## Verify boundaries with an inspectable trace

Use a diagnostic trace containing separate retrieval steps, a nested retry and an ungrouped operation. Check group attributes and the actual metric inputs for each segment. The guides to [pooled evidence versus aggregation](/journal/fg2-trulens-collect-list-evidence-union-mean-chunks/) and [trace export completeness](/journal/fg2-phoenix-short-lived-worker-span-export-shutdown/) provide related controls. Accept the design when group membership makes failures more localizable without inventing mutually exclusive partitions or extending a per-segment judgment into an unmeasured claim about the entire application.
