forked from grafana/opentelemetry-workshop-2023
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
29 lines (24 loc) · 913 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
#### OpenTelemetry traces configuration ######################################
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor, ConsoleSpanExporter
from opentelemetry.trace import set_tracer_provider
tracer_provider = TracerProvider()
tracer_provider.add_span_processor(BatchSpanProcessor(ConsoleSpanExporter()))
set_tracer_provider(tracer_provider)
# Configure app
import flask
app = flask.Flask(__name__)
# Flask auto-instrumentation
from opentelemetry.instrumentation.flask import FlaskInstrumentor
FlaskInstrumentor().instrument_app(app)
# Handle requests to http://localhost:4321/
@app.route('/')
def home():
return 'ok'
# Handle requests to http://localhost:4321/error
@app.route('/error')
def error():
return eval('0/0')
# Run the app when executing this file
if __name__ == '__main__':
app.run(host='0.0.0.0', port=4321)