I would start model deployment logging with five event types: request identity, release identity, stage timing, classified failure, and execution context. Together, they help answer whether a request reached the intended version, where it spent time, and how it ended. More output is useful only when it closes a specific gap in that explanation.
This is a compact event contract for an inference service on Beam. It complements platform logs; it does not require copying prompts, responses, or credentials into every record.
Follow a missing result before choosing fields
Imagine a caller says an extraction request never returned. I would first look for its accepted request record, then its release identity, completed stages, and terminal outcome. This is a diagnostic exercise, not a report of a particular outage.
An admission event without a terminal event leaves several possibilities: the process exited, work is still running, or telemetry was lost. An application terminal event reporting success also does not prove the caller received the response. That distinction determines whether I inspect execution, delivery, or collection next.
I would keep a small schema version on these records. Field names tend to become an informal API for queries and dashboards; changing their meaning without changing the schema can quietly invalidate an investigation.
The five categories below are deliberately about different questions. They need not be five separate lines for every request. Release and resource details can live in a startup record referenced by request events, reducing duplication.
1. Request identity: which attempt belongs to which job?
For request ID logging in Python, I would distinguish a logical operation from a physical attempt. The operation identifies the caller's intended job; each retry gets its own attempt ID. A platform task or container identifier provides another lookup path when available.
Field | Meaning | Mistake it prevents |
|---|---|---|
operation_id | One intended business operation | Counting retries as new work |
request_id | One API request | Mixing concurrent callers |
attempt_id | One execution attempt | Hiding repeated execution |
parent_id | Calling workflow or upstream span | Losing a handoff |
schema_version | Meaning of the event fields | Comparing incompatible records |
I would validate inbound identifiers for length and allowed characters, or generate my own and store a bounded correlation value. Raw caller text should not become an unlimited log field.
A request ID is a lookup key, not permission to see the request. The log reader still needs appropriate access controls, especially when an identifier can be joined to another system containing personal information.
2. Release identity: what code and model actually ran?
A label such as “latest” is convenient for routing and poor evidence for a historical investigation. I would retain the deployment ID, application revision, model revision, tokenizer revision, and relevant inference settings through an immutable configuration reference.
Google Cloud's ML quality guidance recommends tracking lineage and configuration. My inference-specific application is to make a request joinable to the exact release manifest, including prompt and output-schema versions where those affect behavior.
The manifest should contain reproducible references, not secrets. For downloaded artifacts, I would retain a resolved revision or content digest when the tool supports it. A model name alone cannot distinguish two different sets of files published under a moving reference.
If a failure appears only after deployment, I would compare manifests before changing hardware. A dependency update, tokenizer change, or output limit may explain the difference more directly than the GPU model.

3. Stage timing: where did the waiting happen?
One total duration can tell me a request became slower. It cannot distinguish decoding an uploaded file from loading weights or waiting on an external tool.
I would start with a few meaningful stages: input preparation, model execution, output validation, and external calls. Record durations with a monotonic clock inside one process, and retain a wall-clock timestamp for ordering and cross-system investigation. Never subtract unrelated machines' monotonic timestamps.
For asynchronous GPU work, a Python function returning may mean kernels were scheduled rather than finished. PyTorch's CUDA notes describe this timing issue. I would use an appropriate synchronized measurement or device events for a focused benchmark, while recognizing that instrumentation can change concurrency.
I would also keep initialization timing separate from request execution. A warm handler cannot explain everything the first caller waited through. Queue admission and client-side timing need their own observation points; I would not invent queue duration by subtracting partially overlapping measurements.
For structured logging for an inference API, the useful property is consistent meaning. Milliseconds in one event and seconds in another are a more serious problem than whether the JSON is attractive.
4. Classified failure: what is the next useful action?
I would keep outcome, failure class, failed stage, and a bounded error code. “Failed” alone cannot distinguish bad input from unavailable capacity or an invalid generated response.
Useful categories might include input rejection, dependency failure, model execution failure, output validation failure, cancellation, and unknown outcome. These are application choices, not Beam's promised event taxonomy.
An error message may contain submitted text, URLs, headers, or file paths. I would store reviewed diagnostic context and restrict detailed exception collection rather than send every exception string to a broadly accessible stream.
A successful HTTP status with a rejected JSON schema belongs in the quality investigation. A connection timeout after a write-capable tool call belongs in an outcome-reconciliation path. Neither becomes safe to retry merely because an exception was caught.
I want a failure record to suggest the next check, not to declare a root cause the program has not established.
5. Execution context: what resources and limits applied?
I would attach or reference configured GPU type, worker count, memory limits, timeout policy, and concurrency settings. Observed resource measurements need their own sampling window and scope.
Allocated GPU memory is not the same as active compute, and a single utilization sample cannot explain an entire slow request. I would correlate an interval of measurements with stage timings before declaring a CPU or GPU bottleneck.
For Beam deployment logs, the official observability page documents application, system, and resource views. I would use system logs for container startup or exit questions and application events for task-specific decisions. During a rollout, I would target a deployment ID rather than assume the app name selects the version I mean.

Give the event a small, explicit shape
Here is an illustrative terminal event, with synthetic identifiers and invented duration. It demonstrates field relationships, not actual platform output:
{
"schema_version": 1,
"event": "request.finished",
"operation_id": "demo-job-17",
"request_id": "demo-request-02",
"attempt_id": "demo-attempt-01",
"release_ref": "demo-release-a",
"outcome": "rejected",
"failure_class": "output_validation",
"failed_stage": "validate",
"elapsed_ms": 240.0
}I would configure a JSON formatter for the application logger and pass bounded context consistently. Python's Logging Cookbook covers ways to add contextual information; the example above is an original schema, not a built-in Beam format.
The cost is discipline. Someone must maintain field definitions, retention, redaction, and access. I would rather keep this contract small than introduce dozens of optional fields nobody can query reliably.
For collection volume, I would estimate events per request before enabling verbose stage records everywhere. Ten events across a million requests have a different storage and search cost from ten events during a private test. Keep essential outcomes consistently, and choose any sampling policy with a clear account of which investigations it makes impossible.
Sampling also needs correlation. If related stages are sampled independently, a retained request may lose the very event that explains it. I would prefer a consistent decision for related diagnostic events, while separately preserving the minimal records needed for accounting and failure investigation. The exact policy depends on privacy, retention, and cost requirements; there is no universal logging percentage.
For an asynchronous handoff, I would include the parent operation and child task reference on both sides. Otherwise the producer can report successful submission while the consumer fails under an identifier nobody knows to search. That join is often more useful than another paragraph of exception text.
Test the explanation with synthetic failures
Before relying on the records, I would exercise one invalid input, one output-schema rejection, one dependency timeout, and one interrupted worker. For each, check the joins, the terminal state where available, and the gap that still requires platform evidence.
I would also check collection itself: buffering, dropped records, retention limits, and what happens if the log destination fails. Missing evidence should remain visible as missing evidence.
Start with one synthetic rejected request. Follow its operation ID to the release and failed stage, and write down the first question the records cannot answer. That question tells you which field or observation point to add next.
No letters yet — be the first to write.