Skip to content

Commit 43b9ba8

Browse files
committed
Merge branch 'develop'
* develop: feat(pypi): add bumpversion, public release pypi chore: public beta version
2 parents 4745929 + 8a64abf commit 43b9ba8

File tree

10 files changed

+265
-125
lines changed

10 files changed

+265
-125
lines changed

README.md

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,46 @@ A suite of utilities for AWS Lambda Functions that makes tracing with AWS X-Ray,
1010

1111
**Tracing**
1212

13+
> It currently uses AWS X-Ray
14+
1315
* Decorators that capture cold start as annotation, and response and exceptions as metadata
1416
* Run functions locally without code change to disable tracing
15-
* Explicitly disable tracing via env var POWERTOOLS_TRACE_DISABLED="true"
17+
* Explicitly disable tracing via env var `POWERTOOLS_TRACE_DISABLED="true"`
1618

1719
**Logging**
1820

1921
* Decorators that capture key fields from Lambda context, cold start and structures logging output as JSON
2022
* Optionally log Lambda request when instructed (disabled by default)
21-
- Enable via POWERTOOLS_LOGGER_LOG_EVENT="true" or explicitly via decorator param
23+
- Enable via `POWERTOOLS_LOGGER_LOG_EVENT="true"` or explicitly via decorator param
2224
* Logs canonical custom metric line to logs that can be consumed asynchronously
2325

26+
**Environment variables** used across suite of utilities
27+
28+
Environment variable | Description | Default | Utility
29+
------------------------------------------------- | --------------------------------------------------------------------------------- | --------------------------------------------------------------------------------- | -------------------------------------------------
30+
POWERTOOLS_SERVICE_NAME | Sets service name used for tracing namespace, metrics dimensions and structured logging | "service_undefined" | all
31+
POWERTOOLS_TRACE_DISABLED | Disables tracing | "false" | tracing
32+
POWERTOOLS_LOGGER_LOG_EVENT | Logs incoming event | "false" | logging
33+
LOG_LEVEL | Sets logging level | "INFO" | logging
34+
2435
## Usage
2536

37+
### Installation
38+
39+
With [pip](https://pip.pypa.io/en/latest/index.html) installed, run: ``pip install aws-lambda-powertools``
40+
2641
### Tracing
2742

2843
**Example SAM template using supported environment variables**
2944

3045
```yaml
3146
Globals:
3247
Function:
48+
Tracing: Active # can also be enabled per function
3349
Environment:
3450
Variables:
35-
POWERTOOLS_SERVICE_NAME: "payment" # service_undefined by default
36-
POWERTOOLS_TRACE_DISABLED: "false" # false by default
51+
POWERTOOLS_SERVICE_NAME: "payment"
52+
POWERTOOLS_TRACE_DISABLED: "false"
3753
```
3854
3955
**Pseudo Python Lambda code**
@@ -68,9 +84,8 @@ Globals:
6884
Function:
6985
Environment:
7086
Variables:
71-
POWERTOOLS_SERVICE_NAME: "payment" # service_undefined by default
72-
POWERTOOLS_LOGGER_LOG_EVENT: "true" # false by default
73-
LOG_LEVEL: "INFO" # INFO by default
87+
POWERTOOLS_SERVICE_NAME: "payment"
88+
LOG_LEVEL: "INFO"
7489
```
7590
7691
**Pseudo Python Lambda code**
@@ -86,6 +101,7 @@ logger = logger_setup()
86101
def handler(event, context)
87102
logger.info("Collecting payment")
88103
...
104+
# You can log entire objects too
89105
logger.info({
90106
"operation": "collect_payment",
91107
"charge_id": event['charge_id']
@@ -142,19 +158,39 @@ def handler(event, context)
142158
log_metric(name="SuccessfulPayment", unit=MetricUnit.Count, value=10, namespace="MyApplication", customer_id="123-abc", charge_id="abc-123")
143159

144160
# Explicit service name
145-
log_metric(service="payment", name="SuccessfulPayment", namespace="MyApplication".....)
161+
log_metric(service="paymentTest", name="SuccessfulPayment", namespace="MyApplication".....)
146162
...
147163
```
148164

165+
**Exerpt output in CloudWatch Logs**
166+
167+
```
168+
MONITORING|10|Count|SuccessfulPayment|MyApplication|service="payment
169+
MONITORING|10|Count|SuccessfulPayment|MyApplication|customer_id="123-abc",charge_id="abc-123",service="payment
170+
MONITORING|10|Count|SuccessfulPayment|MyApplication|service="paymentTest
171+
```
172+
173+
174+
## Beta
175+
176+
This library may change its API/methods or environment variables as it receives feedback from customers. Currently looking for ideas in the following areas before making it stable:
177+
178+
* **Should Tracer patch all possible imported libraries by default or only AWS SDKs?**
179+
- Patching all libraries may have a small performance penalty (~50ms) at cold start
180+
- Alternatively, we could patch only AWS SDK if available and to provide a param to patch multiple `Tracer(modules=("boto3", "requests"))`
181+
* **Create a Tracer provider to support additional tracing**
182+
- Either duck typing or ABC to allow additional tracing providers
183+
149184
## TODO
150185

151186
* [ ] Enable CI
152-
* [ ] Publish PyPi package
187+
* [ ] Add an example code using powertools
188+
* [ ] Automate release and version bumping in CI
153189

154190
## Credits
155191

156-
* We use a microlib for structured logging [aws-lambda-logging](https://gitlab.com/hadrien/aws_lambda_logging)
157-
* Idea of a powertools to provide a handful utilities for AWS Lambda functiones comes from [DAZN Powertools](https://github.com/getndazn/dazn-lambda-powertools/)
192+
* Structured logging initial implementation from [aws-lambda-logging](https://gitlab.com/hadrien/aws_lambda_logging)
193+
* Powertools idea [DAZN Powertools](https://github.com/getndazn/dazn-lambda-powertools/)
158194

159195
## License
160196

python/Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,11 @@ test-html:
2121
pipenv run pytest --cov-report html
2222

2323
pr: lint test
24+
25+
release: pr
26+
python setup.py sdist bdist_wheel
27+
twine upload dist/* --verbose
28+
29+
release-test: pr
30+
python setup.py sdist bdist_wheel
31+
twine upload --repository testpypi dist/* --verbose

python/Pipfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ flake8-isort = "*"
1717
flake8-variables-names = "*"
1818
isort = "*"
1919
pre-commit = "*"
20-
pytest = "==5.0.1"
20+
pytest = "~=5.0"
2121
pytest-cov = "*"
2222
pytest-mock = "*"
23+
bumpversion = "*"
2324

2425
[packages]
2526
lambda-powertools = {editable = true,path = "."}

0 commit comments

Comments
 (0)