3636from openfeature import api
3737from openfeature .contrib .provider .ofrep import OFREPProvider
3838from openfeature .contrib .hook .opentelemetry import TracingHook
39+ from opentelemetry .trace import Tracer
3940
4041from playwright .async_api import Route , Request
4142
@@ -106,34 +107,42 @@ def get_flagd_value(FlagName):
106107
107108class WebsiteUser (HttpUser ):
108109 wait_time = between (1 , 10 )
110+ # Creates a tracer from the global tracer provider
111+ tracer = trace .get_tracer ("load-generator" )
109112
110113 @task (1 )
114+ @tracer .start_as_current_span ("view home" )
111115 def index (self ):
112116 self .client .get ("/" )
113117
114118 @task (10 )
119+ @tracer .start_as_current_span ("browse product" )
115120 def browse_product (self ):
116121 self .client .get ("/api/products/" + random .choice (products ))
117122
118123 @task (3 )
124+ @tracer .start_as_current_span ("get recommendations" )
119125 def get_recommendations (self ):
120126 params = {
121127 "productIds" : [random .choice (products )],
122128 }
123129 self .client .get ("/api/recommendations" , params = params )
124130
125131 @task (3 )
132+ @tracer .start_as_current_span ("get ads" )
126133 def get_ads (self ):
127134 params = {
128135 "contextKeys" : [random .choice (categories )],
129136 }
130137 self .client .get ("/api/data/" , params = params )
131138
132139 @task (3 )
140+ @tracer .start_as_current_span ("view cart" )
133141 def view_cart (self ):
134142 self .client .get ("/api/cart" )
135143
136144 @task (2 )
145+ @tracer .start_as_current_span ("add to cart" )
137146 def add_to_cart (self , user = "" ):
138147 if user == "" :
139148 user = str (uuid .uuid1 ())
@@ -149,6 +158,7 @@ def add_to_cart(self, user=""):
149158 self .client .post ("/api/cart" , json = cart_item )
150159
151160 @task (1 )
161+ @tracer .start_as_current_span ("checkout with items" )
152162 def checkout (self ):
153163 # checkout call with an item added to cart
154164 user = str (uuid .uuid1 ())
@@ -158,6 +168,7 @@ def checkout(self):
158168 self .client .post ("/api/checkout" , json = checkout_person )
159169
160170 @task (1 )
171+ @tracer .start_as_current_span ("checkout with multiple items" )
161172 def checkout_multi (self ):
162173 # checkout call which adds 2-4 different items to cart before checkout
163174 user = str (uuid .uuid1 ())
@@ -168,6 +179,7 @@ def checkout_multi(self):
168179 self .client .post ("/api/checkout" , json = checkout_person )
169180
170181 @task (5 )
182+ @tracer .start_as_current_span ("flood home" )
171183 def flood_home (self ):
172184 for _ in range (0 , get_flagd_value ("loadGeneratorFloodHomepage" )):
173185 self .client .get ("/" )
0 commit comments