anfra docs
anfra SDK

Lineage

Trace a metric or field back to what it is built from

Anfra.lineage() traces fields upstream: the metrics and model fields a metric uses, their models, and the tables behind them. Use it to show where a number comes from, such as a definitions panel next to a chart.

Anfra.lineage() comes from the lineage plugin. anfra serve installs it, but another host may not.

Tracing fields

const { results: [revenue, country] } = await Anfra.lineage([
  { parent: 'ecommerce', child: 'revenue' }, // a dataset metric
  { parent: 'customers', child: 'country' }, // a model field
])

Name each target by what holds it: a dataset and its metric, or a model and its field. Take the names from Anfra.datasets.

Anfra.lineage() is a plain promise, outside execute() and subscribe. Call it again when the reader picks another field. Check Anfra.plugins.has('lineage') before offering it: on a host without the plugin, Anfra.lineage is undefined.

Results

Each entry in results is { target, query, diagram }, or { target, query, error } when that field could not be traced. error is a string.

A diagram is a set of cards (models, datasets, tables) in layers, upstream first:

diagram.layers // [{ index, types, card_ids }, ...]
diagram.cards  // [{ id, type, label, layer, props, links, sections }, ...]
diagram.total  // matched entities, over every page

A card's sections hold its fields as nodes, which can have sections of their own. A link { to: B, type: 'refers' } on A means A uses B.

An empty diagram means nothing is upstream, as for a dimension that is a plain column.

Options and errors

  • limit and offset page the results. Pass signal from an AbortController to cancel a call.
  • The promise rejects with a ValidationError for a malformed target list, a TransportError when lineage is unavailable, or a PermissionError.

Lineage reads the catalog built by anfra ingest. Run it after you change the AML, or lineage shows the old definitions.

On this page