From the course: Build REST APIs with FastAPI
Unlock this course with a free trial
Join today to access over 24,400 courses taught by industry experts.
Logging and metrics - Python Tutorial
From the course: Build REST APIs with FastAPI
Logging and metrics
Your server is running at production somewhere and your eyes to what's happening are the logging and metrics. The metric answers what's going on now. How many requests we have? How many errors? What's the average time for a database query, et cetera? And they can show you that there is something wrong going on. Logging is helping you after the fact. How did we get here? We had an incident. Let's query the log, see what's brought us here. And it's important with logging to remember that they should help you during an incident. So you should rely on them during development as well. As Billy Kennedy said, if logs don't help you during development, they won't help you during an incident at 4:00 a.m. in the morning. There are many libraries for metrics. One of the main one is Prometheus. There's also the OpenTelemetry standard, and there are hosting companies such as Datadog and others. In logging, there is one single solution in Python. There are other logging libraries, but please use…