Skip to content

Commit

Permalink
add tracer and logger
Browse files Browse the repository at this point in the history
  • Loading branch information
KhanhNQ79 authored and KhanhNQ79 committed Aug 10, 2024
1 parent 224df52 commit b3cba3d
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions azure-vote/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,15 @@ def index():

# Get current values
vote1 = r.get(button1).decode('utf-8')
# TODO: use tracer object to trace cat vote
vote2 = r.get(button2).decode('utf-8')
# TODO: use tracer object to trace dog vote
with tracer.span(name='Cat vote') as span:
vote1 = r.get(button1).decode('utf-8')
properties = {'custom_dimensions': {'Cats Vote': vote1}}
span.add_attribute('custom_dimensions', properties)
vote2 = r.get(button2).decode('utf-8')
with tracer.span(name='Dog vote') as span:
vote2 = r.get(button2).decode('utf-8')
properties = {'custom_dimensions': {'Dogs Vote': vote2}}
span.add_attribute('custom_dimensions', properties)

# Return index with values
return render_template("index.html", value1=int(vote1), value2=int(vote2), button1=button1, button2=button2, title=title)
Expand All @@ -111,11 +117,11 @@ def index():
r.set(button2,0)
vote1 = r.get(button1).decode('utf-8')
properties = {'custom_dimensions': {'Cats Vote': vote1}}
# TODO: use logger object to log cat vote
logger.info('Cat vote recorded', extra=properties)

vote2 = r.get(button2).decode('utf-8')
properties = {'custom_dimensions': {'Dogs Vote': vote2}}
# TODO: use logger object to log dog vote
logger.info('Dog vote recored', extra=properties)

return render_template("index.html", value1=int(vote1), value2=int(vote2), button1=button1, button2=button2, title=title)

Expand Down

0 comments on commit b3cba3d

Please sign in to comment.