Skip to content

fix(docs): remove redundant code in the tutorial section #2796

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions docs/tutorial/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ Within AWS X-Ray, we can answer these questions by using two features: tracing *

Let's put them into action.

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

from aws_lambda_powertools import Logger
Expand Down Expand Up @@ -687,11 +687,10 @@ def lambda_handler(event, context):
global cold_start

subsegment = xray_recorder.current_subsegment()
subsegment.put_annotation(key="ColdStart", value=cold_start)

if cold_start:
subsegment.put_annotation(key="ColdStart", value=cold_start)
cold_start = False
else:
subsegment.put_annotation(key="ColdStart", value=cold_start)

result = app.resolve(event, context)
subsegment.put_metadata("response", result)
Expand All @@ -705,8 +704,8 @@ Let's break it down:
* **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.
* **L26-27**: We repeat what we did in L17-18 except we use the value `unknown` since we don't have that information.
* **L35**: We use `global` to modify our global variable defined in the outer scope.
* **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.
* **L45**: We include the final response under `response` key as part of the `handler` subsegment.
* **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.
* **L44**: We include the final response under `response` key as part of the `handler` subsegment.

???+ info
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"}.
Expand Down