Skip to content

Commit 3f58f3a

Browse files
authored
Merge pull request #551 from aws-powertools/develop
chore: Sync main with develop
2 parents 7de954a + efec6fb commit 3f58f3a

File tree

34 files changed

+143
-77
lines changed

34 files changed

+143
-77
lines changed

.github/workflows/build.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@ jobs:
1616

1717
steps:
1818
- uses: actions/checkout@v3
19-
- name: Setup .NET 6.0
19+
- name: Setup .NET 6.0 & 8.0
2020
uses: actions/setup-dotnet@607fce577a46308457984d59e4954e075820f10a
2121
with:
22-
dotnet-version: 6.0.405
23-
- name: Install solution dependencies
24-
run: dotnet restore
22+
dotnet-version: |
23+
6.0.405
24+
8.0.101
2525
- name: Build
26-
run: dotnet build --configuration Release --no-restore
26+
run: dotnet build --configuration Release
2727
- name: Test Examples
2828
run: dotnet test ../examples/
2929
- name: Test & Code Coverage
30-
run: dotnet test --collect:"XPlat Code Coverage" -r ./codecov --no-restore --verbosity normal
30+
run: dotnet test --collect:"XPlat Code Coverage" --results-directory ./codecov --verbosity normal
3131
- name: Codecov
3232
uses: codecov/codecov-action@81cd2dc8148241f03f5839d295e000b8f761e378 # 3.1.0
3333
with:

docs/core/logging.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ for known event sources, where either a request ID or X-Ray Trace ID are present
223223
*/
224224
public class Function
225225
{
226-
[Logging(CorrelationIdPath = CorrelationIdPaths.API_GATEWAY_REST)]
226+
[Logging(CorrelationIdPath = CorrelationIdPaths.ApiGatewayRest)]
227227
public async Task<APIGatewayProxyResponse> FunctionHandler
228228
(APIGatewayProxyRequest apigProxyEvent, ILambdaContext context)
229229
{

docs/core/tracing.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ a provides functionality to reduce the overhead of performing common tracing tas
1515
* Capture function responses and full exceptions as metadata.
1616
* Better experience when developing with multiple threads.
1717
* Auto-patch supported modules by AWS X-Ray
18+
* Auto-disable when not running in AWS Lambda environment
1819

1920
## Installation
2021

docs/utilities/batch-processing.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,20 @@ This behavior changes when you enable Report Batch Item Failures feature in your
6262

6363
You can find more details on how Lambda works with either [SQS](https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html){target="_blank"}, [Kinesis](https://docs.aws.amazon.com/lambda/latest/dg/with-kinesis.html){target="_blank"}, or [DynamoDB](https://docs.aws.amazon.com/lambda/latest/dg/with-ddb.html){target="_blank"} in the AWS Documentation.
6464

65+
## Installation
66+
67+
You should install with NuGet:
68+
69+
```powershell
70+
Install-Package AWS.Lambda.Powertools.BatchProcessing
71+
```
72+
73+
Or via the .NET Core command line interface:
74+
75+
```bash
76+
dotnet add package AWS.Lambda.Powertools.BatchProcessing
77+
```
78+
6579
## Getting started
6680

6781
For this feature to work, you need to **(1)** configure your Lambda function event source to use `ReportBatchItemFailures`, and **(2)** return [a specific response](https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html#services-sqs-batchfailurereporting){target="_blank" rel="nofollow"} to report which records failed to be processed.

examples/BatchProcessing/src/HelloWorld/HelloWorld.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFramework>net6.0</TargetFramework>
3+
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
44
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
55
<Nullable>enable</Nullable>
66
</PropertyGroup>

examples/BatchProcessing/test/HelloWorld.Test/HelloWorld.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFramework>net6.0</TargetFramework>
3+
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
44
</PropertyGroup>
55
<ItemGroup>
66
<PackageReference Include="Amazon.Lambda.Core" Version="2.1.0" />

examples/Idempotency/src/HelloWorld/HelloWorld.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFramework>net6.0</TargetFramework>
3+
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
44
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
55
<Nullable>enable</Nullable>
66
</PropertyGroup>

examples/Idempotency/test/HelloWorld.Test/HelloWorld.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFramework>net6.0</TargetFramework>
3+
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
44
</PropertyGroup>
55
<ItemGroup>
66
<PackageReference Include="Amazon.Lambda.Core" Version="2.1.0" />

examples/Logging/src/HelloWorld/HelloWorld.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFramework>net6.0</TargetFramework>
3+
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
44
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
55
<Nullable>enable</Nullable>
66
</PropertyGroup>

examples/Logging/test/HelloWorld.Test/HelloWorld.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFramework>net6.0</TargetFramework>
3+
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
44
</PropertyGroup>
55
<ItemGroup>
66
<PackageReference Include="Amazon.Lambda.Core" Version="2.1.0" />

examples/Metrics/src/HelloWorld/HelloWorld.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFramework>net6.0</TargetFramework>
3+
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
44
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
55
<Nullable>enable</Nullable>
66
</PropertyGroup>

examples/Metrics/test/HelloWorld.Test/HelloWorld.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFramework>net6.0</TargetFramework>
3+
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
44
</PropertyGroup>
55
<ItemGroup>
66
<PackageReference Include="Amazon.Lambda.Core" Version="2.1.0" />

examples/Parameters/cfn/HelloWorld.Cfn/HelloWorld.Cfn.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFramework>net6.0</TargetFramework>
3+
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
44
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
55
<Nullable>enable</Nullable>
66
<RootNamespace>HelloWorld.Cfn</RootNamespace>

examples/Parameters/src/HelloWorld/HelloWorld.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFramework>net6.0</TargetFramework>
3+
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
44
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
55
<Nullable>enable</Nullable>
66
</PropertyGroup>

examples/Parameters/test/HelloWorld.Test/HelloWorld.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFramework>net6.0</TargetFramework>
3+
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
44
</PropertyGroup>
55
<ItemGroup>
66
<PackageReference Include="Amazon.Lambda.Core" Version="2.1.0" />

examples/ServerlessApi/src/LambdaPowertoolsAPI/LambdaPowertoolsAPI.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22
<PropertyGroup>
33
<OutputType>Exe</OutputType>
4-
<TargetFramework>net6.0</TargetFramework>
4+
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
77
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>

examples/ServerlessApi/test/LambdaPowertoolsAPI.Tests/LambdaPowertoolsAPI.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22
<PropertyGroup>
3-
<TargetFramework>net6.0</TargetFramework>
3+
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
44
<ImplicitUsings>enable</ImplicitUsings>
55
<Nullable>enable</Nullable>
66
<EnableDefaultContentItems>False</EnableDefaultContentItems>

examples/Tracing/src/HelloWorld/HelloWorld.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFramework>net6.0</TargetFramework>
3+
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
44
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
55
<Nullable>enable</Nullable>
66
</PropertyGroup>

examples/Tracing/test/HelloWorld.Test/HelloWorld.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFramework>net6.0</TargetFramework>
3+
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
44
</PropertyGroup>
55
<ItemGroup>
66
<PackageReference Include="Amazon.Lambda.Core" Version="2.1.0" />

global.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

libraries/src/AWS.Lambda.Powertools.Logging/LoggerExtensions.cs

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/*
22
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3-
*
3+
*
44
* Licensed under the Apache License, Version 2.0 (the "License").
55
* You may not use this file except in compliance with the License.
66
* A copy of the License is located at
7-
*
7+
*
88
* http://aws.amazon.com/apache2.0
9-
*
9+
*
1010
* or in the "license" file accompanying this file. This file is distributed
1111
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
1212
* express or implied. See the License for the specific language governing
@@ -187,7 +187,7 @@ public static void Log(this ILogger logger, LogLevel logLevel, Exception excepti
187187
#region ExtraKeys Logger Extentions
188188

189189
#region Debug
190-
190+
191191
/// <summary>
192192
/// Formats and writes a debug log message.
193193
/// </summary>
@@ -242,15 +242,16 @@ public static void LogDebug<T>(this ILogger logger, T extraKeys, Exception excep
242242
/// <param name="message">Format string of the log message in message template format. Example: <c>"User {User} logged in from {Address}"</c></param>
243243
/// <param name="args">An object array that contains zero or more objects to format.</param>
244244
/// <example>logger.LogDebug(extraKeys, "Processing request from {Address}", address)</example>
245-
public static void LogDebug<T>(this ILogger logger, T extraKeys, string message, params object[] args) where T : class
245+
public static void LogDebug<T>(this ILogger logger, T extraKeys, string message, params object[] args)
246+
where T : class
246247
{
247248
Log(logger, LogLevel.Debug, extraKeys, message, args);
248249
}
249-
250+
250251
#endregion
251252

252253
#region Trace
253-
254+
254255
/// <summary>
255256
/// Formats and writes a trace log message.
256257
/// </summary>
@@ -305,15 +306,16 @@ public static void LogTrace<T>(this ILogger logger, T extraKeys, Exception excep
305306
/// <param name="message">Format string of the log message in message template format. Example: <c>"User {User} logged in from {Address}"</c></param>
306307
/// <param name="args">An object array that contains zero or more objects to format.</param>
307308
/// <example>logger.LogTrace(extraKeys, "Processing request from {Address}", address)</example>
308-
public static void LogTrace<T>(this ILogger logger, T extraKeys, string message, params object[] args) where T : class
309+
public static void LogTrace<T>(this ILogger logger, T extraKeys, string message, params object[] args)
310+
where T : class
309311
{
310312
Log(logger, LogLevel.Trace, extraKeys, message, args);
311313
}
312314

313315
#endregion
314316

315317
#region Information
316-
318+
317319
/// <summary>
318320
/// Formats and writes an informational log message.
319321
/// </summary>
@@ -368,11 +370,12 @@ public static void LogInformation<T>(this ILogger logger, T extraKeys, Exception
368370
/// <param name="message">Format string of the log message in message template format. Example: <c>"User {User} logged in from {Address}"</c></param>
369371
/// <param name="args">An object array that contains zero or more objects to format.</param>
370372
/// <example>logger.LogInformation(extraKeys, "Processing request from {Address}", address)</example>
371-
public static void LogInformation<T>(this ILogger logger, T extraKeys, string message, params object[] args) where T : class
373+
public static void LogInformation<T>(this ILogger logger, T extraKeys, string message, params object[] args)
374+
where T : class
372375
{
373376
Log(logger, LogLevel.Information, extraKeys, message, args);
374377
}
375-
378+
376379
#endregion
377380

378381
#region Warning
@@ -431,11 +434,12 @@ public static void LogWarning<T>(this ILogger logger, T extraKeys, Exception exc
431434
/// <param name="message">Format string of the log message in message template format. Example: <c>"User {User} logged in from {Address}"</c></param>
432435
/// <param name="args">An object array that contains zero or more objects to format.</param>
433436
/// <example>logger.LogWarning(extraKeys, "Processing request from {Address}", address)</example>
434-
public static void LogWarning<T>(this ILogger logger, T extraKeys, string message, params object[] args) where T : class
437+
public static void LogWarning<T>(this ILogger logger, T extraKeys, string message, params object[] args)
438+
where T : class
435439
{
436440
Log(logger, LogLevel.Warning, extraKeys, message, args);
437441
}
438-
442+
439443
#endregion
440444

441445
#region Error
@@ -494,7 +498,8 @@ public static void LogError<T>(this ILogger logger, T extraKeys, Exception excep
494498
/// <param name="message">Format string of the log message in message template format. Example: <c>"User {User} logged in from {Address}"</c></param>
495499
/// <param name="args">An object array that contains zero or more objects to format.</param>
496500
/// <example>logger.LogError(extraKeys, "Processing request from {Address}", address)</example>
497-
public static void LogError<T>(this ILogger logger, T extraKeys, string message, params object[] args) where T : class
501+
public static void LogError<T>(this ILogger logger, T extraKeys, string message, params object[] args)
502+
where T : class
498503
{
499504
Log(logger, LogLevel.Error, extraKeys, message, args);
500505
}
@@ -557,15 +562,16 @@ public static void LogCritical<T>(this ILogger logger, T extraKeys, Exception ex
557562
/// <param name="message">Format string of the log message in message template format. Example: <c>"User {User} logged in from {Address}"</c></param>
558563
/// <param name="args">An object array that contains zero or more objects to format.</param>
559564
/// <example>logger.LogCritical(extraKeys, "Processing request from {Address}", address)</example>
560-
public static void LogCritical<T>(this ILogger logger, T extraKeys, string message, params object[] args) where T : class
565+
public static void LogCritical<T>(this ILogger logger, T extraKeys, string message, params object[] args)
566+
where T : class
561567
{
562568
Log(logger, LogLevel.Critical, extraKeys, message, args);
563569
}
564570

565571
#endregion
566572

567573
#region Log
568-
574+
569575
/// <summary>
570576
/// Formats and writes a log message at the specified log level.
571577
/// </summary>
@@ -630,11 +636,19 @@ public static void Log<T>(this ILogger logger, LogLevel logLevel, T extraKeys, E
630636
/// <param name="message">Format string of the log message in message template format. Example: <c>"User {User} logged in from {Address}"</c></param>
631637
/// <param name="args">An object array that contains zero or more objects to format.</param>
632638
/// <example>logger.Log(LogLevel.Information, extraKeys, "Processing request from {Address}", address)</example>
633-
public static void Log<T>(this ILogger logger, LogLevel logLevel, T extraKeys, string message, params object[] args) where T : class
639+
public static void Log<T>(this ILogger logger, LogLevel logLevel, T extraKeys, string message, params object[] args)
640+
where T : class
634641
{
635-
Log(logger, logLevel, extraKeys, 0, null, message, args);
642+
try
643+
{
644+
Log(logger, logLevel, extraKeys, 0, null, message, args);
645+
}
646+
catch (Exception e)
647+
{
648+
logger.Log(LogLevel.Error, 0, e, "Powertools internal error");
649+
}
636650
}
637-
651+
638652
#endregion
639653

640654
#endregion

libraries/src/Directory.Build.props

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<Project>
22
<PropertyGroup>
3-
4-
<TargetFramework>net6.0</TargetFramework>
3+
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
54
<LangVersion>default</LangVersion>
65
<!-- Version is generated when packaging the individual csproj -->
76
<Version>0.0.1</Version>

libraries/tests/AWS.Lambda.Powertools.BatchProcessing.Tests/AWS.Lambda.Powertools.BatchProcessing.Tests.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net6.0</TargetFramework>
54
<LangVersion>default</LangVersion>
65
<AssemblyName>AWS.Lambda.Powertools.BatchProcessing.Tests</AssemblyName>
76
<RootNamespace>AWS.Lambda.Powertools.BatchProcessing.Tests</RootNamespace>

libraries/tests/AWS.Lambda.Powertools.Common.Tests/AWS.Lambda.Powertools.Common.Tests.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net6.0</TargetFramework>
54
<AssemblyName>AWS.Lambda.Powertools.Common.Tests</AssemblyName>
65
<RootNamespace>AWS.Lambda.Powertools.Common.Tests</RootNamespace>
76
</PropertyGroup>

libraries/tests/AWS.Lambda.Powertools.Idempotency.Tests/AWS.Lambda.Powertools.Idempotency.Tests.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net6.0</TargetFramework>
54
<LangVersion>default</LangVersion>
65
<AssemblyName>AWS.Lambda.Powertools.Idempotency.Tests</AssemblyName>
76
<RootNamespace>AWS.Lambda.Powertools.Idempotency.Tests</RootNamespace>

libraries/tests/AWS.Lambda.Powertools.Logging.Tests/AWS.Lambda.Powertools.Logging.Tests.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net6.0</TargetFramework>
54
<LangVersion>default</LangVersion>
65
<AssemblyName>AWS.Lambda.Powertools.Logging.Tests</AssemblyName>
76
<RootNamespace>AWS.Lambda.Powertools.Logging.Tests</RootNamespace>
@@ -12,6 +11,8 @@
1211
<!-- More info https://learn.microsoft.com/en-us/nuget/consume-packages/central-package-management -->
1312
<PackageReference Include="Amazon.Lambda.ApplicationLoadBalancerEvents" />
1413
<PackageReference Include="Amazon.Lambda.APIGatewayEvents" />
14+
<PackageReference Include="Amazon.Lambda.Core" />
15+
<PackageReference Include="Amazon.Lambda.TestUtilities" />
1516
<PackageReference Include="coverlet.collector" >
1617
<PrivateAssets>all</PrivateAssets>
1718
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

0 commit comments

Comments
 (0)