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
Copy file name to clipboardExpand all lines: docs/quickstart.md
+53-42Lines changed: 53 additions & 42 deletions
Original file line number
Diff line number
Diff line change
@@ -718,69 +718,80 @@ Repeat the process of building, deploying, and invoking your application via the
718
718
719
719
If you choose any of the traces available, try opening the `handler` subsegment and you should see the response of your Lambda function under the `Metadata` tab.
720
720
721
-

721
+

722
722
723
723
### Simplifying with Tracer
724
724
725
-
Now, let's try to simplify it with Lambda Powertools:
725
+
Cross-cutting concerns like filtering traces by Cold Start, including response as well as exceptions as tracing metadata can take a considerable amount of boilerplate.
726
726
727
-
=== "app.py"
727
+
We can simplify our previous patterns by using [Lambda Powertools Tracer](core/tracer.md){target="_blank"}; a thin wrapper on top of X-Ray SDK.
728
728
729
-
```python hl_lines="3 13 15 21 23 29"
730
-
import json
729
+
!!! note
730
+
You can now safely remove `aws-xray-sdk` from `requirements.txt`; keep `aws-lambda-powertools` only.
731
731
732
-
from aws_lambda_powertools import Logger, Tracer
733
-
from aws_lambda_powertools.event_handler.api_gateway import ApiGatewayResolver
734
-
from aws_lambda_powertools.logging import correlation_paths
Decorators, annotations and metadata are largely the same, except we now have a much cleaner code as the boilerplate is gone. Here's what's changed compared to AWS X-Ray SDK approach:
767
+
768
+
***L8**: We initialize `Tracer` and define the name of our service (`APP`). We automatically run `patch_all` from AWS X-Ray SDK on your behalf. Any previously patched or non-imported library is simply ignored
769
+
***L13**: We use `@tracer.capture_method` decorator instead of `xray_recorder.capture`. We automatically **1/** create a subsegment named after the function name (`## hello_name`), and **2/** add the response/exception as tracing metadata
770
+
***L15**: Putting annotations remain exactly the same UX
771
+
***L29**: We use `@tracer.lambda_handler` so we automatically add `ColdStart` annotation within Tracer itself. We also add a new `Service` annotation using the value of `Tracer(service="APP")`, so that you can filter traces by the service your function(s) represent.
772
+
773
+
Another subtle difference is that you can now run your Lambda functions and unit test them locally without having to explicitly disable Tracer.
774
+
775
+
Lambda Powertools optimizes for Lambda compute environment. As such, we add these and other common approaches to accelerate your development, so you don't worry about implementing every cross-cutting concern.
764
776
765
-
To make our methods visible in the traces, we add `@tracer.capture_method` decorator to the processing methods.
766
-
We add annotations directly in the code without adding it with the context handler using the `tracer.put_annotation` method.
767
-
Since we add the `@tracer.capture_lambda_handler` decorator for our `lambda_handler`, powertools automatically adds cold start information as an annotation.
768
-
It also automatically append Lambda response as a metadata into trace, so we don't need to worry about it.
769
777
!!! tip
770
-
For differences between annotations and metadata in traces, please follow [link](https://awslabs.github.io/aws-lambda-powertools-python/latest/core/tracer/#annotations-metadata).
778
+
You can [opt-out some of these behaviours](./core/tracer/#advanced){target="_blank"} like disabling response capturing, explicitly patching only X modules, etc.
771
779
772
-
Therefore, you should see traces of your Lambda in the X-ray console.
Repeat the process of building, deploying, and invoking your application via the API endpoint. Within the [AWS X-Ray Console](https://console.aws.amazon.com/xray/home#/traces/){target="_blank"}, you should see a similar view:
775
781
776
-
You may consider using **CloudWatch ServiceLens** which links the CloudWatch metrics and logs, in addition to traces from the AWS X-Ray.
777
782
778
-
It gives you a complete view of your apps and their dependencies, making your services more observable.
779
-
From here, you can browse to specific logs in CloudWatch Logs Insight, Metrics Dashboard or Traces in CloudWatch X-Ray traces.
780
-
=== "Example CloudWatch ServiceLens View"
783
+

784
+
785
+
!!! tip
786
+
Consider using **Amazon CloudWatch ServiceLens** view as it aggregates AWS X-Ray traces and CloudWatch metrics and logs in one view.
787
+
788
+
From here, you can browse to specific logs in CloudWatch Logs Insight, Metrics Dashboard or AWS X-Ray traces.
For more information on CloudWatch ServiceLens, please visit [link](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/ServiceLens.html).
793
+
For more information on Amazon CloudWatch ServiceLens, please visit [link](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/ServiceLens.html).
794
+
784
795
## Custom Metrics
785
796
The final step to provide complete observability is to add business metrics (such as number of sales or reservations).
786
797
Lambda adds technical metrics (such as Invocations, Duration, Error Count & Success Rate) to the CloudWatch metrics out of the box.
0 commit comments