Skip to content

chore: update docs #864

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

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .github/workflows/publish-artifacts-examples-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ jobs:
--name github \
--username ${{ github.actor }} \
--password ${{ secrets.GITHUB_TOKEN }}
--store-password-in-clear-text

- name: Publish packages to GitHub Packages
run: |
Expand Down
109 changes: 104 additions & 5 deletions docs/core/logging-v2.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: Logging V2
title: Logging v2
description: Core utility
---

Expand All @@ -25,6 +25,73 @@ 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)

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


## Installation

Powertools for AWS Lambda (.NET) are available as NuGet packages. You can install the packages
Expand Down Expand Up @@ -236,6 +303,9 @@ Your logs will always include the following keys to your structured logging:
**SamplingRate** | int | 0.1 | Debug logging sampling rate in percentage e.g. 10% in this case
**Customer Keys** | | |

!!! Warning
If you emit a log message with a key that matches one of `level`, `message`, `name`, `service`, or `timestamp`, the Logger will ignore the key.

## Message templates

You can use message templates to extract properties from your objects and log them as structured data.
Expand Down Expand Up @@ -1467,10 +1537,13 @@ You can change where the `Logger` will output its logs by setting the `LogOutput
We also provide a helper class for tests `TestLoggerOutput` or you can provider your own implementation of `IConsoleWrapper`.

```csharp
// Using TestLoggerOutput
options.LogOutput = new TestLoggerOutput();
// Custom console output for testing
options.LogOutput = new TestConsoleWrapper();
Logger.Configure(options =>
{
// Using TestLoggerOutput
options.LogOutput = new TestLoggerOutput();
// Custom console output for testing
options.LogOutput = new TestConsoleWrapper();
});

// Example implementation for testing:
public class TestConsoleWrapper : IConsoleWrapper
Expand All @@ -1483,6 +1556,32 @@ public class TestConsoleWrapper : IConsoleWrapper
}
}
```
```csharp
// Test example
[Fact]
public void When_Setting_Service_Should_Update_Key()
{
// Arrange
var consoleOut = new TestLoggerOutput();
Logger.Configure(options =>
{
options.LogOutput = consoleOut;
});

// Act
_testHandlers.HandlerService();

// Assert

var st = consoleOut.ToString();

Assert.Contains("\"level\":\"Information\"", st);
Assert.Contains("\"service\":\"test\"", st);
Assert.Contains("\"name\":\"AWS.Lambda.Powertools.Logging.Logger\"", st);
Assert.Contains("\"message\":\"test\"", st);
}
```

### ILogger

If you are using ILogger interface you can inject the logger in a dedicated constructor for your Lambda function and thus you can mock your ILogger instance.
Expand Down
11 changes: 10 additions & 1 deletion docs/core/logging.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
---
title: Logging
title: Logging v1
description: Core utility
---

!!! warning
Version 1.x.x will continue to be supported until **end of July 2025** for critical bug fixes and security updates in very exceptional cases where you cannot update to v2, but no new features will be added to this version.

We recommend you upgrade to the latest version.

The latest version is available at [Logging v2](https://docs.powertools.aws.dev/lambda/dotnet/core/logging-v2/).


The logging utility provides a Lambda optimized logger with output structured as JSON.


## Key features

* Capture key fields from Lambda context, cold start and structures logging output as JSON
Expand Down
8 changes: 7 additions & 1 deletion docs/core/metrics.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
---
title: Metrics
title: Metrics v1
description: Core utility
---

!!! warning
Version 1.x.x will continue to be supported **until end of October 2025** for bug fixes and security updates, but no new features will be added to this version. We recommend you upgrade to the latest version.

The latest version is available at [Metrics v2](https://docs.powertools.aws.dev/lambda/dotnet/core/metrics-v2/).


Metrics creates custom metrics asynchronously by logging metrics to standard output following [Amazon CloudWatch Embedded Metric Format (EMF)](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Embedded_Metric_Format.html).

These metrics can be visualized through [Amazon CloudWatch Console](https://aws.amazon.com/cloudwatch/).
Expand Down
Empty file.
4 changes: 4 additions & 0 deletions docs/getting-started/idempotency/simple.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
title: Simple Logging
description: Getting started with Logging
---
Loading