In this article
A replica-local ASGI builder avoids serializing the constructed app, but its dependencies and initialization must still work in every replica environment.
Telemetry changes where application construction must happen
A FastAPI application works locally, then fails while being packaged for Ray Serve after telemetry is added. The issue can be a nonserializable object captured inside the constructed application, rather than an invalid route or inference model. Moving the construction boundary is a different remedy from removing monitoring or changing GPU resources. First identify which object is serialized and which initialization should instead happen inside the replica that will own it.
Object ingress and builder ingress carry different objects
The Serve HTTP guide describes the factory pattern for applications containing components such as thread locks. In the object-based form, the app must be serializable. In the builder form, a callable constructs the app on each replica. The callable and its captured environment still need an appropriate deployment boundary; moving an already-created unpicklable object into a closure does not magically remove that object from what must be transported.
Replica initialization is the documented builder boundary
The ingress API explains that the builder is evaluated during replica initialization. Construct replica-owned clients and middleware in that intended scope. Handlers declared inside a factory do not automatically gain access to a deployment instance’s attributes; explicitly arrange the dependencies they need. The startup resource guide supplies background on separating host-side orchestration from GPU work, but does not replace application-level ownership decisions.
Instrumentation must be installed consistently
The OpenTelemetry FastAPI instrumentation documentation describes application instrumentation interfaces. Confirm the installed dependency set and initialization behavior in a fresh replica, including any exporters and configuration it requires. Avoid applying instrumentation twice through both global startup and the factory. Verify route responses and emitted telemetry separately: a successful HTTP request can coexist with missing traces, while emitted traces do not prove the inference response is correct.
Reproduce construction on a clean replica
Test a newly started replica rather than only a long-lived development process with preinitialized imports. Record the factory code, dependency versions and application configuration alongside the release identity. Use artifact verification to connect that identity to the tested deployment package. The desired evidence is repeatable construction with correct routes and observability; the factory pattern itself is not a guarantee that any captured object, external client or middleware lifecycle will be safe automatically.
Earn rental income from GPUs
Have idle GPUs or looking to fund AI infrastructure? Retrivium finds a rental platform, sets up the server and helps you assess income and costs with a pilot.