Strukturierte Logs für Vorhersagen
Protokollieren Sie Eingaben, Ausgaben und Latenz als JSON.
Strukturierte Logs für Vorhersagen ist eine kostenlose MLOps Academy-Lektion auf CoddyKit. Dies ist Lektion 1 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des MLOps Academy-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der MLOps Academy-Kurs umfasst insgesamt 4 Lektionen.
Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.
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) * 1000Add 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. ✅
Häufig gestellte Fragen
Ist die Lektion „Strukturierte Logs für Vorhersagen“ kostenlos?
Ja — der vollständige Text von „Strukturierte Logs für Vorhersagen“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des MLOps Academy-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der MLOps Academy-Kurs umfasst insgesamt 4 Lektionen.
Was lerne ich in „Strukturierte Logs für Vorhersagen“?
Protokollieren Sie Eingaben, Ausgaben und Latenz als JSON. Du übst MLOps Academy mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.
Brauche ich Erfahrung, um MLOps Academy zu starten?
Keine Vorkenntnisse erforderlich. MLOps Academy auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 1 von 4.
Wie lange dauert die Lektion „Strukturierte Logs für Vorhersagen“?
Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.
Kann ich in dieser MLOps Academy-Lektion Code schreiben und ausführen?
Ja. Jede MLOps Academy-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.
Alle Lektionen in diesem Kurs
- Strukturierte Logs für Vorhersagen
- Metriken mit Prometheus bereitstellen
- Ein Grafana-Dashboard erstellen
- Bei Latenz- und Fehlerspitzen alarmieren