Skip to content

Commit 28bba13

Browse files
committed
feat(load-balancer): add spans for feature flag evaluation
As the span was created before the feature flag evaluation, we are now creating a span for each task, so we can enhance it with information when needed. Signed-off-by: Simon Schrottner <simon.schrottner@dynatrace.com>
1 parent 06e6e46 commit 28bba13

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ the release.
1515
* [load-generator] Change OpenFeature Evaluation to Remote Evaluation Protocol,
1616
based on [this issue in OpenFeature/python-sdk-contrib](https://github.com/open-feature/python-sdk-contrib/issues/198)
1717
([#2114](https://github.com/open-telemetry/opentelemetry-demo/pull/2114))
18+
* [load-generator] Create well-named spans for each load task, to allow
19+
enrichment with information like flag evaluations.
20+
([#2119](https://github.com/open-telemetry/opentelemetry-demo/pull/2119))
1821

1922
## 2.0.1
2023

src/load-generator/locustfile.py

+12
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
from openfeature import api
3737
from openfeature.contrib.provider.ofrep import OFREPProvider
3838
from openfeature.contrib.hook.opentelemetry import TracingHook
39+
from opentelemetry.trace import Tracer
3940

4041
from playwright.async_api import Route, Request
4142

@@ -106,34 +107,42 @@ def get_flagd_value(FlagName):
106107

107108
class 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

Comments
 (0)