-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
30 lines (23 loc) · 853 Bytes
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from random import randint
from flask import Flask
from opentelemetry import trace
from opentelemetry.trace.status import Status, StatusCode
# Acquire a tracer
tracer = trace.get_tracer("diceroller.tracer")
app = Flask(__name__)
@app.route("/rolldice")
def roll_dice():
with tracer.start_as_current_span("roll_dice") as span:
roll_result = roll()
if roll_result == 6:
span.set_status(Status(StatusCode.ERROR, "Rolled a 6"))
return "Not Found", 404
else:
span.set_status(Status(StatusCode.OK, "Successful roll"))
return str(roll_result)
def roll():
# This creates a new span that's the child of the current one
with tracer.start_as_current_span("roll") as rollspan:
res = randint(1, 6)
rollspan.set_attribute("roll.value", res)
return res