Skip to content

← Tutorials overview

11. Logs

Reference

The reference for this topic is Inspect & monitor.

Every ingestion leaves a row in the follow-up table (FS_FOLLOW_UP): what ran, when, for which business date and segment, and how it ended. Read it whenever you need to answer "did that run finish?" or "which runs failed last week?". The console log (DISPLAY_LOGS) tells the same story as it happens.

import dataclasses
import getpass
import os

import tdfs4ds                      # importing it first also loads a .env file, if you have one
import teradataml as tdml

# 1. Open the Teradata session. Host and user come from the environment (TDFS4DS_TD_HOST,
#    TDFS4DS_TD_USERNAME), the password from TDFS4DS_TD_PASSWORD or a prompt: nothing secret
#    is written on this page.
host = os.environ["TDFS4DS_TD_HOST"]
user = os.environ["TDFS4DS_TD_USERNAME"]
password = os.environ.get("TDFS4DS_TD_PASSWORD") or getpass.getpass("Teradata password: ")
tdml.create_context(host=host, username=user, password=password)

# 2. Pick your industry. This is the ONLY line to change: retail, banking, healthcare, pharma,
#    manufacturing, assembly, energy or transportation. Every name below comes from S.
S = tdfs4ds.tutorial_scenario("retail")

# 3. Connect to the feature store (created when missing) and choose a data domain. disposable=True
#    records that this domain is an experiment, so the last page removes it in one call.
DATABASE = os.environ.get("TDFS4DS_TD_DATABASE") or user
tdfs4ds.connect(database=DATABASE, create_if_missing=True)
tdfs4ds.create_data_domain(f"TUTORIAL_{S.name.upper()}", disposable=True)   # an experiment: removable in one call

# 4. The tutorial data: three tables written once; a second run keeps them.
try:
    S = tdfs4ds.create_tutorial_data(S.name, DATABASE)
except ValueError:
    S = dataclasses.replace(S, database=DATABASE)


def register_entity_features():
    """Page 1 in one call: (re)register the entity features and return the process id."""
    sql = f"""
        SELECT {S.entity}, COUNT(*) AS nb_events, SUM({S.amount}) AS total_amount,
               AVG({S.amount}) AS avg_amount, COUNT(DISTINCT {S.partner}) AS nb_partners
        FROM {S.table('events')}
        GROUP BY 1"""
    return tdfs4ds.upload_features(
        df=None, sql_query=sql, target_view_name=f"{S.database}.{S.name}_entity_features",
        entity_id=[S.entity], feature_names=["nb_events", "total_amount", "avg_amount", "nb_partners"],
        replace=True, document=False, optimize_query=False, return_process_id=True)

process_id = register_entity_features()

You should see a process id.

1 · The console log

tdfs4ds.DISPLAY_LOGS = True        # the default: INFO lines for every step
tdfs4ds.run(process_id, force_compute=True)
tdfs4ds.DISPLAY_LOGS = False       # quiet, e.g. inside a loop over many processes
tdfs4ds.run(process_id, force_compute=True)
tdfs4ds.DISPLAY_LOGS = True

You should see log lines for the first run (process opened, features prepared, values merged, statistics, run completed) and nothing for the second one. Keep the display on while you learn; the follow-up table below records every run whatever the display says.

2 · Read the follow-up report

follow_up = tdfs4ds.follow_up_report(process_id=process_id).to_pandas().reset_index()
print(follow_up[["RUN_ID", "START_DATETIME", "END_DATETIME", "VALIDTIME_DATE", "STATUS"]].head())
                                 RUN_ID  ...     STATUS
0  <run id>  ...  COMPLETED
1  <run id>  ...  COMPLETED
...
[5 rows x 5 columns]

Output (columns shortened): one row per run of this process, most recent first, with STATUS COMPLETED. Without process_id, the report covers every process.

Column Meaning
RUN_ID Identifier of the Python session's run (one per import, with the process id)
PROCESS_ID The registered process
START_DATETIME / END_DATETIME When the run opened and closed (the end is empty while it runs)
VALIDTIME_DATE The business date of the run (empty for a real-time run)
APPLIED_FILTER The FilterManager segment (JSON), for a segmented run
STATUS RUNNING, COMPLETED, COMPLETED,0 rows or FAILED,<error>

3 · Find the failures

everything = tdfs4ds.follow_up_report().to_pandas().reset_index()      # every process of the store
mine = tdfs4ds.process_catalog(as_pandas=True)["PROCESS_ID"]            # the processes of this data domain
everything = everything[everything["PROCESS_ID"].isin(mine)]
failures = everything[everything["STATUS"].str.startswith("FAILED")]
print(len(failures), "failed runs")
print(failures[["PROCESS_ID", "START_DATETIME", "STATUS"]].head())
                                 RUN_ID  ...     STATUS
0  <run id>  ...  COMPLETED
1  <run id>  ...  COMPLETED
...
[5 rows x 5 columns]

Output: 0 failed runs when only this page's process has run. After module 9, whose refusal is provoked on purpose, the failed row is listed here with its message (shortened):

1 failed runs
                             PROCESS_ID  ...                                             STATUS
5  <process id>  ...  FAILED,Invalid process: NULL value(s) in entit...
[1 rows x 3 columns]

A failed run writes FAILED,<message> (the error, up to 2,048 characters) on its own row, so a segment that fails is visible beside the segments that completed.

Status lifecycle

open  ->  RUNNING
          |-- success            ->  COMPLETED  (COMPLETED,0 rows when nothing was written)
          '-- exception          ->  FAILED,<message>

A row that stays RUNNING for hours is stale: the Python process was killed before the run could close. Re-run the process (tdfs4ds.run(process_id, force_compute=True)), and tdfs4ds.close_interrupted_runs(dry_run=True) lists and closes such rows. Production loops use on_failure="raise" so a failure is not silent (Operate in production).

Clean up

Nothing to remove: the follow-up rows are history. remove_process deletes the process's rows along with it.

Learn more

  • Inspect & monitor: full follow_up_report reference, plus process_catalog, feature_catalog, dataset_catalog.
  • Temporal model: the write lifecycle and why a RUNNING row left after a crash is the signal of an incomplete ingestion.