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
You'll have to make sure that your service is authorized to fetch the appropriate secret from Vault.
25
+
26
+
Prerequisite configuration:
27
+
-------
28
+
Setup :code:`reddit-experiments` in your application's configuration file:
22
29
23
30
.. code-block:: ini
24
31
@@ -41,24 +48,102 @@ configure it in your application's configuration file:
41
48
42
49
...
43
50
44
-
and then use the attached :py:class:`~reddit_decider.Decider` object in
45
-
request::
46
51
47
-
def my_method(request):
48
-
if request.decider.get_variant("foo") == "bar":
49
-
pass
52
+
Integrate :code:`reddit-experiments` into Baseplate service
53
+
-------
54
+
In your service's initialization process, add a :code:`decider` instance to baseplate's context:
55
+
(Note the use of the :code:`ExperimentLogger`, which is used to publish exposure V2 events,
56
+
an example can be seen `here <https://github.snooguts.net/reddit/reddit-service-graphql/blob/3734b51732c29d07eef32aced86677cce5064dbb/graphql-py/graphql_api/events/utils.py#L205>`_)
50
57
51
-
Configuration
52
-
-------------
58
+
.. code-block:: python
53
59
54
-
.. autoclass:: DeciderClient
60
+
# application code
61
+
from reddit_decider import decider_client_from_config
Make sure :code:`edge_context`is accessible on :code:`request`object like so:
86
+
87
+
.. code-block:: python
88
+
89
+
request.edge_context
90
+
91
+
92
+
[Optional] Define request field extractor function (`example <https://github.snooguts.net/reddit/reddit-service-graphql/blob/master/graphql-py/graphql_api/models/experiment.py#L67-L92>`_)
93
+
94
+
.. code-block:: python
57
95
58
-
Classes
96
+
# Baseplate calls `make_object_for_context()` and creates a `DeciderContext`
97
+
# which fetches the following fields from EdgeContext automatically:
98
+
# - user_id
99
+
# - device_id
100
+
# - logged_in
101
+
# - cookie_created_timestamp
102
+
# - oauth_client_id
103
+
# - country_code
104
+
# - locale
105
+
# - origin_service
106
+
# - is_employee
107
+
# - loid_created_ms
108
+
109
+
# Customized fields can be defined below to be extracted from a baseplate request
110
+
# and will override above edge_context fields.
111
+
112
+
def my_field_extractor(request):
113
+
# an example of customized baseplate request field extractor:
0 commit comments