From b3cba3d441250a67616cb41f0853f5ac7ffe3c52 Mon Sep 17 00:00:00 2001 From: KhanhNQ79 Date: Sun, 11 Aug 2024 01:12:22 +0700 Subject: [PATCH] add tracer and logger --- azure-vote/main.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/azure-vote/main.py b/azure-vote/main.py index 8e36d7377c..5b3e7dd435 100644 --- a/azure-vote/main.py +++ b/azure-vote/main.py @@ -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) @@ -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)