You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"""Simple function to add two numbers that is not aware of the request id"""
106
-
106
+
107
107
logging.debug('Called generic_add({}, {}) from request_id: {}'.format(a, b, current_request_id()))
108
108
return a + b
109
-
109
+
110
110
@app.route('/')
111
111
defindex():
112
112
a, b = randint(1, 15), randint(1, 15)
113
113
logging.info('Adding two random numbers {}{}'.format(a, b))
114
114
returnstr(generic_add.delay(a, b)) # Calling the task here, will forward the request id to the workers
115
115
```
116
116
117
-
You can follow the same logging strategy for both web application and workers using the `RequestIDLogFilter` as shown in
117
+
You can follow the same logging strategy for both web application and workers using the `RequestIDLogFilter` as shown in
118
118
example 1 and 2.
119
119
120
+
### Example 4: If you want to return request id in response
121
+
122
+
This will be useful while integrating with frontend where in you can get the request id from the response (be it 400 or 500) and then trace the request in logs.
123
+
124
+
```python
125
+
from flask_log_request_id import current_request_id
0 commit comments