-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp_auto.py
More file actions
55 lines (49 loc) · 1.32 KB
/
app_auto.py
File metadata and controls
55 lines (49 loc) · 1.32 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import os
import time
from flask import Flask, jsonify
app = Flask(__name__)
@app.route('/')
def hello_world():
"""Simple hello world endpoint."""
return jsonify({
'message': 'Hello, World! (Auto-Instrumentation Demo)',
'status': 'success'
})
@app.route('/health')
def health():
"""Health check endpoint."""
return jsonify({
'status': 'healthy',
'service': 'otel-python-auto-example'
})
@app.route('/api/users')
def get_users():
"""
Simulated endpoint returning users.
Zero code instrumentation will capture this HTTP request automatically.
"""
# Simulate DB delay
time.sleep(0.15)
return jsonify({
'users': [
{'id': 1, 'name': 'Alice'},
{'id': 2, 'name': 'Bob'},
{'id': 3, 'name': 'Charlie'}
],
'total': 3
})
@app.route('/api/computation')
def heavy_computation():
"""
Simulated heavy computation endpoint.
Zero code instrumentation will capture the duration automatically.
"""
# Simulate heavy workload delay
time.sleep(0.8)
return jsonify({
'status': 'success',
'result': 42
})
if __name__ == '__main__':
debug_mode = os.getenv('FLASK_DEBUG', 'false').lower() in ('true', '1', 'yes')
app.run(host='0.0.0.0', port=5000, debug=debug_mode)