-
Notifications
You must be signed in to change notification settings - Fork 0
/
application.py
63 lines (43 loc) · 1.61 KB
/
application.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
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
56
57
58
59
60
61
62
63
import boto3
from flask import Flask
from aws_xray_sdk.core import xray_recorder, patch_all
from aws_xray_sdk.ext.flask.middleware import XRayMiddleware
from aws_xray_sdk.ext.flask_sqlalchemy.query import XRayFlaskSqlAlchemy
import requests
application = app = Flask(__name__)
application.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
application.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///db.sqlite3"
xray_recorder.configure(service='My Flask Web Application')
XRayMiddleware(app, xray_recorder)
patch_all()
db = XRayFlaskSqlAlchemy(app=application)
class User(db.Model):
__tablename__ = 'users'
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(255), nullable=False, unique=True)
@app.route('/outgoing-http-call')
def callHTTP():
requests.get("https://aws.amazon.com")
return "Ok! tracing outgoing http call"
@app.route('/aws-sdk-call')
def callAWSSDK():
client = boto3.client('s3')
client.list_buckets()
return 'Ok! tracing aws sdk call'
@app.route('/flask-sql-alchemy-call')
def callSQL():
name = 'sql-alchemy-model'
user = User(name=name)
db.create_all()
db.session.add(user)
return 'Ok! tracing sql call'
# use the exact value (integration testing module will be using this values)
@app.route('/annotation-metadata')
def callCustomSegment():
subsegment = xray_recorder.begin_subsegment('subsegment_name')
subsegment.put_annotation('one', '1')
subsegment.put_metadata('integration-test', 'true')
xray_recorder.end_subsegment()
return 'Ok! annotation-metadata testing'
if __name__ == "__main__":
app.run(debug=True)