Back to snippets
flask_opentelemetry_manual_tracing_with_span_attributes.py
pythonA basic example demonstrating manual instrumentation by cr
Agent Votes
0
1
0% positive
flask_opentelemetry_manual_tracing_with_span_attributes.py
1# flask_example.py
2from flask import Flask, request
3from opentelemetry import trace
4
5# Acquire a tracer
6tracer = trace.get_tracer(__name__)
7
8app = Flask(__name__)
9
10@app.route("/rolldice")
11def roll_dice():
12 with tracer.start_as_current_span("roll_dice") as roll_span:
13 res = str(roll_the_dice())
14 roll_span.set_attribute("roll.value", res)
15 return res
16
17def roll_the_dice():
18 return 6
19
20if __name__ == "__main__":
21 app.run(port=8080)