0Pricing
MLOps Academy · レッスン

予測用の構造化ログ

入力、出力、レイテンシーをJSONとして記録します。

「予測用の構造化ログ」はCoddyKit上の無料MLOps Academyレッスンです。 これはレッスン1/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはMLOps Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 MLOps Academyコースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

Why Log Predictions

Once your model serves real users, you cannot watch it by hand. Logging every prediction is how you see what it actually does in production. 📊

Plain Text Is Painful

A log line like "got request, returned 0.91" reads fine to you but is brutal to search at scale. Machines need structure, not prose.

Structured Logging

Structured logging means each log line is a small object of named fields, not a sentence. Tools can then filter, group, and aggregate them instantly.

JSON Is the Format

The common choice is one JSON object per line. Every field has a key, so log systems parse it the same way every time.

{"event": "prediction", "model": "churn-v3", "score": 0.91}

What to Log per Prediction

For each call, capture the inputs, the output, and how long it took. Together these let you debug, audit, and measure quality later.

Log the Latency

Always record latency in milliseconds. It is your earliest warning that a model or its server is starting to struggle.

import time
start = time.perf_counter()
score = model.predict(x)
latency_ms = (time.perf_counter() - start) * 1000

Add an ID to Trace It

Give every request a unique request_id. Later you can follow one prediction across logs, dashboards, and the eventual real outcome.

import uuid
request_id = str(uuid.uuid4())

Build the Log Record

Collect your fields into one dictionary. This single record becomes one searchable JSON line in your logs.

record = {
    "request_id": request_id,
    "model": "churn-v3",
    "score": score,
    "latency_ms": latency_ms,
}

Emit JSON with the Logger

Use Python's built-in logging module and dump the record as JSON. Never use print, which skips levels and timestamps.

import json, logging
log = logging.getLogger("predictions")
log.info(json.dumps(record))

Never Log Raw Secrets

Be careful what goes in. Skip passwords, tokens, and raw PII, or hash sensitive fields before they ever touch a log line. 🔒

Ship Logs Somewhere Central

Logs on one server vanish when it restarts. Forward them to a central store like Loki or CloudWatch so they outlive any single container.

Quick Check

You want prediction logs you can search and aggregate at scale. What format fits best?

Recap

You log every prediction as a structured JSON record with inputs, output, latency, and an id, then ship it somewhere central. That is your eyes in production. ✅

よくある質問

「予測用の構造化ログ」レッスンは無料ですか?

はい。「予測用の構造化ログ」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、MLOps Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 MLOps Academyコースには全4レッスンが含まれています。

「予測用の構造化ログ」で何を学びますか?

入力、出力、レイテンシーをJSONとして記録します。 ブラウザで直接実行するハンズオンコードでMLOps Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

MLOps Academyを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのMLOps Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン1/4です。

「予測用の構造化ログ」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このMLOps Academyレッスンでコードを書いて実行できますか?

はい。すべてのMLOps Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. 予測用の構造化ログ
  2. Prometheusでメトリクスを公開する
  3. Grafanaダッシュボードを構築する
  4. レイテンシーとエラーの急増を検知する
← MLOps Academyに戻る