Skip to content

Commit e2bfcb3

Browse files
authored
Merge pull request #609 from aws-powertools/develop
chore: Sync Main with Develop for release 1.11
2 parents 1bac3a9 + 33546b4 commit e2bfcb3

38 files changed

+601
-808
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
runs-on: ubuntu-latest
1919

2020
steps:
21-
- uses: actions/checkout@v3
21+
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
2222
- name: Setup .NET 6.0 & 8.0
2323
uses: actions/setup-dotnet@4d6c8fcf3c8f7a60068d26b594648e99df24cee3 # 4.0.0
2424
with:
@@ -32,10 +32,9 @@ jobs:
3232
- name: Test & Code Coverage
3333
run: dotnet test --collect:"XPlat Code Coverage" --results-directory ./codecov --verbosity normal
3434
- name: Codecov
35-
uses: codecov/codecov-action@5ecb98a3c6b747ed38dc09f787459979aebb39be # 4.3.1
36-
env:
37-
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
35+
uses: codecov/codecov-action@e28ff129e5465c2c0dcc6f003fc735cb6ae0c673 # 4.5.0
3836
with:
37+
token: ${{ secrets.CODECOV_TOKEN }}
3938
flags: unittests
4039
fail_ci_if_error: false
4140
name: codecov-lambda-powertools-dotnet

.github/workflows/codeql-analysis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525

2626
steps:
2727
- name: Checkout repository
28-
uses: actions/checkout@v3
28+
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
2929

3030
# Initializes the CodeQL tools for scanning.
3131
- name: Initialize CodeQL

.github/workflows/docs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
runs-on: ubuntu-latest
2121
environment: Docs
2222
steps:
23-
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c
23+
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
2424
with:
2525
fetch-depth: 0
2626
- name: Set up Python
@@ -52,7 +52,7 @@ jobs:
5252
runs-on: ubuntu-latest
5353
environment: Docs
5454
steps:
55-
- uses: actions/checkout@v3
55+
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
5656
- name: Setup .NET 6.0
5757
uses: actions/setup-dotnet@607fce577a46308457984d59e4954e075820f10a
5858
with:

.github/workflows/label_pr_on_title.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
runs-on: ubuntu-latest
2323
steps:
2424
- name: Checkout repository
25-
uses: actions/checkout@v3
25+
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
2626
- name: "Label PR based on title"
2727
uses: actions/github-script@v6
2828
env:

.github/workflows/on_label_added.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
issues: write
2424
pull-requests: write
2525
steps:
26-
- uses: actions/checkout@v3
26+
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
2727
# Maintenance: Persist state per PR as an artifact to avoid spam on label add
2828
- name: "Suggest split large Pull Request"
2929
uses: actions/github-script@v6

.github/workflows/on_merged_pr.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
runs-on: ubuntu-latest
2121
if: needs.get_pr_details.outputs.prIsMerged == 'true'
2222
steps:
23-
- uses: actions/checkout@v3
23+
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
2424
- name: "Label PR related issue for release"
2525
uses: actions/github-script@v6
2626
env:

.github/workflows/on_opened_pr.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
needs: get_pr_details
2020
runs-on: ubuntu-latest
2121
steps:
22-
- uses: actions/checkout@v3
22+
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
2323
- name: "Ensure related issue is present"
2424
uses: actions/github-script@v6
2525
env:

.github/workflows/record_pr.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
runs-on: ubuntu-latest
1010

1111
steps:
12-
- uses: actions/checkout@v3
12+
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
1313
- name: "Extract PR details"
1414
uses: actions/github-script@v6
1515
with:

.github/workflows/reusable_export_pr_details.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
5353
prIsMerged: ${{ steps.prIsMerged.outputs.prIsMerged }}
5454
steps:
5555
- name: Checkout repository # in case caller workflow doesn't checkout thus failing with file not found
56-
uses: actions/checkout@v3
56+
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
5757
- name: "Download previously saved PR"
5858
uses: actions/github-script@v6
5959
env:

.github/workflows/reusable_publish_changelog.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
runs-on: ubuntu-latest
1919
steps:
2020
- name: Checkout repository # reusable workflows start clean, so we need to checkout again
21-
uses: actions/checkout@v3
21+
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
2222
with:
2323
fetch-depth: 0
2424
- name: Git client setup and refresh tip

.github/workflows/reusable_publish_docs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
runs-on: ubuntu-latest
3636
environment: Docs
3737
steps:
38-
- uses: actions/checkout@v3
38+
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
3939
with:
4040
fetch-depth: 0
4141
- name: Install poetry
@@ -86,7 +86,7 @@ jobs:
8686
runs-on: macos-latest
8787
environment: Docs
8888
steps:
89-
- uses: actions/checkout@v3
89+
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
9090
with:
9191
fetch-depth: 0
9292
- name: Configure and build api docs generator

.github/workflows/secure_workflows.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
runs-on: ubuntu-latest
1515
steps:
1616
- name: Checkout code
17-
uses: actions/checkout@v3
17+
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
1818
- name: Ensure 3rd party workflows have SHA pinned
1919
uses: zgosalvez/github-actions-ensure-sha-pinned-actions@6ca5574367befbc9efdb2fa25978084159c5902d # v1.3.0
2020
with:

docs/core/metrics.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ These metrics can be visualized through [Amazon CloudWatch Console](https://aws.
1313
* Validating your metrics against common metric definitions mistakes (for example, metric unit, values, max dimensions, max metrics)
1414
* Metrics are created asynchronously by the CloudWatch service. You do not need any custom stacks, and there is no impact to Lambda function latency
1515
* Context manager to create a one off metric with a different dimension
16+
* 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
1617

1718
<br />
1819

examples/Metrics/src/HelloWorld/HelloWorld.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<PackageReference Include="Amazon.Lambda.APIGatewayEvents" Version="2.7.0" />
1010
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.4.1" />
1111
<PackageReference Include="AWS.Lambda.Powertools.Logging" Version="1.5.1" />
12-
<PackageReference Include="AWS.Lambda.Powertools.Metrics" Version="1.6.1" />
12+
<PackageReference Include="AWS.Lambda.Powertools.Metrics" Version="1.6.2" />
1313
<PackageReference Include="AWSSDK.DynamoDBv2" Version="3.7.301.18" />
1414
</ItemGroup>
1515
</Project>

examples/ServerlessApi/src/LambdaPowertoolsAPI/LambdaPowertoolsAPI.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<ItemGroup>
1515
<PackageReference Include="Amazon.Lambda.AspNetCoreServer" Version="9.0.0" />
1616
<PackageReference Include="AWS.Lambda.Powertools.Logging" Version="1.5.1" />
17-
<PackageReference Include="AWS.Lambda.Powertools.Metrics" Version="1.6.1" />
17+
<PackageReference Include="AWS.Lambda.Powertools.Metrics" Version="1.6.2" />
1818
<PackageReference Include="AWS.Lambda.Powertools.Tracing" Version="1.4.2" />
1919
</ItemGroup>
2020
</Project>

libraries/src/AWS.Lambda.Powertools.Common/Aspects/UniversalWrapperAspect.cs

Lines changed: 21 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
@@ -15,6 +15,7 @@
1515

1616
using System;
1717
using System.Collections.Generic;
18+
using System.Diagnostics.CodeAnalysis;
1819
using System.Linq;
1920
using System.Linq.Expressions;
2021
using System.Reflection;
@@ -32,19 +33,19 @@ public class UniversalWrapperAspect
3233
/// <summary>
3334
/// The delegate cache
3435
/// </summary>
35-
private static readonly Dictionary<MethodBase, Handler> _delegateCache = new();
36+
private static readonly Dictionary<MethodBase, Handler> DelegateCache = new();
3637

3738
/// <summary>
3839
/// The asynchronous generic handler
3940
/// </summary>
40-
private static readonly MethodInfo _asyncGenericHandler =
41+
private static readonly MethodInfo AsyncGenericHandler =
4142
typeof(UniversalWrapperAttribute).GetMethod(nameof(UniversalWrapperAttribute.WrapAsync),
4243
BindingFlags.NonPublic | BindingFlags.Instance);
4344

4445
/// <summary>
4546
/// The synchronize generic handler
4647
/// </summary>
47-
private static readonly MethodInfo _syncGenericHandler =
48+
private static readonly MethodInfo SyncGenericHandler =
4849
typeof(UniversalWrapperAttribute).GetMethod(nameof(UniversalWrapperAttribute.WrapSync),
4950
BindingFlags.NonPublic | BindingFlags.Instance);
5051

@@ -94,6 +95,7 @@ public object Handle(
9495
/// <param name="returnType">Type of the return.</param>
9596
/// <param name="wrappers">The wrappers.</param>
9697
/// <returns>Handler.</returns>
98+
[UnconditionalSuppressMessage("AOT", "IL3050:Calling members annotated with 'RequiresDynamicCodeAttribute' may break functionality when AOT compiling.", Justification = "<Pending>")]
9799
private static Handler CreateMethodHandler(Type returnType, IEnumerable<UniversalWrapperAttribute> wrappers)
98100
{
99101
var targetParam = Expression.Parameter(typeof(Func<object[], object>), "orig");
@@ -107,13 +109,13 @@ private static Handler CreateMethodHandler(Type returnType, IEnumerable<Universa
107109
? returnType.GenericTypeArguments[0]
108110
: Type.GetType("System.Threading.Tasks.VoidTaskResult");
109111
returnType = typeof(Task<>).MakeGenericType(taskType);
110-
wrapperMethod = _asyncGenericHandler.MakeGenericMethod(taskType);
112+
wrapperMethod = AsyncGenericHandler.MakeGenericMethod(taskType);
111113
}
112114
else
113115
{
114116
if (returnType == typeof(void))
115117
returnType = typeof(object);
116-
wrapperMethod = _syncGenericHandler.MakeGenericMethod(returnType);
118+
wrapperMethod = SyncGenericHandler.MakeGenericMethod(returnType);
117119
}
118120

119121
var converArgs = Expression.Parameter(typeof(object[]), "args");
@@ -128,9 +130,9 @@ private static Handler CreateMethodHandler(Type returnType, IEnumerable<Universa
128130
argsParam);
129131
}
130132

131-
var orig_args = Expression.Parameter(typeof(object[]), "orig_args");
132-
var handler = Expression.Lambda<Handler>(Expression.Convert(Expression.Invoke(next, orig_args), typeof(object)),
133-
targetParam, orig_args, eventArgsParam);
133+
var origArgs = Expression.Parameter(typeof(object[]), "orig_args");
134+
var handler = Expression.Lambda<Handler>(Expression.Convert(Expression.Invoke(next, origArgs), typeof(object)),
135+
targetParam, origArgs, eventArgsParam);
134136

135137
var handlerCompiled = handler.Compile();
136138

@@ -147,14 +149,14 @@ private static Handler CreateMethodHandler(Type returnType, IEnumerable<Universa
147149
private static Handler GetMethodHandler(MethodBase method, Type returnType,
148150
IEnumerable<UniversalWrapperAttribute> wrappers)
149151
{
150-
if (!_delegateCache.TryGetValue(method, out var handler))
151-
lock (method)
152-
{
153-
if (!_delegateCache.TryGetValue(method, out handler))
154-
_delegateCache[method] = handler = CreateMethodHandler(returnType, wrappers);
155-
}
156-
157-
return handler;
152+
lock (method)
153+
{
154+
if (!DelegateCache.TryGetValue(method, out var handler))
155+
if (!DelegateCache.TryGetValue(method, out handler))
156+
DelegateCache[method] = handler = CreateMethodHandler(returnType, wrappers);
157+
158+
return handler;
159+
}
158160
}
159161

160162
/// <summary>

libraries/src/AWS.Lambda.Powertools.Common/Core/ISystemWrapper.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
* permissions and limitations under the License.
1414
*/
1515

16+
using System.IO;
17+
1618
namespace AWS.Lambda.Powertools.Common;
1719

1820
/// <summary>
@@ -57,4 +59,15 @@ public interface ISystemWrapper
5759
/// </summary>
5860
/// <param name="type"></param>
5961
void SetExecutionEnvironment<T>(T type);
62+
63+
/// <summary>
64+
/// Sets console output
65+
/// Useful for testing and checking the console output
66+
/// <code>
67+
/// var consoleOut = new StringWriter();
68+
/// SystemWrapper.Instance.SetOut(consoleOut);
69+
/// </code>
70+
/// </summary>
71+
/// <param name="writeTo">The TextWriter instance where to write to</param>
72+
void SetOut(TextWriter writeTo);
6073
}

libraries/src/AWS.Lambda.Powertools.Common/Core/SystemWrapper.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,12 @@ public void SetExecutionEnvironment<T>(T type)
126126
SetEnvironmentVariable(envName, envValue.ToString());
127127
}
128128

129+
/// <inheritdoc />
130+
public void SetOut(TextWriter writeTo)
131+
{
132+
Console.SetOut(writeTo);
133+
}
134+
129135
/// <summary>
130136
/// Parsing the name to conform with the required naming convention for the UserAgent header (PTFeature/Name/Version)
131137
/// Fallback to Assembly Name on exception

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,4 @@
1111
<ProjectReference Include="..\AWS.Lambda.Powertools.Common\AWS.Lambda.Powertools.Common.csproj" PrivateAssets="All" />
1212
</ItemGroup>
1313

14-
<ItemGroup>
15-
<Folder Include="Serializer\" />
16-
</ItemGroup>
17-
1814
</Project>

0 commit comments

Comments
 (0)