✨ Add support for generating a UUID on application startup by fadyNabil16 · Pull Request #15243 · fastapi/fastapi

Summary

This PR introduces a mechanism to generate a unique UUID when the application starts. This UUID can be used to uniquely identify each running instance of the application, which is especially useful in distributed or containerized environments.

Motivation

In modern deployments (e.g., Docker, Kubernetes), multiple instances of the same application may run concurrently. Having a unique identifier per instance helps with:

  • Logging and debugging across multiple instances
  • Observability and tracing
  • Instance-level metrics and monitoring

Changes

  • Generate a UUID during application startup
  • Ensure the UUID is created once per application lifecycle

Usage

The generated UUID can be accessed within the application (e.g., via app state or configuration) and used in logs, responses, or internal processing.