Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Principle:Truera Trulens Selector Based Data Extraction

From Leeroopedia
Knowledge Sources
Domains Observability, Data_Extraction
Last Updated 2026-02-14 08:00 GMT

Overview

A data extraction pattern that targets specific attributes from OpenTelemetry spans using type-based and attribute-based filtering to provide inputs for evaluation functions.

Description

Selector-Based Data Extraction provides a mechanism for precisely targeting data within application traces. When an instrumented application runs, it produces a tree of OTEL spans with typed attributes (RECORD_ROOT, RETRIEVAL, GENERATION, TOOL, AGENT). Selectors filter these spans by type, function name, or span name, then extract specific attributes to feed into feedback functions.

This principle solves the problem of connecting evaluation logic to the right data in complex, multi-step application traces. Without selectors, users would need to manually parse trace data and extract relevant inputs/outputs for each evaluation.

Key capabilities:

  • Span type filtering: Match spans by type (e.g., only RETRIEVAL spans)
  • Function name matching: Target specific method calls within the trace
  • Attribute extraction: Pull specific attributes (input, output, kwargs, return values)
  • List collection: Aggregate data across multiple matching spans or evaluate individually

Usage

Use this principle when defining feedback functions for custom instrumented applications where the default .on_input() and .on_output() selectors are insufficient. Selectors are essential when evaluating data from intermediate steps (like retrieval contexts) or when targeting specific instrumented methods in complex applications.

Theoretical Basis

Selectors implement a query pattern over trace trees:

Pseudo-code Logic:

# Abstract selector matching algorithm
for span in trace.spans:
    if matches(span, selector.span_type, selector.function_name):
        value = extract(span.attributes, selector.span_attribute)
        if selector.collect_list:
            results.append(value)  # Aggregate all matches
        else:
            yield value  # Evaluate each independently

The design follows the Observer Pattern -- selectors declaratively describe what to observe in the trace, separating the observation specification from the trace production.

Related Pages

Implemented By

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment