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"""
104
-
104
+
105
105
logging.debug('Called generic_add({}, {}) from request_id: {}'.format(a, b, current_request_id()))
106
106
return a + b
107
-
107
+
108
108
@app.route('/')
109
109
defindex():
110
110
a, b = randint(1, 15), randint(1, 15)
111
111
logging.info('Adding two random numbers {}{}'.format(a, b))
112
112
returnstr(generic_add.delay(a, b)) # Calling the task here, will forward the request id to the workers
113
113
```
114
114
115
-
You can follow the same logging strategy for both web application and workers using the `RequestIDLogFilter` as shown in
115
+
You can follow the same logging strategy for both web application and workers using the `RequestIDLogFilter` as shown in
116
116
example 1 and 2.
117
117
118
+
### Example 4: If you want to return request id in response
119
+
120
+
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.
121
+
122
+
```python
123
+
from flask_log_request_id import current_request_id
0 commit comments