You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Decorator factory Feat: Create your own middleware (#17)
* feat(utils): add decorator factory
* improv: use partial to reduce complexity
* improv: add error handling
* chore: type hint
* docs: include pypi downloads badge
* feat: opt in to trace each middleware that runs
* improv: add initial util tests
* improv: test explicit and implicit trace_execution
* improv: test decorator with params
* chore: linting
* docs: include utilities
* improv: correct tests, dec_factory only for func
* improv: make util name more explicit
* improv: doc trace_execution, fix casting
* docs: add limitations, improve syntax
* docs: use new docs syntax
* fix: remove middleware decorator from libs
* feat: build docs in CI
* chore: linting
* fix: CI python-version type
* chore: remove docs CI
* chore: kick CI
* chore: include build badge master branch
* chore: refactor naming
* fix: rearrange tracing tests
* improv(tracer): toggle default auto patching
* feat(tracer): retrieve registered class instance
* fix(Makefile): make cov target more explicit
* improv(Register): support multiple classes reg.
* improv(Register): inject class methods correctly
* docs: add how to reutilize Tracer
* improv(tracer): test auto patch method
* improv: address nicolas feedback
* improv: update example to reflect middleware feat
* fix: metric dimension in root blob
* chore: version bump
Co-authored-by: heitorlessa <[email protected]>
A suite of utilities for AWS Lambda Functions that makes tracing with AWS X-Ray, structured logging and creating custom metrics asynchronously easier - Currently available for Python only and compatible with Python >=3.6.
6
6
@@ -32,12 +32,20 @@ A suite of utilities for AWS Lambda Functions that makes tracing with AWS X-Ray,
32
32
* Validate against common metric definitions mistakes (metric unit, values, max dimensions, max metrics, etc)
33
33
* No stack, custom resource, data collection needed — Metrics are created async by CloudWatch EMF
34
34
35
+
**Bring your own middleware**
36
+
37
+
* Utility to easily create your own middleware
38
+
* Run logic before, after, and handle exceptions
39
+
* Receive lambda handler, event, context
40
+
* Optionally create sub-segment for each custom middleware
41
+
35
42
**Environment variables** used across suite of utilities
This makes use of an existing Tracer instance that you may have initialized anywhere in your code, otherwise it'll initialize one using default options and provider (X-Ray).
292
+
293
+
```python
294
+
from aws_lambda_powertools.middleware_factory import lambda_handler_decorator
295
+
296
+
@lambda_handler_decorator(trace_execution=True)
297
+
defmiddleware_name(handler, event, context):
298
+
return handler(event, context)
299
+
300
+
@middleware_name
301
+
deflambda_handler(event, context):
302
+
returnTrue
303
+
```
304
+
305
+
Optionally, you can enrich the final trace with additional annotations and metadata by retrieving a copy of the Tracer used.
306
+
307
+
```python
308
+
from aws_lambda_powertools.middleware_factory import lambda_handler_decorator
309
+
from aws_lambda_powertools.tracing import Tracer
310
+
311
+
@lambda_handler_decorator(trace_execution=True)
312
+
defmiddleware_name(handler, event, context):
313
+
tracer = Tracer() # Takes a copy of an existing tracer instance
314
+
tracer.add_anotation...
315
+
tracer.metadata...
316
+
return handler(event, context)
317
+
318
+
@middleware_name
319
+
deflambda_handler(event, context):
320
+
returnTrue
321
+
```
322
+
207
323
## Beta
208
324
209
325
> **[Progress towards GA](https://github.com/awslabs/aws-lambda-powertools/projects/1)**
0 commit comments