fastapi-gae-logging 0.0.6__tar.gz → 0.0.7__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {fastapi_gae_logging-0.0.6 → fastapi_gae_logging-0.0.7}/PKG-INFO +4 -4
- {fastapi_gae_logging-0.0.6 → fastapi_gae_logging-0.0.7}/fastapi_gae_logging/fastapi_gae_logging.py +51 -10
- {fastapi_gae_logging-0.0.6 → fastapi_gae_logging-0.0.7}/fastapi_gae_logging.egg-info/PKG-INFO +4 -4
- fastapi_gae_logging-0.0.7/fastapi_gae_logging.egg-info/requires.txt +2 -0
- {fastapi_gae_logging-0.0.6 → fastapi_gae_logging-0.0.7}/setup.py +4 -4
- fastapi_gae_logging-0.0.6/fastapi_gae_logging.egg-info/requires.txt +0 -2
- {fastapi_gae_logging-0.0.6 → fastapi_gae_logging-0.0.7}/LICENSE +0 -0
- {fastapi_gae_logging-0.0.6 → fastapi_gae_logging-0.0.7}/README.md +0 -0
- {fastapi_gae_logging-0.0.6 → fastapi_gae_logging-0.0.7}/fastapi_gae_logging/__init__.py +0 -0
- {fastapi_gae_logging-0.0.6 → fastapi_gae_logging-0.0.7}/fastapi_gae_logging.egg-info/SOURCES.txt +0 -0
- {fastapi_gae_logging-0.0.6 → fastapi_gae_logging-0.0.7}/fastapi_gae_logging.egg-info/dependency_links.txt +0 -0
- {fastapi_gae_logging-0.0.6 → fastapi_gae_logging-0.0.7}/fastapi_gae_logging.egg-info/top_level.txt +0 -0
- {fastapi_gae_logging-0.0.6 → fastapi_gae_logging-0.0.7}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: fastapi-gae-logging
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.7
|
|
4
4
|
Summary: Custom Cloud Logging handler for FastAPI applications deployed in Google App Engine. Groups logs coming from the same request lifecycle and propagates the maximum log level throughout the request lifecycle using middleware and context management.
|
|
5
5
|
Home-page: https://github.com/chrisK824/fastapi-gae-logging
|
|
6
6
|
Author: Chris Karvouniaris
|
|
@@ -8,11 +8,11 @@ Author-email: christos.karvouniaris247@gmail.com
|
|
|
8
8
|
License: MIT
|
|
9
9
|
Classifier: Programming Language :: Python :: 3
|
|
10
10
|
Classifier: Operating System :: OS Independent
|
|
11
|
-
Requires-Python: >=3.
|
|
11
|
+
Requires-Python: >=3.8
|
|
12
12
|
Description-Content-Type: text/markdown
|
|
13
13
|
License-File: LICENSE
|
|
14
|
-
Requires-Dist: fastapi
|
|
15
|
-
Requires-Dist: google-cloud-logging
|
|
14
|
+
Requires-Dist: fastapi
|
|
15
|
+
Requires-Dist: google-cloud-logging
|
|
16
16
|
|
|
17
17
|
# fastapi-gae-logging
|
|
18
18
|
Custom Cloud Logging handler for FastAPI applications deployed in Google App Engine to ease out logs analysis and monitoring through Google Cloud Log Explorer.
|
{fastapi_gae_logging-0.0.6 → fastapi_gae_logging-0.0.7}/fastapi_gae_logging/fastapi_gae_logging.py
RENAMED
|
@@ -56,6 +56,20 @@ class LogInterceptor(logging.Filter):
|
|
|
56
56
|
|
|
57
57
|
|
|
58
58
|
class GAERequestLogger:
|
|
59
|
+
"""
|
|
60
|
+
A logger for emitting structured request logs in Google App Engine.
|
|
61
|
+
|
|
62
|
+
This logger is designed to work with FastAPI applications deployed on Google App Engine. It logs
|
|
63
|
+
structured data after each request is handled, including the HTTP request method, URL, status,
|
|
64
|
+
user agent, response size, latency, and remote IP address. The log severity is determined by the
|
|
65
|
+
maximum log level recorded during the request.
|
|
66
|
+
|
|
67
|
+
Attributes:
|
|
68
|
+
LOG_LEVEL_TO_SEVERITY (Dict[int, str]): Mapping of Python logging levels to Cloud Logging severity levels.
|
|
69
|
+
logger (Logger): The Google Cloud Logger instance to log requests.
|
|
70
|
+
resource (Resource): The Google Cloud resource associated with the logger.
|
|
71
|
+
log_payload (bool): Whether to log the request payload for certain HTTP methods. Defaults to True.
|
|
72
|
+
"""
|
|
59
73
|
LOG_LEVEL_TO_SEVERITY: Dict[int, str] = {
|
|
60
74
|
logging.NOTSET: 'DEFAULT',
|
|
61
75
|
logging.DEBUG: 'DEBUG',
|
|
@@ -72,6 +86,7 @@ class GAERequestLogger:
|
|
|
72
86
|
Args:
|
|
73
87
|
logger (Logger): The Google Cloud Logger instance to log requests.
|
|
74
88
|
resource (Resource): The resource associated with the logger.
|
|
89
|
+
log_payload (bool): Whether to log the request payload for certain HTTP methods. Defaults to True.
|
|
75
90
|
"""
|
|
76
91
|
self.logger = logger
|
|
77
92
|
self.resource = resource
|
|
@@ -143,15 +158,41 @@ class GAERequestLogger:
|
|
|
143
158
|
|
|
144
159
|
class FastAPIGAELoggingMiddleware:
|
|
145
160
|
"""
|
|
146
|
-
|
|
147
|
-
|
|
161
|
+
Middleware to set up request start time and emit logs after request completion.
|
|
162
|
+
|
|
163
|
+
This middleware is specifically designed for FastAPI applications deployed on Google App Engine.
|
|
164
|
+
It records the start time of the request and then emits a log after the request is completed,
|
|
165
|
+
containing details about the request and response.
|
|
166
|
+
|
|
167
|
+
Attributes:
|
|
168
|
+
app (ASGIApp): The ASGI application instance.
|
|
169
|
+
logger (GAERequestLogger): The logger used to emit structured logs.
|
|
148
170
|
"""
|
|
149
171
|
|
|
150
172
|
def __init__(self, app: ASGIApp, logger: GAERequestLogger):
|
|
173
|
+
"""
|
|
174
|
+
Initialize the middleware.
|
|
175
|
+
|
|
176
|
+
Args:
|
|
177
|
+
app (ASGIApp): The ASGI application instance.
|
|
178
|
+
logger (GAERequestLogger): The logger instance used to log request data.
|
|
179
|
+
"""
|
|
151
180
|
self.app = app
|
|
152
181
|
self.logger = logger
|
|
153
182
|
|
|
154
183
|
async def __call__(self, scope: Scope, receive: Receive, send: Send):
|
|
184
|
+
"""
|
|
185
|
+
Middleware entry point, invoked for each request.
|
|
186
|
+
|
|
187
|
+
This method sets up the request context with trace information, start time, and initial log level.
|
|
188
|
+
It then intercepts the response to capture details for logging. In case of exceptions, they are
|
|
189
|
+
logged, and the exception is re-raised.
|
|
190
|
+
|
|
191
|
+
Args:
|
|
192
|
+
scope (Scope): The ASGI scope dictionary containing request information.
|
|
193
|
+
receive (Receive): The receive channel for incoming messages.
|
|
194
|
+
send (Send): The send channel for outgoing messages.
|
|
195
|
+
"""
|
|
155
196
|
if scope["type"] == "http":
|
|
156
197
|
|
|
157
198
|
# https://stackoverflow.com/questions/64115628/get-starlette-request-body-in-the-middleware-context
|
|
@@ -171,10 +212,10 @@ class FastAPIGAELoggingMiddleware:
|
|
|
171
212
|
'max_log_level': logging.NOTSET
|
|
172
213
|
})
|
|
173
214
|
|
|
174
|
-
#
|
|
215
|
+
# Default response in case of an error
|
|
175
216
|
response = Response(status_code=500)
|
|
176
217
|
|
|
177
|
-
#
|
|
218
|
+
# Intercept the sent message to get the response status and body
|
|
178
219
|
# for later use
|
|
179
220
|
async def send_spoof_wrapper(message: Dict[str, Any]) -> None:
|
|
180
221
|
if message["type"] == "http.response.start":
|
|
@@ -195,9 +236,11 @@ class FastAPIGAELoggingMiddleware:
|
|
|
195
236
|
|
|
196
237
|
class FastAPIGAELoggingHandler(CloudLoggingHandler):
|
|
197
238
|
"""
|
|
198
|
-
Custom Cloud Logging handler for FastAPI applications deployed
|
|
199
|
-
|
|
200
|
-
|
|
239
|
+
Custom Cloud Logging handler for FastAPI applications deployed on Google App Engine.
|
|
240
|
+
|
|
241
|
+
This handler groups logs from the same request lifecycle and propagates the maximum log level
|
|
242
|
+
observed throughout the request. It also integrates with FastAPI by adding middleware that
|
|
243
|
+
handles request and response logging.
|
|
201
244
|
"""
|
|
202
245
|
|
|
203
246
|
REQUEST_LOGGER_SUFFIX: str = '-request-logger'
|
|
@@ -216,9 +259,7 @@ class FastAPIGAELoggingHandler(CloudLoggingHandler):
|
|
|
216
259
|
app (FastAPI): The FastAPI application instance.
|
|
217
260
|
request_logger_name (Optional[str]): The name of the Cloud Logging logger to use for request logs.
|
|
218
261
|
Defaults to the Google Cloud Project ID with '-request-logger' suffix.
|
|
219
|
-
log_payload (bool): Whether to log the request payload
|
|
220
|
-
POST, PUT, PATCH, and DELETE requests will be logged.
|
|
221
|
-
Defaults to True.
|
|
262
|
+
log_payload (bool): Whether to log the request payload for certain HTTP methods. Defaults to True.
|
|
222
263
|
*args: Additional arguments to pass to the superclass constructor.
|
|
223
264
|
Any argument you would pass to CloudLoggingHandler.
|
|
224
265
|
**kwargs: Additional keyword arguments to pass to the superclass constructor.
|
{fastapi_gae_logging-0.0.6 → fastapi_gae_logging-0.0.7}/fastapi_gae_logging.egg-info/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: fastapi-gae-logging
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.7
|
|
4
4
|
Summary: Custom Cloud Logging handler for FastAPI applications deployed in Google App Engine. Groups logs coming from the same request lifecycle and propagates the maximum log level throughout the request lifecycle using middleware and context management.
|
|
5
5
|
Home-page: https://github.com/chrisK824/fastapi-gae-logging
|
|
6
6
|
Author: Chris Karvouniaris
|
|
@@ -8,11 +8,11 @@ Author-email: christos.karvouniaris247@gmail.com
|
|
|
8
8
|
License: MIT
|
|
9
9
|
Classifier: Programming Language :: Python :: 3
|
|
10
10
|
Classifier: Operating System :: OS Independent
|
|
11
|
-
Requires-Python: >=3.
|
|
11
|
+
Requires-Python: >=3.8
|
|
12
12
|
Description-Content-Type: text/markdown
|
|
13
13
|
License-File: LICENSE
|
|
14
|
-
Requires-Dist: fastapi
|
|
15
|
-
Requires-Dist: google-cloud-logging
|
|
14
|
+
Requires-Dist: fastapi
|
|
15
|
+
Requires-Dist: google-cloud-logging
|
|
16
16
|
|
|
17
17
|
# fastapi-gae-logging
|
|
18
18
|
Custom Cloud Logging handler for FastAPI applications deployed in Google App Engine to ease out logs analysis and monitoring through Google Cloud Log Explorer.
|
|
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
|
|
|
2
2
|
|
|
3
3
|
setup(
|
|
4
4
|
name="fastapi-gae-logging",
|
|
5
|
-
version="0.0.
|
|
5
|
+
version="0.0.7",
|
|
6
6
|
description="Custom Cloud Logging handler for FastAPI applications deployed in Google App Engine. \
|
|
7
7
|
Groups logs coming from the same request lifecycle and propagates the maximum log level \
|
|
8
8
|
throughout the request lifecycle using middleware and context management.",
|
|
@@ -13,10 +13,10 @@ setup(
|
|
|
13
13
|
author_email="christos.karvouniaris247@gmail.com",
|
|
14
14
|
packages=find_packages(),
|
|
15
15
|
install_requires=[
|
|
16
|
-
"fastapi
|
|
17
|
-
"google-cloud-logging
|
|
16
|
+
"fastapi",
|
|
17
|
+
"google-cloud-logging",
|
|
18
18
|
],
|
|
19
|
-
python_requires=">=3.
|
|
19
|
+
python_requires=">=3.8",
|
|
20
20
|
license="MIT",
|
|
21
21
|
license_files=["LICENSE"],
|
|
22
22
|
classifiers=[
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{fastapi_gae_logging-0.0.6 → fastapi_gae_logging-0.0.7}/fastapi_gae_logging.egg-info/SOURCES.txt
RENAMED
|
File without changes
|
|
File without changes
|
{fastapi_gae_logging-0.0.6 → fastapi_gae_logging-0.0.7}/fastapi_gae_logging.egg-info/top_level.txt
RENAMED
|
File without changes
|
|
File without changes
|