Skip to content

Commit 7371273

Browse files
authored
Merge pull request #17 from FireTail-io/update-python-example
Update minimal python example
2 parents af124ff + 826458d commit 7371273

File tree

7 files changed

+47
-13161
lines changed

7 files changed

+47
-13161
lines changed

examples/minimal-python/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
node_modules
2+
src
23
.serverless
34
*.pyc
45
*.pyo

examples/minimal-python/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ This example demonstrates how to setup a simple HTTP GET endpoint. Once you fetc
2121
## Deploy
2222

2323
```bash
24+
pip3 install -t src/vendor -r aws_requirements.txt
25+
npm install
2426
serverless deploy
2527
```
2628

@@ -38,7 +40,7 @@ Serverless: Stack update finished...
3840
Service Information
3941
service: aws-python-simple-http-endpoint
4042
stage: dev
41-
region: us-east-1
43+
region: eu-west-1
4244
api keys:
4345
None
4446
endpoints:
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
aws-xray-sdk
2+
requests
3+
firetail-lambda

examples/minimal-python/handler.py

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,17 @@
1-
import base64, datetime, json, os, time
1+
import sys, base64, datetime, json, os, time
22

3-
def firetail_logger(func):
4-
def wrapper_func(*args, **kwargs):
5-
start_time = time.time()
3+
# Deps in src/vendor
4+
sys.path.insert(0, 'src/vendor')
5+
import requests
66

7-
# Unpack the args
8-
event, _ = args
7+
from firetail_lambda import firetail_handler, firetail_app
8+
app = firetail_app()
99

10-
# Get the response returned down the chain
11-
response = func(*args, **kwargs)
10+
from aws_xray_sdk.core import xray_recorder
11+
from aws_xray_sdk.core import patch_all
12+
patch_all()
1213

13-
# Create our log payload, and print it
14-
log_payload = base64.b64encode(json.dumps({"event": event,"response": response}).encode("utf-8")).decode("ascii")
15-
print("firetail:log-ext:%s" % log_payload)
16-
17-
# Ensure the execution time is >25ms to give the logs API time to propagate our print() to the extension.
18-
time.sleep(max(500/1000 - (time.time() - start_time), 0))
19-
20-
# Return the response from down the chain
21-
return response
22-
return wrapper_func
23-
24-
@firetail_logger
14+
@firetail_handler(app)
2515
def endpoint(event, context):
2616
return {
2717
"statusCode": 200,

0 commit comments

Comments
 (0)