36
36
from openfeature import api
37
37
from openfeature .contrib .provider .ofrep import OFREPProvider
38
38
from openfeature .contrib .hook .opentelemetry import TracingHook
39
+ from opentelemetry .trace import Tracer
39
40
40
41
from playwright .async_api import Route , Request
41
42
@@ -106,34 +107,42 @@ def get_flagd_value(FlagName):
106
107
107
108
class WebsiteUser (HttpUser ):
108
109
wait_time = between (1 , 10 )
110
+ # Creates a tracer from the global tracer provider
111
+ tracer = trace .get_tracer ("load-generator" )
109
112
110
113
@task (1 )
114
+ @tracer .start_as_current_span ("view home" )
111
115
def index (self ):
112
116
self .client .get ("/" )
113
117
114
118
@task (10 )
119
+ @tracer .start_as_current_span ("browse product" )
115
120
def browse_product (self ):
116
121
self .client .get ("/api/products/" + random .choice (products ))
117
122
118
123
@task (3 )
124
+ @tracer .start_as_current_span ("get recommendations" )
119
125
def get_recommendations (self ):
120
126
params = {
121
127
"productIds" : [random .choice (products )],
122
128
}
123
129
self .client .get ("/api/recommendations" , params = params )
124
130
125
131
@task (3 )
132
+ @tracer .start_as_current_span ("get ads" )
126
133
def get_ads (self ):
127
134
params = {
128
135
"contextKeys" : [random .choice (categories )],
129
136
}
130
137
self .client .get ("/api/data/" , params = params )
131
138
132
139
@task (3 )
140
+ @tracer .start_as_current_span ("view cart" )
133
141
def view_cart (self ):
134
142
self .client .get ("/api/cart" )
135
143
136
144
@task (2 )
145
+ @tracer .start_as_current_span ("add to cart" )
137
146
def add_to_cart (self , user = "" ):
138
147
if user == "" :
139
148
user = str (uuid .uuid1 ())
@@ -149,6 +158,7 @@ def add_to_cart(self, user=""):
149
158
self .client .post ("/api/cart" , json = cart_item )
150
159
151
160
@task (1 )
161
+ @tracer .start_as_current_span ("checkout with items" )
152
162
def checkout (self ):
153
163
# checkout call with an item added to cart
154
164
user = str (uuid .uuid1 ())
@@ -158,6 +168,7 @@ def checkout(self):
158
168
self .client .post ("/api/checkout" , json = checkout_person )
159
169
160
170
@task (1 )
171
+ @tracer .start_as_current_span ("checkout with multiple items" )
161
172
def checkout_multi (self ):
162
173
# checkout call which adds 2-4 different items to cart before checkout
163
174
user = str (uuid .uuid1 ())
@@ -168,6 +179,7 @@ def checkout_multi(self):
168
179
self .client .post ("/api/checkout" , json = checkout_person )
169
180
170
181
@task (5 )
182
+ @tracer .start_as_current_span ("flood home" )
171
183
def flood_home (self ):
172
184
for _ in range (0 , get_flagd_value ("loadGeneratorFloodHomepage" )):
173
185
self .client .get ("/" )
0 commit comments