コード例 #1
0
ファイル: app.py プロジェクト: haandol/aws-xray-tutorial
    def on_post(self, req, resp):
        params = self.get_params(req)
        title = params.get('title', '')
        content = params.get('content', '')
        if not (title and content):
            raise falcon.HTTPBadRequest(
                'title and content should not be empty')

        username = params.get('username', '')
        if not username:
            raise falcon.HTTPBadRequest('username should not be empty')

        req.context.segment.put_annotation('username', username)

        conn = self.get_conn()
        with xray_recorder.in_subsegment('create post') as subsegment:
            with conn.cursor() as cursor:
                sql = f"INSERT INTO posts (title, content, username) VALUES ('{title}', '{content}', '{username}')"
                cursor.execute(sql)
                conn.commit()
            subsegment.put_metadata('sql', sql)
        PG_POOL.putconn(conn)

        resp.status = falcon.HTTP_OK
        resp.body = 'ok'
コード例 #2
0
def handler(evt, _):
    print(json.loads(evt['body']))
    with xray_recorder.in_subsegment('Process') as _:
        boto3.client('sqs').send_message(
            QueueUrl=QUEUE_URL,
            MessageBody=evt['body'],
        )
    return {
        'statusCode': 200,
        'body': 'OK',
    }
コード例 #3
0
def lambda_handler(event, context):
    raw_data = S3.get_object(Bucket=BUCKET_NAME, Key="sample_data.json")
    data = json.loads(raw_data["Body"].read())
    with xray_recorder.in_subsegment("Throwing exception") as subsegment:
        subsegment.put_metadata("very_important_inforamtion",
                                {"message": "Hello I am metadata"},
                                "information")
        subsegment.put_annotation("very_important_annotation",
                                  "Very very important information")
        raise Exception("Information")
    return {"statusCode": 200, "body": data["message"]}
コード例 #4
0
ファイル: app.py プロジェクト: haandol/aws-xray-tutorial
    def on_delete(self, req, resp):
        conn = self.get_conn()
        with xray_recorder.in_subsegment('drop table') as subsegment:
            with conn.cursor() as cursor:
                sql = """DROP TABLE posts"""
                cursor.execute(sql)
                conn.commit()
            subsegment.put_metadata('sql', sql)
        PG_POOL.putconn(conn)

        resp.status = falcon.HTTP_OK
        resp.body = 'ok'
コード例 #5
0
ファイル: app.py プロジェクト: haandol/aws-xray-tutorial
    def on_delete(self, req, resp, pid):
        conn = self.get_conn()
        req.context.segment.put_annotation('post_id', pid)
        with xray_recorder.in_subsegment('delete post') as subsegment:
            with conn.cursor() as cursor:
                sql = f'DELETE FROM posts WHERE id={pid}'
                cursor.execute(sql)
                conn.commit()
            subsegment.put_metadata('sql', sql)
        PG_POOL.putconn(conn)

        resp.status = falcon.HTTP_OK
        resp.body = 'ok'
コード例 #6
0
ファイル: app.py プロジェクト: haandol/aws-xray-tutorial
    def on_get(self, req, resp, pid):
        conn = self.get_conn()
        req.context.segment.put_annotation('post_id', pid)
        with xray_recorder.in_subsegment('get post') as subsegment:
            with conn.cursor() as cursor:
                sql = f'SELECT * FROM posts WHERE id={pid}'
                cursor.execute(sql)
                posts = cursor.fetchall()
            subsegment.put_metadata('sql', sql)
        PG_POOL.putconn(conn)

        resp.status = falcon.HTTP_OK
        resp.body = json.dumps(posts)
コード例 #7
0
ファイル: app.py プロジェクト: haandol/aws-xray-tutorial
    def on_post(self, req, resp):
        conn = self.get_conn()
        with xray_recorder.in_subsegment('create table') as subsegment:
            with conn.cursor() as cursor:
                sql = """CREATE TABLE posts ( \
                    id serial PRIMARY KEY, \
                    username VARCHAR(256), \
                    title VARCHAR(256), \
                    content TEXT
                );"""
                cursor.execute(sql)
                conn.commit()
            subsegment.put_metadata('sql', sql)
        PG_POOL.putconn(conn)

        resp.status = falcon.HTTP_OK
        resp.body = 'ok'