Skip to content

Commit d8cfe51

Browse files
tintiheitorlessa
andauthored
fix(docs): remove redundant code (#2796)
Co-authored-by: Heitor Lessa <lessa@amazon.co.uk>
1 parent 9dc00b9 commit d8cfe51

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

docs/tutorial/index.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ Within AWS X-Ray, we can answer these questions by using two features: tracing *
649649

650650
Let's put them into action.
651651

652-
```python title="Enriching traces with annotations and metadata" hl_lines="10 17-18 26-27 35 37-42 45"
652+
```python title="Enriching traces with annotations and metadata" hl_lines="10 17-18 26-27 35 37-41 44"
653653
from aws_xray_sdk.core import patch_all, xray_recorder
654654

655655
from aws_lambda_powertools import Logger
@@ -687,11 +687,10 @@ def lambda_handler(event, context):
687687
global cold_start
688688

689689
subsegment = xray_recorder.current_subsegment()
690+
subsegment.put_annotation(key="ColdStart", value=cold_start)
691+
690692
if cold_start:
691-
subsegment.put_annotation(key="ColdStart", value=cold_start)
692693
cold_start = False
693-
else:
694-
subsegment.put_annotation(key="ColdStart", value=cold_start)
695694

696695
result = app.resolve(event, context)
697696
subsegment.put_metadata("response", result)
@@ -705,8 +704,8 @@ Let's break it down:
705704
* **L17-18**: We use AWS X-Ray SDK to add `User` annotation on `hello_name` subsegment. This will allow us to filter traces using the `User` value.
706705
* **L26-27**: We repeat what we did in L17-18 except we use the value `unknown` since we don't have that information.
707706
* **L35**: We use `global` to modify our global variable defined in the outer scope.
708-
* **37-42**: We add `ColdStart` annotation and flip the value of `cold_start` variable, so that subsequent requests annotates the value `false` when the sandbox is reused.
709-
* **L45**: We include the final response under `response` key as part of the `handler` subsegment.
707+
* **37-41**: We add `ColdStart` annotation and set `cold_start` variable to `false`, so that subsequent requests annotates the value `false` when the sandbox is reused.
708+
* **L44**: We include the final response under `response` key as part of the `handler` subsegment.
710709

711710
???+ info
712711
If you want to understand how the Lambda execution environment (sandbox) works and why cold starts can occur, see this [blog series on Lambda performance](https://aws.amazon.com/blogs/compute/operating-lambda-performance-optimization-part-1/){target="_blank"}.

0 commit comments

Comments
 (0)