Skip to content

Commit f92e9fb

Browse files
authored
Merge pull request #431 from aws-powertools/develop
chore: Sync develop to main
2 parents 46c85ee + 6192abc commit f92e9fb

File tree

8 files changed

+141
-37
lines changed

8 files changed

+141
-37
lines changed

.github/dependabot.yml

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,47 @@ updates:
1414
prefix: chore
1515
include: scope
1616
- package-ecosystem: "nuget" # See documentation for possible values
17-
directory: "/examples/" # Location of package manifests
17+
directory: "/examples/Idempotency/" # Location of package manifests
18+
schedule:
19+
interval: "weekly"
20+
target-branch: "develop"
21+
commit-message:
22+
prefix: chore
23+
include: scope
24+
- package-ecosystem: "nuget" # See documentation for possible values
25+
directory: "/examples/Logging/" # Location of package manifests
26+
schedule:
27+
interval: "weekly"
28+
target-branch: "develop"
29+
commit-message:
30+
prefix: chore
31+
include: scope
32+
- package-ecosystem: "nuget" # See documentation for possible values
33+
directory: "/examples/Metrics/" # Location of package manifests
34+
schedule:
35+
interval: "weekly"
36+
target-branch: "develop"
37+
commit-message:
38+
prefix: chore
39+
include: scope
40+
- package-ecosystem: "nuget" # See documentation for possible values
41+
directory: "/examples/Parameters/" # Location of package manifests
42+
schedule:
43+
interval: "weekly"
44+
target-branch: "develop"
45+
commit-message:
46+
prefix: chore
47+
include: scope
48+
- package-ecosystem: "nuget" # See documentation for possible values
49+
directory: "/examples/ServerlessApi/" # Location of package manifests
50+
schedule:
51+
interval: "weekly"
52+
target-branch: "develop"
53+
commit-message:
54+
prefix: chore
55+
include: scope
56+
- package-ecosystem: "nuget" # See documentation for possible values
57+
directory: "/examples/Tracing/" # Location of package manifests
1858
schedule:
1959
interval: "weekly"
2060
target-branch: "develop"

docs/core/tracing.md

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,5 +244,36 @@ under a subsegment, or you are doing multithreaded programming. Refer examples b
244244

245245
## Instrumenting SDK clients and HTTP calls
246246

247-
User should make sure to instrument the SDK clients explicitly based on the function dependency. Refer details on
248-
[how to instrument SDK client with Xray](https://docs.aws.amazon.com/xray/latest/devguide/xray-sdk-dotnet-sdkclients.html) and [outgoing http calls](https://docs.aws.amazon.com/xray/latest/devguide/xray-sdk-dotnet-httpclients.html).
247+
You should make sure to instrument the SDK clients explicitly based on the function dependency. You can instrument all of your AWS SDK for .NET clients by calling RegisterForAllServices before you create them.
248+
249+
=== "Function.cs"
250+
251+
```c# hl_lines="14"
252+
using Amazon.DynamoDBv2;
253+
using Amazon.DynamoDBv2.Model;
254+
using AWS.Lambda.Powertools.Tracing;
255+
256+
public class Function
257+
{
258+
private static IAmazonDynamoDB _dynamoDb;
259+
260+
/// <summary>
261+
/// Function constructor
262+
/// </summary>
263+
public Function()
264+
{
265+
Tracing.RegisterForAllServices();
266+
267+
_dynamoDb = new AmazonDynamoDBClient();
268+
}
269+
}
270+
```
271+
272+
To instrument clients for some services and not others, call Register instead of RegisterForAllServices. Replace the highlighted text with the name of the service's client interface.
273+
274+
```c#
275+
Tracing.Register<IAmazonDynamoDB>()
276+
```
277+
278+
This functionality is a thin wrapper for AWS X-Ray .NET SDK. Refer details on [how to instrument SDK client with Xray](https://docs.aws.amazon.com/xray/latest/devguide/xray-sdk-dotnet-sdkclients.html) and [outgoing http calls](https://docs.aws.amazon.com/xray/latest/devguide/xray-sdk-dotnet-httpclients.html).
279+

docs/utilities/idempotency.md

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ You can quickly start by configuring `Idempotency` and using it with the `Idempo
140140
!!! warning "Important"
141141
Initialization and configuration of the `Idempotency` must be performed outside the handler, preferably in the constructor.
142142

143-
```csharp hl_lines="4 7"
143+
```csharp hl_lines="5 8"
144144
public class Function
145145
{
146146
public Function()
@@ -167,7 +167,7 @@ When using `Idempotent` attribute on another method, you must tell which paramet
167167

168168
!!! info "The parameter must be serializable in JSON. We use `System.Text.Json` internally to (de)serialize objects"
169169

170-
```csharp hl_lines="4 13-14"
170+
```csharp hl_lines="5 14-15"
171171
public class Function
172172
{
173173
public Function()
@@ -211,7 +211,7 @@ If we were to treat the entire request as our idempotency key, a simple HTTP hea
211211

212212
=== "Payment function"
213213

214-
```csharp hl_lines="3"
214+
```csharp hl_lines="4"
215215
Idempotency.Configure(builder =>
216216
builder
217217
.WithOptions(optionsBuilder =>
@@ -221,7 +221,7 @@ If we were to treat the entire request as our idempotency key, a simple HTTP hea
221221

222222
=== "Sample event"
223223

224-
```json hl_lines="27"
224+
```json hl_lines="28"
225225
{
226226
"version": "2.0",
227227
"routeKey": "ANY /createpayment",
@@ -257,25 +257,25 @@ If we were to treat the entire request as our idempotency key, a simple HTTP hea
257257
### Lambda timeouts
258258

259259
???+ note
260-
This is automatically done when you decorate your Lambda handler with [Idempotent attribute](#idempotent-attribute).
261-
262-
To prevent against extended failed retries when a [Lambda function times out](https://aws.amazon.com/premiumsupport/knowledge-center/lambda-verify-invocation-timeouts/){target="_blank"},
263-
Powertools for AWS Lambda (.NET) calculates and includes the remaining invocation available time as part of the idempotency record.
260+
This is automatically done when you decorate your Lambda handler with [Idempotent attribute](#idempotent-attribute).
261+
262+
To prevent against extended failed retries when a [Lambda function times out](https://aws.amazon.com/premiumsupport/knowledge-center/lambda-verify-invocation-timeouts/){target="_blank"},
263+
Powertools for AWS Lambda (.NET) calculates and includes the remaining invocation available time as part of the idempotency record.
264264

265265
???+ example
266-
If a second invocation happens **after** this timestamp, and the record is marked as `INPROGRESS`, we will execute the invocation again as if it was in the `EXPIRED` state (e.g, `Expired` field elapsed).
266+
If a second invocation happens **after** this timestamp, and the record is marked as `INPROGRESS`, we will execute the invocation again as if it was in the `EXPIRED` state (e.g, `Expired` field elapsed).
267267

268268
This means that if an invocation expired during execution, it will be quickly executed again on the next retry.
269269

270270
???+ important
271-
If you are only using the [Idempotent attribute](#Idempotent-attribute-on-another-method) to guard isolated parts of your code,
272-
you must use `RegisterLambdaContext` available in the `Idempotency` static class to benefit from this protection.
271+
If you are only using the [Idempotent attribute](#Idempotent-attribute-on-another-method) to guard isolated parts of your code,
272+
you must use `RegisterLambdaContext` available in the `Idempotency` static class to benefit from this protection.
273273

274274
Here is an example on how you register the Lambda context in your handler:
275275

276276
=== "Registering the Lambda context"
277277

278-
```csharp hl_lines="9" title="Registering the Lambda context"
278+
```csharp hl_lines="10" title="Registering the Lambda context"
279279
public class Function
280280
{
281281
public Function()
@@ -331,7 +331,7 @@ If an Exception is raised _outside_ the scope of the decorated method and after
331331

332332
=== "Handling exceptions"
333333

334-
```csharp hl_lines="2-4 8-10" title="Exception not affecting idempotency record sample"
334+
```csharp hl_lines="10-12 16-18 21" title="Exception not affecting idempotency record sample"
335335
public class Function
336336
{
337337
public Function()
@@ -675,7 +675,7 @@ With **`PayloadValidationJMESPath`**, you can provide an additional JMESPath exp
675675

676676
=== "Function.cs"
677677

678-
```csharp
678+
```csharp hl_lines="6"
679679
Idempotency.Configure(builder =>
680680
builder
681681
.WithOptions(optionsBuilder =>
@@ -730,7 +730,7 @@ This means that we will throw **`IdempotencyKeyException`** if the evaluation of
730730

731731
=== "Function.cs"
732732

733-
```csharp
733+
```csharp hl_lines="9"
734734
public App()
735735
{
736736
Idempotency.Configure(builder =>
@@ -752,7 +752,7 @@ This means that we will throw **`IdempotencyKeyException`** if the evaluation of
752752

753753
=== "Success Event"
754754

755-
```json
755+
```json hl_lines="6"
756756
{
757757
"user": {
758758
"uid": "BB0D045C-8878-40C8-889E-38B3CB0A61B1",
@@ -782,7 +782,7 @@ When creating the `DynamoDBPersistenceStore`, you can set a custom [`AmazonDynam
782782

783783
=== "Custom AmazonDynamoDBClient"
784784

785-
```csharp
785+
```csharp hl_lines="3 9"
786786
public Function()
787787
{
788788
AmazonDynamoDBClient customClient = new AmazonDynamoDBClient(RegionEndpoint.APSouth1);
@@ -804,14 +804,16 @@ With this setting, we will save the idempotency key in the sort key instead of t
804804

805805
You can optionally set a static value for the partition key using the `StaticPkValue` parameter.
806806

807-
```csharp title="Reusing a DynamoDB table that uses a composite primary key"
808-
Idempotency.Configure(builder =>
809-
builder.UseDynamoDb(storeBuilder =>
810-
storeBuilder.
811-
WithTableName("TABLE_NAME")
812-
.WithSortKeyAttr("sort_key")
813-
));
814-
```
807+
=== "Reusing a DynamoDB table that uses a composite primary key"
808+
809+
```csharp hl_lines="5"
810+
Idempotency.Configure(builder =>
811+
builder.UseDynamoDb(storeBuilder =>
812+
storeBuilder.
813+
WithTableName("TABLE_NAME")
814+
.WithSortKeyAttr("sort_key")
815+
));
816+
```
815817

816818
Data would then be stored in DynamoDB like this:
817819

libraries/src/AWS.Lambda.Powertools.Tracing/AWS.Lambda.Powertools.Tracing.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@
3030
</ItemGroup>
3131

3232
<ItemGroup>
33-
<PackageReference Include="AWSSDK.XRay" Version="3.7.102.25" />
33+
<PackageReference Include="AWSSDK.XRay" Version="3.7.200.34" />
3434
<PackageReference Include="AWSXRayRecorder.Core" Version="2.14.0" />
35+
<PackageReference Include="AWSXRayRecorder.Handlers.AwsSdk" Version="2.12.0" />
3536
</ItemGroup>
3637
<ItemGroup>
3738
<None Include="README.md" Pack="true" PackagePath="\" />

libraries/src/AWS.Lambda.Powertools.Tracing/Internal/TracingAspectHandler.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,15 @@ public void OnEntry(AspectEventArgs eventArgs)
117117
if (_captureAnnotations)
118118
{
119119
_xRayRecorder.AddAnnotation("ColdStart", _isColdStart);
120-
121-
_isColdStart = false;
120+
122121
_captureAnnotations = false;
123122
_isAnnotationsCaptured = true;
124123

125124
if (_powertoolsConfigurations.IsServiceDefined)
126125
_xRayRecorder.AddAnnotation("Service", _powertoolsConfigurations.Service);
127126
}
127+
128+
_isColdStart = false;
128129
}
129130

130131
/// <summary>

libraries/src/AWS.Lambda.Powertools.Tracing/Tracing.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
using System;
1717
using Amazon.XRay.Recorder.Core.Internal.Entities;
18+
using Amazon.XRay.Recorder.Handlers.AwsSdk;
1819
using AWS.Lambda.Powertools.Common;
1920
using AWS.Lambda.Powertools.Tracing.Internal;
2021

@@ -239,4 +240,20 @@ private static string GetNamespaceOrDefault(string nameSpace)
239240

240241
return PowertoolsConfigurations.Instance.Service;
241242
}
243+
244+
/// <summary>
245+
/// Registers X-Ray for all instances of <see cref="Amazon.Runtime.AmazonServiceClient"/>.
246+
/// </summary>
247+
public static void RegisterForAllServices()
248+
{
249+
AWSSDKHandler.RegisterXRayForAllServices();
250+
}
251+
252+
/// <summary>
253+
/// Registers X-Ray for the given type of <see cref="Amazon.Runtime.AmazonServiceClient"/>.
254+
/// </summary>
255+
public static void Register<T>()
256+
{
257+
AWSSDKHandler.RegisterXRay<T>();
258+
}
242259
}

mkdocs.yml

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ theme:
2626
palette:
2727
- scheme: default
2828
primary: blue
29-
accent: deep orange
29+
accent: deep blue
3030
toggle:
3131
icon: material/toggle-switch-off-outline
3232
name: Switch to dark mode
3333
- scheme: slate
3434
primary: blue
35-
accent: orange
35+
accent: deep blue
3636
toggle:
3737
icon: material/toggle-switch
3838
name: Switch to light mode
@@ -69,9 +69,15 @@ markdown_extensions:
6969
permalink: true
7070
toc_depth: 4
7171
- attr_list
72-
- pymdownx.emoji
72+
- pymdownx.emoji:
73+
emoji_index: !!python/name:materialx.emoji.twemoji
74+
emoji_generator: !!python/name:materialx.emoji.to_svg
7375
- pymdownx.inlinehilite
74-
- pymdownx.superfences
76+
- pymdownx.superfences:
77+
custom_fences:
78+
- name: mermaid
79+
class: mermaid
80+
format: !!python/name:pymdownx.superfences.fence_code_format
7581

7682
copyright: Copyright &copy; 2023 Amazon Web Services
7783

@@ -88,3 +94,9 @@ extra_javascript:
8894
extra:
8995
version:
9096
provider: mike
97+
social:
98+
- icon: fontawesome/brands/github
99+
link: https://github.com/aws-powertools/powertools-lambda-dotnet
100+
- icon: fontawesome/brands/discord
101+
link: https://discord.gg/B8zZKbbyET
102+
name: Join our Discord Server!

version.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
"Common": "1.1.2",
44
"Logging": "1.2.0",
55
"Metrics": "1.3.3",
6-
"Tracing": "1.1.2"
6+
"Tracing": "1.2.0"
77
},
88
"Utilities": {
9-
"Parameters": "0.0.3-preview",
9+
"Parameters": "1.0.0",
1010
"Idempotency": "0.1.0-preview"
1111
}
1212
}

0 commit comments

Comments
 (0)