Skip to content

chore: Sync develop to main #431

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 14 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
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
42 changes: 41 additions & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,47 @@ updates:
prefix: chore
include: scope
- package-ecosystem: "nuget" # See documentation for possible values
directory: "/examples/" # Location of package manifests
directory: "/examples/Idempotency/" # Location of package manifests
schedule:
interval: "weekly"
target-branch: "develop"
commit-message:
prefix: chore
include: scope
- package-ecosystem: "nuget" # See documentation for possible values
directory: "/examples/Logging/" # Location of package manifests
schedule:
interval: "weekly"
target-branch: "develop"
commit-message:
prefix: chore
include: scope
- package-ecosystem: "nuget" # See documentation for possible values
directory: "/examples/Metrics/" # Location of package manifests
schedule:
interval: "weekly"
target-branch: "develop"
commit-message:
prefix: chore
include: scope
- package-ecosystem: "nuget" # See documentation for possible values
directory: "/examples/Parameters/" # Location of package manifests
schedule:
interval: "weekly"
target-branch: "develop"
commit-message:
prefix: chore
include: scope
- package-ecosystem: "nuget" # See documentation for possible values
directory: "/examples/ServerlessApi/" # Location of package manifests
schedule:
interval: "weekly"
target-branch: "develop"
commit-message:
prefix: chore
include: scope
- package-ecosystem: "nuget" # See documentation for possible values
directory: "/examples/Tracing/" # Location of package manifests
schedule:
interval: "weekly"
target-branch: "develop"
Expand Down
35 changes: 33 additions & 2 deletions docs/core/tracing.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,5 +244,36 @@ under a subsegment, or you are doing multithreaded programming. Refer examples b

## Instrumenting SDK clients and HTTP calls

User should make sure to instrument the SDK clients explicitly based on the function dependency. 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).
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.

=== "Function.cs"

```c# hl_lines="14"
using Amazon.DynamoDBv2;
using Amazon.DynamoDBv2.Model;
using AWS.Lambda.Powertools.Tracing;

public class Function
{
private static IAmazonDynamoDB _dynamoDb;

/// <summary>
/// Function constructor
/// </summary>
public Function()
{
Tracing.RegisterForAllServices();

_dynamoDb = new AmazonDynamoDBClient();
}
}
```

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.

```c#
Tracing.Register<IAmazonDynamoDB>()
```

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).

52 changes: 27 additions & 25 deletions docs/utilities/idempotency.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ You can quickly start by configuring `Idempotency` and using it with the `Idempo
!!! warning "Important"
Initialization and configuration of the `Idempotency` must be performed outside the handler, preferably in the constructor.

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

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

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

=== "Payment function"

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

=== "Sample event"

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

???+ note
This is automatically done when you decorate your Lambda handler with [Idempotent attribute](#idempotent-attribute).

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"},
Powertools for AWS Lambda (.NET) calculates and includes the remaining invocation available time as part of the idempotency record.
This is automatically done when you decorate your Lambda handler with [Idempotent attribute](#idempotent-attribute).
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"},
Powertools for AWS Lambda (.NET) calculates and includes the remaining invocation available time as part of the idempotency record.

???+ example
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).
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).

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

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

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

=== "Registering the Lambda context"

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

=== "Handling exceptions"

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

=== "Function.cs"

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

=== "Function.cs"

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

=== "Success Event"

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

=== "Custom AmazonDynamoDBClient"

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

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

```csharp title="Reusing a DynamoDB table that uses a composite primary key"
Idempotency.Configure(builder =>
builder.UseDynamoDb(storeBuilder =>
storeBuilder.
WithTableName("TABLE_NAME")
.WithSortKeyAttr("sort_key")
));
```
=== "Reusing a DynamoDB table that uses a composite primary key"

```csharp hl_lines="5"
Idempotency.Configure(builder =>
builder.UseDynamoDb(storeBuilder =>
storeBuilder.
WithTableName("TABLE_NAME")
.WithSortKeyAttr("sort_key")
));
```

Data would then be stored in DynamoDB like this:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="AWSSDK.XRay" Version="3.7.102.25" />
<PackageReference Include="AWSSDK.XRay" Version="3.7.200.34" />
<PackageReference Include="AWSXRayRecorder.Core" Version="2.14.0" />
<PackageReference Include="AWSXRayRecorder.Handlers.AwsSdk" Version="2.12.0" />
</ItemGroup>
<ItemGroup>
<None Include="README.md" Pack="true" PackagePath="\" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,15 @@ public void OnEntry(AspectEventArgs eventArgs)
if (_captureAnnotations)
{
_xRayRecorder.AddAnnotation("ColdStart", _isColdStart);

_isColdStart = false;

_captureAnnotations = false;
_isAnnotationsCaptured = true;

if (_powertoolsConfigurations.IsServiceDefined)
_xRayRecorder.AddAnnotation("Service", _powertoolsConfigurations.Service);
}

_isColdStart = false;
}

/// <summary>
Expand Down
17 changes: 17 additions & 0 deletions libraries/src/AWS.Lambda.Powertools.Tracing/Tracing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

using System;
using Amazon.XRay.Recorder.Core.Internal.Entities;
using Amazon.XRay.Recorder.Handlers.AwsSdk;
using AWS.Lambda.Powertools.Common;
using AWS.Lambda.Powertools.Tracing.Internal;

Expand Down Expand Up @@ -239,4 +240,20 @@ private static string GetNamespaceOrDefault(string nameSpace)

return PowertoolsConfigurations.Instance.Service;
}

/// <summary>
/// Registers X-Ray for all instances of <see cref="Amazon.Runtime.AmazonServiceClient"/>.
/// </summary>
public static void RegisterForAllServices()
{
AWSSDKHandler.RegisterXRayForAllServices();
}

/// <summary>
/// Registers X-Ray for the given type of <see cref="Amazon.Runtime.AmazonServiceClient"/>.
/// </summary>
public static void Register<T>()
{
AWSSDKHandler.RegisterXRay<T>();
}
}
20 changes: 16 additions & 4 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ theme:
palette:
- scheme: default
primary: blue
accent: deep orange
accent: deep blue
toggle:
icon: material/toggle-switch-off-outline
name: Switch to dark mode
- scheme: slate
primary: blue
accent: orange
accent: deep blue
toggle:
icon: material/toggle-switch
name: Switch to light mode
Expand Down Expand Up @@ -69,9 +69,15 @@ markdown_extensions:
permalink: true
toc_depth: 4
- attr_list
- pymdownx.emoji
- pymdownx.emoji:
emoji_index: !!python/name:materialx.emoji.twemoji
emoji_generator: !!python/name:materialx.emoji.to_svg
- pymdownx.inlinehilite
- pymdownx.superfences
- pymdownx.superfences:
custom_fences:
- name: mermaid
class: mermaid
format: !!python/name:pymdownx.superfences.fence_code_format

copyright: Copyright &copy; 2023 Amazon Web Services

Expand All @@ -88,3 +94,9 @@ extra_javascript:
extra:
version:
provider: mike
social:
- icon: fontawesome/brands/github
link: https://github.com/aws-powertools/powertools-lambda-dotnet
- icon: fontawesome/brands/discord
link: https://discord.gg/B8zZKbbyET
name: Join our Discord Server!
4 changes: 2 additions & 2 deletions version.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"Common": "1.1.2",
"Logging": "1.2.0",
"Metrics": "1.3.3",
"Tracing": "1.1.2"
"Tracing": "1.2.0"
},
"Utilities": {
"Parameters": "0.0.3-preview",
"Parameters": "1.0.0",
"Idempotency": "0.1.0-preview"
}
}