Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(load-generator): add spans for feature flag evaluation #2119

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ the release.
* [load-generator] Change OpenFeature Evaluation to Remote Evaluation Protocol,
based on [this issue in OpenFeature/python-sdk-contrib](https://github.com/open-feature/python-sdk-contrib/issues/198)
([#2114](https://github.com/open-telemetry/opentelemetry-demo/pull/2114))
* [load-generator] Create well-named spans for each load task, to allow
enrichment with information like flag evaluations.
([#2119](https://github.com/open-telemetry/opentelemetry-demo/pull/2119))

## 2.0.1

Expand Down
12 changes: 12 additions & 0 deletions src/load-generator/locustfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
from openfeature import api
from openfeature.contrib.provider.ofrep import OFREPProvider
from openfeature.contrib.hook.opentelemetry import TracingHook
from opentelemetry.trace import Tracer

from playwright.async_api import Route, Request

Expand Down Expand Up @@ -106,34 +107,42 @@ def get_flagd_value(FlagName):

class WebsiteUser(HttpUser):
wait_time = between(1, 10)
# Creates a tracer from the global tracer provider
tracer = trace.get_tracer("load-generator")

@task(1)
@tracer.start_as_current_span("view home")
def index(self):
self.client.get("/")

@task(10)
@tracer.start_as_current_span("browse product")
def browse_product(self):
self.client.get("/api/products/" + random.choice(products))

@task(3)
@tracer.start_as_current_span("get recommendations")
def get_recommendations(self):
params = {
"productIds": [random.choice(products)],
}
self.client.get("/api/recommendations", params=params)

@task(3)
@tracer.start_as_current_span("get ads")
def get_ads(self):
params = {
"contextKeys": [random.choice(categories)],
}
self.client.get("/api/data/", params=params)

@task(3)
@tracer.start_as_current_span("view cart")
def view_cart(self):
self.client.get("/api/cart")

@task(2)
@tracer.start_as_current_span("add to cart")
def add_to_cart(self, user=""):
if user == "":
user = str(uuid.uuid1())
Expand All @@ -149,6 +158,7 @@ def add_to_cart(self, user=""):
self.client.post("/api/cart", json=cart_item)

@task(1)
@tracer.start_as_current_span("checkout with items")
def checkout(self):
# checkout call with an item added to cart
user = str(uuid.uuid1())
Expand All @@ -158,6 +168,7 @@ def checkout(self):
self.client.post("/api/checkout", json=checkout_person)

@task(1)
@tracer.start_as_current_span("checkout with multiple items")
def checkout_multi(self):
# checkout call which adds 2-4 different items to cart before checkout
user = str(uuid.uuid1())
Expand All @@ -168,6 +179,7 @@ def checkout_multi(self):
self.client.post("/api/checkout", json=checkout_person)

@task(5)
@tracer.start_as_current_span("flood home")
def flood_home(self):
for _ in range(0, get_flagd_value("loadGeneratorFloodHomepage")):
self.client.get("/")
Expand Down