Logging served features
A logger records what the serving engine computed for each call of a prepared statement, at the time it computed it: a trace of every answer, and training data without skew ( Train on what serving saw ).
A logger is a feature, like a prepared statement. It names the prepared statement whose calls it logs, the sink it writes to, and optionally which columns to drop and which rows to keep. It never changes the statement: adding, changing or removing a logger does not recompile it, and a logger never slows or fails a call.
What to log: CAPTURE
A prepared statement returns one feature. To log more, list features in CAPTURE: they are computed in the same call, from the same reads, and never returned to the caller.
CREATE OR REPLACE FEATURES IN FM.TUTORIALS.LOGGING AS
PERSIST
user_id := INPUT(BIGINT),
req_ts := INPUT(TIMESTAMP),
basket_value := user_id * 12,
score := ROW(basket_value / 100.0 AS value, 'v1' AS model),
score_ps := PREPARED_STATEMENT(
score
USING (user_id, req_ts := REQUEST_TIME())
CAPTURE (basket_value)
)
;| feature_name VARCHAR | status VARCHAR | message VARCHAR |
|---|---|---|
| FM.TUTORIALS.LOGGING.USER_ID | CREATED | Feature created as not exists |
| FM.TUTORIALS.LOGGING.REQ_TS | CREATED | Feature created as not exists |
| FM.TUTORIALS.LOGGING.BASKET_VALUE | CREATED | Feature created as not exists |
| FM.TUTORIALS.LOGGING.SCORE | CREATED | Feature created as not exists |
| FM.TUTORIALS.LOGGING.SCORE_PS | CREATED | Feature created as not exists |
Where to write: SINK
A sink is a feature too, so several loggers can share one:
CREATE OR REPLACE FEATURE FM.TUTORIALS.LOGGING.ML_LOGS AS SINK('file:///tmp/featuremesh_logs' WITH (FORMAT = 'jsonl'));| feature_name VARCHAR | status VARCHAR | message VARCHAR |
|---|---|---|
| FM.TUTORIALS.LOGGING.ML_LOGS | CREATED | Feature created as not exists |
| Scheme | Formats | Written as |
|---|---|---|
s3://, gs://, az:// | 'parquet' (default), 'jsonl' | Files rolled every minute or 64 MB, credentials from the server's environment |
file:// | 'parquet' (default), 'jsonl' | Parquet files as above; JSON lines appended to <dir>/<logger>/<boot_id>-<seq>.jsonl, a new file every hour |
stdout:// | 'jsonl' | One JSON object per line, with "fm_logger" set to the logger's name |
FORMAT defaults to 'parquet' for every scheme but stdout://, including file://. The serving engine embedded in the Python library writes JSON lines only ( Logging ).
Parquet files, and JSON lines written to object storage, are partitioned the way DuckDB, Spark, Trino, BigQuery and Snowflake read them: <sink>/<logger>/statement=<hash>/date=YYYY-MM-DD/hour=HH/<file>. The statement hash changes when the statement or the logged columns change, so one partition has one schema. A new process starts new files, so file names do not sort by time: read call_time.
Each sink sets how its files are cut, so a 10,000 QPS endpoint and a 50 QPS one can log to sinks of their own:
| Property | Values | Default |
|---|---|---|
COMPRESSION | 'zstd', 'snappy', 'gzip', 'none' (Parquet only) | 'zstd' |
ROLL_SECONDS | 1 to 3600: a file is closed and uploaded once this old | 60 (the server's serving.logging.roll_interval); file:// JSON lines: every hour |
ROLL_MB | 1 to 1024: a file is closed once this large | 64 (the server's serving.logging.roll_size_mb) |
-- A busy endpoint: fewer, bigger files
CREATE OR REPLACE FEATURE FM.SHOP.SCORE_LOGS AS
SINK('s3://ml-logs/score' WITH (FORMAT = 'parquet', ROLL_SECONDS = 300, ROLL_MB = 256)); An open file is held in memory until it is uploaded, and a crash loses it: a longer ROLL_SECONDS means fewer files, later rows and a larger loss.
A logger writes cold sinks only: files, object stores and stdout://. A Redis, PostgreSQL or MySQL sink is refused (UE/LOGGER-SINK-HOT): logged rows are for training, audit and other systems, never read back by serving.
stdout:// and file:// with 'jsonl' are meant for a collector (Vector, Fluent Bit, an OpenTelemetry collector) that ships the lines where you want them.
The logger
CREATE OR REPLACE FEATURE FM.TUTORIALS.LOGGING.SCORE_LOGGER AS
LOGGER(
ON FM.TUTORIALS.LOGGING.SCORE_PS
WHERE HASH01('log/' || FM.TUTORIALS.LOGGING.USER_ID::VARCHAR) <.6 0.5
EXCLUDE (FM.TUTORIALS.LOGGING.SCORE[model])
TO FM.TUTORIALS.LOGGING.ML_LOGS
);| feature_name VARCHAR | status VARCHAR | message VARCHAR |
|---|---|---|
| FM.TUTORIALS.LOGGING.SCORE_LOGGER | CREATED | Feature created as not exists |
ONnames the prepared statement, andTOthe sink, after the optionalWHEREandEXCLUDE, in this order.EXCLUDE (...)drops inputs, the output, captures, or fields of a ROW (SCORE[model],SCORE[embedding][dim]).WHEREkeeps a row when it is TRUE. Hashing the key, rather than drawing at random, keeps whole histories: a user is either always logged or never.A call that fails is always logged, whatever
WHEREsays, with its inputs and its error.
WHERE reads the call's row only: the statement's inputs, its output and its captures. To filter on anything else, capture it first:
CREATE OR REPLACE FEATURE FM.TUTORIALS.LOGGING.BAD_LOGGER AS
LOGGER(ON FM.TUTORIALS.LOGGING.SCORE_PS WHERE INPUT(BIGINT) > 1 TO FM.TUTORIALS.LOGGING.ML_LOGS);A logged row
The caller receives the score, not the captured basket value:
FM.TUTORIALS.LOGGING.SCORE_PS{"input_1": [[1], [2], [3]]} | USER_ID BIGINT | REQ_TS VARCHAR | SCORE_PS ROW |
|---|---|---|
| 1 | * | {value: 0.12, model: v1} |
| 2 | * | {value: 0.24, model: v1} |
| 3 | * | {value: 0.36, model: v1} |
Each row the logger keeps holds:
| Column | Type | Content |
|---|---|---|
call_id | VARCHAR | UUIDv7 of the call, shared by its rows; sorts by time |
call_index | BIGINT | Position of the row in the call, from 1. (call_id, call_index) is the key |
call_time | TIMESTAMP | Time the call started (UTC), the value of an input bound to REQUEST_TIME(). For a hook's call, its REQUEST_TIME(): the record's Kafka timestamp, or the drain's time, so a replay logs rows dated in the past, and the date=/hour= partitions follow it |
call_details | ROW | status (OK, PARTIAL when only guarded source reads failed, ERROR), error_code, error_message, latency_ms, row_count, server_version, boot_id, sources (one entry per failed source and kind: source, kind, message, features, failed_keys, requested_keys, call_indexes, guarded), timings (where the call's time went, in ms: total_ms, transpile_ms, plan_ms, compute_ms, and sources, one entry per source kind read: source (sql, redis, http), calls, window_ms, summed_ms; the same numbers as the response's timings), path (serving, or the full name of the hook that ran the call), source, a ROW<partition INTEGER, offset BIGINT, drain BIGINT>: an event hook's run has its record's partition and offset, drain NULL; a scheduled hook's run has its drain number, partition and offset NULL; a hook ON a statement has its trigger's; a serving call has NULL |
| inputs, output, captures | their types | Named like query outputs (fm.tutorials.logging.basket_value), minus EXCLUDE |
Loggers are served definitions: SHOW SERVING STATUS lists them, and a logger whose sink cannot be opened is ERROR while calls are still served.
SHOW SERVING STATUS LIKE 'FM.TUTORIALS.LOGGING.SCORE_LOGGER';| FEATURE VARCHAR | KIND VARCHAR | STATUS VARCHAR | MESSAGE VARCHAR | SINCE VARCHAR |
|---|---|---|---|---|
| LOADED |
SHOW SERVING LOGS [LIKE '<logger>'] [LIMIT n]; lists the last rows each logger kept (100 per logger), with WHERE and EXCLUDE applied: what the sink receives, checked without opening it. Each row starts with LOGGER, its SINK and SINK_URL (without credentials), then the call columns as in the sink. RECORD holds the inputs, output and captures as JSON. It is a quick check: read the sink for the typed rows.
SHOW SERVING LOGS LIKE 'FM.TUTORIALS.LOGGING.SCORE_LOGGER' LIMIT 3;| LOGGER VARCHAR | SINK VARCHAR | SINK_URL VARCHAR | CALL_ID VARCHAR | CALL_INDEX BIGINT | CALL_TIME TIMESTAMP | CALL_DETAILS ROW(status VARCHAR, error_code VARCHAR, error_message VARCHAR, latency_ms DOUBLE, row_count BIGINT, server_version VARCHAR, boot_id VARCHAR, path VARCHAR, source ROW(partition INTEGER, "offset" BIGINT, drain BIGINT)) | RECORD VARCHAR |
|---|---|---|---|---|---|---|---|
| FM.TUTORIALS.LOGGING.SCORE_LOGGER | FM.TUTORIALS.LOGGING.ML_LOGS | file:///tmp/featuremesh_logs | OK | "fm.tutorials.logging.basket_value": |
Delivery
A logger is best effort. It keeps what it delivers, and a row can be missing while the call succeeded.
- After the call. A logger runs right after each call. For a hook's call, that is before the hook's sinks are written and its offsets committed.
- A bounded queue. Rows wait in a queue of bounded size (
serving.logging). When it is full, calls are dropped and counted ( Metrics ). - A failed write drops its rows, after its upload attempts, and counts them.
- A crash loses the rows not yet written. A featuremeshd that is stopped writes them before it exits, within a grace period ( Shutdown ).
- A row can be logged twice. A hook's batch computed again, or run again after a crash, logs its calls again ( Write results to Kafka ).
Training on the logs
Joining the logs to labels, and replaying a logged call, are in Train on what serving saw .
With the Python library
The serving engine embedded in the Python library runs the same loggers, and hands their rows to your code right after each call: Logging from Python .