Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
21 changes: 17 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
![aws provider](https://img.shields.io/badge/provider-AWS-orange?logo=amazon-aws&color=ff9900)
[![Build](https://github.com/aws-powertools/powertools-lambda-dotnet/actions/workflows/build.yml/badge.svg?branch=develop)](https://github.com/aws-powertools/powertools-lambda-dotnet/actions/workflows/build.yml)
[![codecov.io](https://codecov.io/github/aws-powertools/powertools-lambda-dotnet/branch/develop/graphs/badge.svg)](https://app.codecov.io/gh/aws-powertools/powertools-lambda-dotnet)
[![dotnet support](https://img.shields.io/static/v1?label=dotnet&message=%20NET6.0|NET8.0&color=blue?style=flat-square&logo=dotnet)](https://dotnet.microsoft.com/en-us/download/dotnet/6.0)
[![dotnet support](https://img.shields.io/static/v1?label=dotnet&message=%20NET8.0&color=blue?style=flat-square&logo=dotnet)](https://dotnet.microsoft.com/en-us/download/dotnet/8.0)
[![NuGet Downloads](https://img.shields.io/nuget/dt/AWS.Lambda.Powertools.Logging.svg)](https://www.nuget.org/packages?q=AWS.Lambda.Powertools) [![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/aws-powertools/powertools-lambda-dotnet/badge)](https://scorecard.dev/viewer/?uri=github.com/aws-powertools/powertools-lambda-dotnet)
[![Join our Discord](https://dcbadge.vercel.app/api/server/B8zZKbbyET?style=flat-square)](https://discord.gg/B8zZKbbyET)
[![Discord](https://img.shields.io/badge/Discord-Join_Community-7289da.svg)](https://discord.gg/B8zZKbbyET)

Powertools for AWS Lambda (.NET) is a developer toolkit to implement Serverless [best practices and increase developer velocity](https://docs.powertools.aws.dev/lambda-dotnet/#features).

Expand Down Expand Up @@ -37,7 +37,7 @@ Powertools for AWS Lambda (.NET) provides three core utilities:

### Installation

The Powertools for AWS Lambda (.NET) utilities (.NET 6 and .NET 8) are available as NuGet packages. You can install the packages from [NuGet Gallery](https://www.nuget.org/packages?q=AWS+Lambda+Powertools*) or from Visual Studio editor by searching `AWS.Lambda.Powertools*` to see various utilities available.
The Powertools for AWS Lambda (.NET) utilities are available as NuGet packages. You can install the packages from [NuGet Gallery](https://www.nuget.org/packages?q=AWS+Lambda+Powertools*) or from Visual Studio editor by searching `AWS.Lambda.Powertools*` to see various utilities available.

* [AWS.Lambda.Powertools.Logging](https://www.nuget.org/packages/AWS.Lambda.Powertools.Logging):

Expand Down Expand Up @@ -75,9 +75,22 @@ The Powertools for AWS Lambda (.NET) utilities (.NET 6 and .NET 8) are available

`dotnet add package AWS.Lambda.Powertools.EventHandler.Resolvers.BedrockAgentFunction`

* [AWS.Lambda.Powertools.Kafka.Avro](https://www.nuget.org/packages/AWS.Lambda.Powertools.Kafka.Avro):

`dotnet add package AWS.Lambda.Powertools.Kafka.Avro`

* [AWS.Lambda.Powertools.Kafka.Json](https://www.nuget.org/packages/AWS.Lambda.Powertools.Kafka.Json):

`dotnet add package AWS.Lambda.Powertools.Kafka.Json`

* [AWS.Lambda.Powertools.Kafka.Protobuf](https://www.nuget.org/packages/AWS.Lambda.Powertools.Kafka.Protobuf):

`dotnet add package AWS.Lambda.Powertools.Kafka.Protobuf`


## Examples

We have provided examples focused specifically on each of the utilities. Each solution comes with an AWS Serverless Application Model (AWS SAM) templates to run your functions as a Zip package using the AWS Lambda .NET 6 or .NET 8 managed runtime; or as a container package using the AWS base images for .NET.
We have provided examples focused specifically on each of the utilities. Each solution comes with an AWS Serverless Application Model (AWS SAM) templates to run your functions as a Zip package using the AWS Lambda .NET 8 managed runtime; or as a container package using the AWS base images for .NET.

* **[Logging example](examples/Logging/)**
* **[Metrics example](examples/Metrics/)**
Expand Down
12 changes: 12 additions & 0 deletions docs/core/event_handler/appsync_events.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@ stateDiagram-v2

**[AWS AppSync Events](https://docs.aws.amazon.com/appsync/latest/eventapi/event-api-welcome.html){target="_blank"}**. A service that enables you to quickly build secure, scalable real-time WebSocket APIs without managing infrastructure or writing API code. It handles connection management, message broadcasting, authentication, and monitoring, reducing time to market and operational costs.

!!! warning "Migrating to v3"

If you're upgrading to v3, please review the [Migration Guide v3](../migration-guide-v3.md) for important breaking changes including .NET 8 requirement and AWS SDK v4 migration.

## Installation

Install the package via NuGet:

```bash
dotnet add package AWS.Lambda.Powertools.EventHandler
```

## Getting started

???+ tip "Tip: New to AppSync Real-time API?"
Expand Down
3 changes: 3 additions & 0 deletions docs/core/event_handler/bedrock_agent_function.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ flowchart LR

**Amazon Bedrock Agent** is an Amazon Bedrock feature to build and deploy conversational agents that can interact with your customers using Large Language Models (LLM) and AWS Lambda functions.

!!! warning "Migrating to v3"

If you're upgrading to v3, please review the [Migration Guide v3](../migration-guide-v3.md) for important breaking changes including .NET 8 requirement and AWS SDK v4 migration.

## Installation

Expand Down
72 changes: 4 additions & 68 deletions docs/core/logging.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,75 +25,11 @@ The logging utility provides a Lambda optimized logger with output structured as
interface
* Support for message templates `{}` and `{@}` for structured logging

## Breaking changes from v1 (dependency updates)
!!! warning "Migrating to v3"

!!! info

Loooking for V1 specific documentation please go to [Logging v1](/lambda/dotnet/core/logging-v1)

| Change | Before (v1.x) | After (v2.0) | Migration Action |
|--------|---------------|--------------|-----------------|
| Amazon.Lambda.Core | 2.2.0|2.5.0 | dotnet add package Amazon.Lambda.Core |
| Amazon.Lambda.Serialization.SystemTextJson | 2.4.3 | 2.4.4 | dotnet add package Amazon.Lambda.Serialization.SystemTextJson |
| Microsoft.Extensions.DependencyInjection | 8.0.0 | 8.0.1 | dotnet add package Microsoft.Extensions.DependencyInjection |

#### Extra keys - Breaking change
If you're upgrading to v3, please review the [Migration Guide v3](../migration-guide-v3.md) for important breaking changes including .NET 8 requirement and AWS SDK v4 migration.

In v1.x, the extra keys were added to the log entry as a dictionary. In v2.x, the extra keys are added to the log entry as
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to dedicated page migration-guide-v2

a JSON object.

There is no longer a method that accepts extra keys as first argument.

=== "Before (v1)"

```csharp
public class User
{
public string Name { get; set; }
public int Age { get; set; }
}

Logger.LogInformation<User>(user, "{Name} is {Age} years old",
new object[]{user.Name, user.Age});

var scopeKeys = new
{
PropOne = "Value 1",
PropTwo = "Value 2"
};
Logger.LogInformation(scopeKeys, "message");

```

=== "After (v2)"

```csharp
public class User
{
public string Name { get; set; }
public int Age { get; set; }

public override string ToString()
{
return $"{Name} is {Age} years old";
}
}

// It uses the ToString() method of the object to log the message
// the extra keys are added because of the {@} in the message template
Logger.LogInformation("{@user}", user);

var scopeKeys = new
{
PropOne = "Value 1",
PropTwo = "Value 2"
};

// there is no longer a method that accepts extra keys as first argument.
Logger.LogInformation("{@keys}", scopeKeys);
```

This change was made to improve the performance of the logger and to make it easier to work with the extra keys.
If you're upgrading to v2, please review the [Migration Guide v2](../migration-guide-v2.md/#logging).


## Installation
Expand Down Expand Up @@ -1078,7 +1014,7 @@ inheriting the ``ILogFormatter`` class and implementing the ``object FormatLogEn

=== "CustomLogFormatter.cs"

```c#
```csharp
public class CustomLogFormatter : ILogFormatter
{
public object FormatLogEntry(LogEntry logEntry)
Expand Down
17 changes: 3 additions & 14 deletions docs/core/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,11 @@ These metrics can be visualized through [Amazon CloudWatch Console](https://aws.
* Ahead-of-Time compilation to native code support [AOT](https://docs.aws.amazon.com/lambda/latest/dg/dotnet-native-aot.html) from version 1.7.0
* Support for AspNetCore middleware and filters to capture metrics for HTTP requests

## Breaking changes from V1
!!! warning "Migrating to v3"

!!! info

Loooking for v1 specific documentation please go to [Metrics v1](/lambda/dotnet/core/metrics-v1)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved to dedicated guide


* **`Dimensions`** outputs as an array of arrays instead of an array of objects. Example: `Dimensions: [["service", "Environment"]]` instead of `Dimensions: ["service", "Environment"]`
* **`FunctionName`** is not added as default dimension and only to cold start metric.
* **`Default Dimensions`** can now be included in Cold Start metrics, this is a potential breaking change if you were relying on the absence of default dimensions in Cold Start metrics when searching.
If you're upgrading to v3, please review the [Migration Guide v3](../migration-guide-v3.md) for important breaking changes including .NET 8 requirement and AWS SDK v4 migration.

<br />

<figure>
<img src="../../media/metrics_utility_showcase.png" loading="lazy" alt="Screenshot of the Amazon CloudWatch Console showing an example of business metrics in the Metrics Explorer" />
<figcaption>Metrics showcase - Metrics Explorer</figcaption>
</figure>
If you're upgrading to v2, please review the [Migration Guide v2](../migration-guide-v2.md/#metrics).

## Installation

Expand Down
4 changes: 4 additions & 0 deletions docs/core/tracing.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ a provides functionality to reduce the overhead of performing common tracing tas
* Auto-disable when not running in AWS Lambda environment
* Ahead-of-Time compilation to native code support [AOT](https://docs.aws.amazon.com/lambda/latest/dg/dotnet-native-aot.html) from version 1.5.0

!!! warning "Migrating to v3"

If you're upgrading to v3, please review the [Migration Guide v3](../migration-guide-v3.md) for important breaking changes including .NET 8 requirement and AWS SDK v4 migration.

## Installation

Powertools for AWS Lambda (.NET) are available as NuGet packages. You can install the packages from [NuGet Gallery](https://www.nuget.org/packages?q=AWS+Lambda+Powertools*){target="_blank"} or from Visual Studio editor by searching `AWS.Lambda.Powertools*` to see various utilities available.
Expand Down
8 changes: 4 additions & 4 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ description: Powertools for AWS Lambda (.NET)
Powertools for AWS Lambda (.NET) (which from here will be referred as Powertools) is a suite of utilities for [AWS Lambda](https://aws.amazon.com/lambda/) functions to ease adopting best practices such as tracing, structured logging, custom metrics, and more.

!!! info
**Supports .NET 6 and .NET 8 runtimes**
**Supports .NET 8 runtime**

???+ tip
Powertools is also available for [Python](https://docs.powertools.aws.dev/lambda/python/){target="_blank"}, [Java](https://docs.powertools.aws.dev/lambda/java/){target="_blank"}, and [TypeScript](https://docs.powertools.aws.dev/lambda/typescript/latest/){target="_blank"}.
Expand Down Expand Up @@ -71,14 +71,14 @@ We have provided you with a custom template for the Serverless Application Model
To use the SAM CLI, you need the following tools.

* SAM CLI - [Install the SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html)
* .NET 6.0 (LTS) - [Install .NET 6.0](https://www.microsoft.com/net/download)
* .NET 8.0 (LTS) - [Install .NET 8.0](https://www.microsoft.com/net/download)
* Docker - [Install Docker community edition](https://hub.docker.com/search/?type=edition&offering=community)

Once you have SAM CLI installed, follow the these steps to initialize a .NET 6 project using Powertools for AWS (.NET)
Once you have SAM CLI installed, follow the these steps to initialize a .NET 8 project using Powertools for AWS (.NET)

1. Run the following command in your command line
```bash
sam init -r dotnet6
sam init -r dotnet8
```
2. Select option 1 as your template source

Expand Down
101 changes: 101 additions & 0 deletions docs/migration-guide-v2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
---
title: Migration Guide v2
slug: migration-guide-v2
description: Migration guide to upgrade to v2
---

# Migration Guide to v2

This guide will help you migrate to v2

## Logging

### Breaking changes from v1 (dependency updates)

!!! info

Looking for V1 specific documentation please go to [Logging v1](/lambda/dotnet/core/logging-v1)

| Change | Before (v1.x) | After (v2.0) | Migration Action |
|--------|---------------|--------------|-----------------|
| Amazon.Lambda.Core | 2.2.0|2.5.0 | dotnet add package Amazon.Lambda.Core |
| Amazon.Lambda.Serialization.SystemTextJson | 2.4.3 | 2.4.4 | dotnet add package Amazon.Lambda.Serialization.SystemTextJson |
| Microsoft.Extensions.DependencyInjection | 8.0.0 | 8.0.1 | dotnet add package Microsoft.Extensions.DependencyInjection |

#### Extra keys - Breaking change

In v1.x, the extra keys were added to the log entry as a dictionary. In v2.x, the extra keys are added to the log entry as
a JSON object.

There is no longer a method that accepts extra keys as first argument.

=== "Before (v1)"

```csharp
public class User
{
public string Name { get; set; }
public int Age { get; set; }
}

Logger.LogInformation<User>(user, "{Name} is {Age} years old",
new object[]{user.Name, user.Age});

var scopeKeys = new
{
PropOne = "Value 1",
PropTwo = "Value 2"
};
Logger.LogInformation(scopeKeys, "message");

```

=== "After (v2)"

```csharp
public class User
{
public string Name { get; set; }
public int Age { get; set; }

public override string ToString()
{
return $"{Name} is {Age} years old";
}
}

// It uses the ToString() method of the object to log the message
// the extra keys are added because of the {@} in the message template
Logger.LogInformation("{@user}", user);

var scopeKeys = new
{
PropOne = "Value 1",
PropTwo = "Value 2"
};

// there is no longer a method that accepts extra keys as first argument.
Logger.LogInformation("{@keys}", scopeKeys);
```

This change was made to improve the performance of the logger and to make it easier to work with the extra keys.

## Metrics

### Breaking changes from V1

!!! info

Loooking for v1 specific documentation please go to [Metrics v1](/lambda/dotnet/core/metrics-v1)

* **`Dimensions`** outputs as an array of arrays instead of an array of objects. Example: `Dimensions: [["service", "Environment"]]` instead of `Dimensions: ["service", "Environment"]`
* **`FunctionName`** is not added as default dimension and only to cold start metric.
* **`Default Dimensions`** can now be included in Cold Start metrics, this is a potential breaking change if you were relying on the absence of default dimensions in Cold Start metrics when searching.

<br />

<figure>
<img src="../../media/metrics_utility_showcase.png" loading="lazy" alt="Screenshot of the Amazon CloudWatch Console showing an example of business metrics in the Metrics Explorer" />
<figcaption>Metrics showcase - Metrics Explorer</figcaption>
</figure>

Loading
Loading