@@ -24,11 +24,16 @@ First you'll need to write a "grouping function" to inform ReadMe of the user or
24
24
``` python
25
25
def grouping_function (request ):
26
26
# You can lookup your user here, pull it off the request object, etc.
27
- return {
28
- " api_key" : " unique api_key of the user" ,
29
- " label" : " label for us to show for this user (ie email, project name, user name, etc)" ,
30
- " email" : " email address for user"
31
- }
27
+ # Your grouping function should return None if you don't want the request
28
+ # to be logged, and otherwise return a structure like the one below.
29
+ if user_is_authenticated:
30
+ return {
31
+ " api_key" : " unique api_key of the user" ,
32
+ " label" : " label for us to show for this user (ie email, project name, user name, etc)" ,
33
+ " email" : " email address for user"
34
+ }
35
+ else :
36
+ return None
32
37
```
33
38
34
39
Second, once you have written a grouping function, add a ` README_METRICS_CONFIG ` setting using the ` MetricsApiConfig ` helper object:
@@ -69,11 +74,16 @@ First you'll need to write a "grouping function" to inform ReadMe of the user or
69
74
``` python
70
75
def grouping_function (request ):
71
76
# You can lookup your user here, pull it off the request object, etc.
72
- return {
73
- " api_key" : " unique api_key of the user" ,
74
- " label" : " label for us to show for this user (ie email, project name, user name, etc)" ,
75
- " email" : " email address for user"
76
- }
77
+ # Your grouping function should return None if you don't want the request
78
+ # to be logged, and otherwise return a structure like the one below.
79
+ if user_is_authenticated:
80
+ return {
81
+ " api_key" : " unique api_key of the user" ,
82
+ " label" : " label for us to show for this user (ie email, project name, user name, etc)" ,
83
+ " email" : " email address for user"
84
+ }
85
+ else :
86
+ return None
77
87
```
78
88
79
89
Second, once you have written a grouping function, set up the extension wherever you create your Flask app.
@@ -113,11 +123,17 @@ First you'll need to write a "grouping function" to inform ReadMe of the user or
113
123
114
124
``` python
115
125
def grouping_function (request ):
116
- return {
117
- " api_key" : " unique api_key of the user" ,
118
- " label" : " label for us to show for this user (ie email, project name, user name, etc)" ,
119
- " email" : " email address for user"
120
- }
126
+ # You can lookup your user here, pull it off the request object, etc.
127
+ # Your grouping function should return None if you don't want the request
128
+ # to be logged, and otherwise return a structure like the one below.
129
+ if user_is_authenticated:
130
+ return {
131
+ " api_key" : " unique api_key of the user" ,
132
+ " label" : " label for us to show for this user (ie email, project name, user name, etc)" ,
133
+ " email" : " email address for user"
134
+ }
135
+ else :
136
+ return None
121
137
```
122
138
123
139
Then, wherever you initialize your WSGI app, you can wrap it with our middleware wrapper:
0 commit comments