Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
88fdaa3
feat: update environment variable references to use AWS_SDK_UA_APP_ID
hjgraca Jul 21, 2025
d0c3a26
Merge branch 'develop' into chore/ua-change-env
hjgraca Jul 29, 2025
d593cbb
on sourcegenerator per project
hjgraca Jul 28, 2025
c1927d6
chore: update execution environment setter to support utility name an…
hjgraca Jul 28, 2025
65cfe37
chore: remove SetExecutionEnvironment from PowertoolsConfigurations a…
hjgraca Jul 28, 2025
5a17bdf
chore: update CodeAnalysis dependency usage and refine UA environment…
hjgraca Jul 29, 2025
ac4fa6f
chore: refactor UA environment initialization with EnvWrapper and upd…
hjgraca Jul 29, 2025
a13b8d0
chore: update UA app ID test to reflect new environment variable order
hjgraca Jul 29, 2025
ec06192
chore: remove obsolete execution environment setter and update Lambda…
hjgraca Jul 29, 2025
2c6e7a2
chore: add explicit namespace declarations to UA source generators fo…
hjgraca Jul 29, 2025
067e9d8
chore: update UA environment handling to use dynamic execution enviro…
hjgraca Aug 21, 2025
247a23a
Merge branch 'develop' into chore/ua-change-env
hjgraca Sep 16, 2025
b6531b3
chore: remove IPowertoolsConfigurations dependency from batch process…
hjgraca Sep 16, 2025
843a928
chore: update UASourceGenerator to register compilation provider for …
hjgraca Sep 16, 2025
b008221
chore: initialize module initializers
hjgraca Sep 16, 2025
7d0b64d
chore: add UASourceGenerator analyzer to project files
hjgraca Sep 16, 2025
494775a
Revert "chore: update UASourceGenerator to register compilation provi…
hjgraca Sep 16, 2025
55e7b8c
Revert "chore: add UASourceGenerator analyzer to project files"
hjgraca Sep 16, 2025
fe51661
Revert "chore: initialize module initializers"
hjgraca Sep 16, 2025
c4f5561
updated the project references in libraries/tests/AWS.Lambda.Powertoo…
hjgraca Sep 16, 2025
fe6b07d
Force loading of all the assemblies by accessing their types
hjgraca Sep 16, 2025
51eda50
add fallback
hjgraca Sep 16, 2025
182630d
using reflection
hjgraca Sep 16, 2025
ebc4cc1
replace source generator with module initializer
hjgraca Sep 16, 2025
6fdfccc
add module initializers for AWS Lambda Powertools libraries with envi…
hjgraca Sep 16, 2025
d5906e7
add XML documentation for EnvWrapper class and its method. remove bui…
hjgraca Sep 17, 2025
da79060
remove IncludeExecutionEnvironment property from project files
hjgraca Sep 17, 2025
9eeb52f
cleanup
hjgraca Sep 17, 2025
b9e95ce
add MSBuild targets for auto-initializers in AWS Lambda Powertools li…
hjgraca Sep 17, 2025
f587b0f
refactor tests for MSBuild auto-initialization and improve logging
hjgraca Sep 17, 2025
92316fd
add MSBuild targets for auto-initializers in Kafka libraries
hjgraca Sep 17, 2025
f16d005
remove SetExecutionEnvironment calls from various classes and add Env…
hjgraca Sep 17, 2025
5cddf03
update environment variable prefix from PTENV to PTEnv for consistenc…
hjgraca Sep 19, 2025
531eb6a
add test coverage, for insert before ptenv
hjgraca Sep 19, 2025
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
18 changes: 18 additions & 0 deletions libraries/AWS.Lambda.Powertools.sln
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AWS.Lambda.Powertools.Kafka
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AWS.Lambda.Powertools.Kafka.Protobuf", "src\AWS.Lambda.Powertools.Kafka.Protobuf\AWS.Lambda.Powertools.Kafka.Protobuf.csproj", "{B640DB80-C982-407B-A2EC-CD29AC77DDB8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AWS.Lambda.Powertools.ModuleInitializer.Tests", "tests\AWS.Lambda.Powertools.ModuleInitializer.Tests\AWS.Lambda.Powertools.ModuleInitializer.Tests.csproj", "{E1F2A3B4-C5D6-7E8F-9A0B-1C2D3E4F5A6B}"
EndProject

Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -688,6 +691,19 @@ Global
{B640DB80-C982-407B-A2EC-CD29AC77DDB8}.Release|x64.Build.0 = Release|Any CPU
{B640DB80-C982-407B-A2EC-CD29AC77DDB8}.Release|x86.ActiveCfg = Release|Any CPU
{B640DB80-C982-407B-A2EC-CD29AC77DDB8}.Release|x86.Build.0 = Release|Any CPU
{E1F2A3B4-C5D6-7E8F-9A0B-1C2D3E4F5A6B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E1F2A3B4-C5D6-7E8F-9A0B-1C2D3E4F5A6B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E1F2A3B4-C5D6-7E8F-9A0B-1C2D3E4F5A6B}.Debug|x64.ActiveCfg = Debug|Any CPU
{E1F2A3B4-C5D6-7E8F-9A0B-1C2D3E4F5A6B}.Debug|x64.Build.0 = Debug|Any CPU
{E1F2A3B4-C5D6-7E8F-9A0B-1C2D3E4F5A6B}.Debug|x86.ActiveCfg = Debug|Any CPU
{E1F2A3B4-C5D6-7E8F-9A0B-1C2D3E4F5A6B}.Debug|x86.Build.0 = Debug|Any CPU
{E1F2A3B4-C5D6-7E8F-9A0B-1C2D3E4F5A6B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E1F2A3B4-C5D6-7E8F-9A0B-1C2D3E4F5A6B}.Release|Any CPU.Build.0 = Release|Any CPU
{E1F2A3B4-C5D6-7E8F-9A0B-1C2D3E4F5A6B}.Release|x64.ActiveCfg = Release|Any CPU
{E1F2A3B4-C5D6-7E8F-9A0B-1C2D3E4F5A6B}.Release|x64.Build.0 = Release|Any CPU
{E1F2A3B4-C5D6-7E8F-9A0B-1C2D3E4F5A6B}.Release|x86.ActiveCfg = Release|Any CPU
{E1F2A3B4-C5D6-7E8F-9A0B-1C2D3E4F5A6B}.Release|x86.Build.0 = Release|Any CPU

EndGlobalSection

GlobalSection(NestedProjects) = preSolution
Expand Down Expand Up @@ -746,5 +762,7 @@ Global
{25F0929B-2E04-4ED6-A0ED-5379A0A755B0} = {73C9B1E5-3893-47E8-B373-17E5F5D7E6F5}
{9E2B8160-3E76-4B33-86AB-DE35A5FCDB1E} = {73C9B1E5-3893-47E8-B373-17E5F5D7E6F5}
{B640DB80-C982-407B-A2EC-CD29AC77DDB8} = {73C9B1E5-3893-47E8-B373-17E5F5D7E6F5}
{E1F2A3B4-C5D6-7E8F-9A0B-1C2D3E4F5A6B} = {1CFF5568-8486-475F-81F6-06105C437528}

EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,10 @@
<PackageReference Include="Amazon.Lambda.SQSEvents" />
<ProjectReference Include="..\AWS.Lambda.Powertools.Common\AWS.Lambda.Powertools.Common.csproj" Condition="'$(Configuration)'=='Debug'"/>
</ItemGroup>

<!-- Include MSBuild targets in the NuGet package -->
<ItemGroup>
<None Include="build\AWS.Lambda.Powertools.BatchProcessing.targets" Pack="true" PackagePath="build\AWS.Lambda.Powertools.BatchProcessing.targets" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Threading;
using System.Threading.Tasks;
using AWS.Lambda.Powertools.BatchProcessing.Exceptions;
using AWS.Lambda.Powertools.Common;

namespace AWS.Lambda.Powertools.BatchProcessing;

Expand All @@ -16,14 +15,6 @@ namespace AWS.Lambda.Powertools.BatchProcessing;
/// <typeparam name="TRecord">Type of batch record.</typeparam>
public abstract class BatchProcessor<TEvent, TRecord> : IBatchProcessor<TEvent, TRecord>
{
/// <summary>
/// Default constructor
/// </summary>
protected BatchProcessor(IPowertoolsConfigurations powertoolsConfigurations)
{
powertoolsConfigurations.SetExecutionEnvironment(this);
}

/// <inheritdoc />
public ProcessingResult<TRecord> ProcessingResult { get; protected set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

using System.Collections.Generic;
using Amazon.Lambda.DynamoDBEvents;
using AWS.Lambda.Powertools.Common;

namespace AWS.Lambda.Powertools.BatchProcessing.DynamoDb;

Expand All @@ -20,23 +19,16 @@ public class DynamoDbStreamBatchProcessor : BatchProcessor<DynamoDBEvent, Dynamo
/// The singleton instance of the batch processor.
/// </summary>
public static IDynamoDbStreamBatchProcessor Instance =>
_instance ??= new DynamoDbStreamBatchProcessor(PowertoolsConfigurations.Instance);
_instance ??= new DynamoDbStreamBatchProcessor();


/// <summary>
/// This is the default constructor
/// </summary>
/// <param name="powertoolsConfigurations"></param>
public DynamoDbStreamBatchProcessor(IPowertoolsConfigurations powertoolsConfigurations) : base(powertoolsConfigurations)
{
_instance = this;
}

/// <summary>
/// Need default constructor for when consumers create a custom batch processor
/// </summary>
// ReSharper disable once MemberCanBePrivate.Global
protected DynamoDbStreamBatchProcessor() : this(PowertoolsConfigurations.Instance)
protected DynamoDbStreamBatchProcessor()
{
_instance = this;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using Amazon.Lambda.DynamoDBEvents;
using AWS.Lambda.Powertools.BatchProcessing.Exceptions;
using AWS.Lambda.Powertools.BatchProcessing.Internal;
using AWS.Lambda.Powertools.Common;

namespace AWS.Lambda.Powertools.BatchProcessing.DynamoDb;

Expand All @@ -20,30 +19,18 @@ public class TypedDynamoDbStreamBatchProcessor : DynamoDbStreamBatchProcessor, I
private readonly IRecordDataExtractor<DynamoDBEvent.DynamodbStreamRecord> _recordDataExtractor;



/// <summary>
/// Initializes a new instance of the TypedDynamoDbStreamBatchProcessor class.
/// </summary>
/// <param name="powertoolsConfigurations">The Powertools configurations.</param>
/// <param name="deserializationService">The deserialization service. If null, uses JsonDeserializationService.Instance.</param>
/// <param name="recordDataExtractor">The record data extractor. If null, uses DynamoDbRecordDataExtractor.Instance.</param>
public TypedDynamoDbStreamBatchProcessor(
IPowertoolsConfigurations powertoolsConfigurations,
IDeserializationService deserializationService = null,
public TypedDynamoDbStreamBatchProcessor(IDeserializationService deserializationService = null,
IRecordDataExtractor<DynamoDBEvent.DynamodbStreamRecord> recordDataExtractor = null)
: base(powertoolsConfigurations)
{
_deserializationService = deserializationService ?? JsonDeserializationService.Instance;
_recordDataExtractor = recordDataExtractor ?? DynamoDbRecordDataExtractor.Instance;
}

/// <summary>
/// Default constructor for when consumers create a custom typed batch processor.
/// </summary>
protected TypedDynamoDbStreamBatchProcessor() : this(PowertoolsConfigurations.Instance)
{
}

/// <inheritdoc />
public async Task<ProcessingResult<DynamoDBEvent.DynamodbStreamRecord>> ProcessAsync<T>(
DynamoDBEvent @event,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using AWS.Lambda.Powertools.Common;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Each project has an eventwrapper class

namespace AWS.Lambda.Powertools.BatchProcessing.Internal
{
/// <summary>
/// Wrapper class to set the execution environment
/// </summary>
public static class EnvWrapper
{
/// <summary>
/// Sets the execution environment
/// </summary>
public static void SetExecutionEnvironment()
{
PowertoolsEnvironment.Instance.SetExecutionEnvironment(typeof(EnvWrapper));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Collections.Generic;
using Amazon.Lambda.KinesisEvents;
using AWS.Lambda.Powertools.Common;

namespace AWS.Lambda.Powertools.BatchProcessing.Kinesis;

Expand All @@ -18,25 +17,16 @@ public class KinesisEventBatchProcessor : BatchProcessor<KinesisEvent, KinesisEv
/// The singleton instance of the batch processor.
/// </summary>
public static IKinesisEventBatchProcessor Instance =>
_instance ??= new KinesisEventBatchProcessor(PowertoolsConfigurations.Instance);

/// <summary>
/// This is the default constructor
/// </summary>
/// <param name="powertoolsConfigurations"></param>
public KinesisEventBatchProcessor(IPowertoolsConfigurations powertoolsConfigurations) : base(powertoolsConfigurations)
{
_instance = this;
}
_instance ??= new KinesisEventBatchProcessor();

/// <summary>
/// Need default constructor for when consumers create a custom batch processor
/// </summary>
// ReSharper disable once MemberCanBePrivate.Global
protected KinesisEventBatchProcessor() : this(PowertoolsConfigurations.Instance)
protected KinesisEventBatchProcessor()
{
_instance = this;
}

/// <summary>
/// Return the instance ProcessingResult
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using Amazon.Lambda.KinesisEvents;
using AWS.Lambda.Powertools.BatchProcessing.Exceptions;
using AWS.Lambda.Powertools.BatchProcessing.Internal;
using AWS.Lambda.Powertools.Common;

namespace AWS.Lambda.Powertools.BatchProcessing.Kinesis;

Expand All @@ -20,30 +19,18 @@ public class TypedKinesisEventBatchProcessor : KinesisEventBatchProcessor, IType
private readonly IRecordDataExtractor<KinesisEvent.KinesisEventRecord> _recordDataExtractor;



/// <summary>
/// Initializes a new instance of the TypedKinesisEventBatchProcessor class.
/// </summary>
/// <param name="powertoolsConfigurations">The Powertools configurations.</param>
/// <param name="deserializationService">The deserialization service. If null, uses JsonDeserializationService.Instance.</param>
/// <param name="recordDataExtractor">The record data extractor. If null, uses KinesisRecordDataExtractor.Instance.</param>
public TypedKinesisEventBatchProcessor(
IPowertoolsConfigurations powertoolsConfigurations,
IDeserializationService deserializationService = null,
public TypedKinesisEventBatchProcessor(IDeserializationService deserializationService = null,
IRecordDataExtractor<KinesisEvent.KinesisEventRecord> recordDataExtractor = null)
: base(powertoolsConfigurations)
{
_deserializationService = deserializationService ?? JsonDeserializationService.Instance;
_recordDataExtractor = recordDataExtractor ?? KinesisRecordDataExtractor.Instance;
}

/// <summary>
/// Default constructor for when consumers create a custom typed batch processor.
/// </summary>
protected TypedKinesisEventBatchProcessor() : this(PowertoolsConfigurations.Instance)
{
}

/// <inheritdoc />
public async Task<ProcessingResult<KinesisEvent.KinesisEventRecord>> ProcessAsync<T>(
KinesisEvent @event,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Linq;
using Amazon.Lambda.SQSEvents;
using AWS.Lambda.Powertools.Common;

namespace AWS.Lambda.Powertools.BatchProcessing.Sqs;

Expand All @@ -20,22 +19,14 @@ public class SqsBatchProcessor : BatchProcessor<SQSEvent, SQSEvent.SQSMessage>,
/// Gets the instance.
/// </summary>
/// <value>The instance.</value>
public static ISqsBatchProcessor Instance => _instance ??= new SqsBatchProcessor(PowertoolsConfigurations.Instance);

/// <summary>
/// This is the default constructor
/// </summary>
/// <param name="powertoolsConfigurations"></param>
public SqsBatchProcessor(IPowertoolsConfigurations powertoolsConfigurations) : base(powertoolsConfigurations)
{
_instance = this;
}

public static ISqsBatchProcessor Instance => _instance ??= new SqsBatchProcessor();

/// <summary>
/// Need default constructor for when consumers create a custom batch processor
/// </summary>
protected SqsBatchProcessor() : this(PowertoolsConfigurations.Instance)
public SqsBatchProcessor()
{
_instance = this;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using Amazon.Lambda.SQSEvents;
using AWS.Lambda.Powertools.BatchProcessing.Exceptions;
using AWS.Lambda.Powertools.BatchProcessing.Internal;
using AWS.Lambda.Powertools.Common;

namespace AWS.Lambda.Powertools.BatchProcessing.Sqs;

Expand All @@ -20,30 +19,18 @@ public class TypedSqsBatchProcessor : SqsBatchProcessor, ITypedBatchProcessor<SQ
private readonly IRecordDataExtractor<SQSEvent.SQSMessage> _recordDataExtractor;



/// <summary>
/// Initializes a new instance of the TypedSqsBatchProcessor class.
/// </summary>
/// <param name="powertoolsConfigurations">The Powertools configurations.</param>
/// <param name="deserializationService">The deserialization service. If null, uses JsonDeserializationService.Instance.</param>
/// <param name="recordDataExtractor">The record data extractor. If null, uses SqsRecordDataExtractor.Instance.</param>
public TypedSqsBatchProcessor(
IPowertoolsConfigurations powertoolsConfigurations,
IDeserializationService deserializationService = null,
public TypedSqsBatchProcessor(IDeserializationService deserializationService = null,
IRecordDataExtractor<SQSEvent.SQSMessage> recordDataExtractor = null)
: base(powertoolsConfigurations)
{
_deserializationService = deserializationService ?? JsonDeserializationService.Instance;
_recordDataExtractor = recordDataExtractor ?? SqsRecordDataExtractor.Instance;
}

/// <summary>
/// Default constructor for when consumers create a custom typed batch processor.
/// </summary>
protected TypedSqsBatchProcessor() : this(PowertoolsConfigurations.Instance)
{
}

/// <inheritdoc />
public async Task<ProcessingResult<SQSEvent.SQSMessage>> ProcessAsync<T>(
SQSEvent @event,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<Project>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Each project with have a targets file - this file is executed by MsBuild, the builder and compiled with the code that references our Nuget packages, making it possible to run this on adding Powertools nuget to a project


<!-- Automatically inject a module initializer for the BatchProcessing library -->
<Target Name="InjectBatchProcessingAutoInitializer" BeforeTargets="BeforeCompile">

<!-- Generate the C# content directly -->
<PropertyGroup>
<GeneratedFileContent>// Generated by AWS Lambda Powertools Auto-Initializer
using System.Runtime.CompilerServices%3B

internal static class PowertoolsBatchProcessingAutoInitializer
{
[ModuleInitializer]
internal static void Initialize()
{
try
{
// Force load the Powertools assembly by calling its initialization method
AWS.Lambda.Powertools.BatchProcessing.Internal.EnvWrapper.SetExecutionEnvironment()%3B
}
catch
{
// Ignore errors - the assembly might not be available in all scenarios
}
}
}</GeneratedFileContent>
</PropertyGroup>

<!-- Write the generated file -->
<WriteLinesToFile
File="$(IntermediateOutputPath)PowertoolsBatchProcessingAutoInitializer.g.cs"
Lines="$(GeneratedFileContent)"
Overwrite="true" />

<!-- Include the generated file in compilation -->
<ItemGroup>
<Compile Include="$(IntermediateOutputPath)PowertoolsBatchProcessingAutoInitializer.g.cs" />
</ItemGroup>

</Target>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@

<PropertyGroup>
<!-- Remaining properties are defined in Directory.Build.props -->
<PackageId>AWS.Lambda.Powertools.Common</PackageId>
<Description>Powertools for AWS Lambda (.NET) - Core package.</Description>
<AssemblyName>AWS.Lambda.Powertools.Common</AssemblyName>
<RootNamespace>AWS.Lambda.Powertools.Common</RootNamespace>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<PackageId>AWS.Lambda.Powertools.Common</PackageId>
<Description>Powertools for AWS Lambda (.NET) - Core package.</Description>
<AssemblyName>AWS.Lambda.Powertools.Common</AssemblyName>
<RootNamespace>AWS.Lambda.Powertools.Common</RootNamespace>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
</PropertyGroup>

<ItemGroup>
<!-- Package versions are Centrally managed in Directory.Packages.props file -->
<!-- More info https://learn.microsoft.com/en-us/nuget/consume-packages/central-package-management -->
<!-- Package versions are Centrally managed in Directory.Packages.props file -->
<!-- More info https://learn.microsoft.com/en-us/nuget/consume-packages/central-package-management -->
<PackageReference Include="Amazon.Lambda.Core"/>
<PackageReference Include="AspectInjector"/>
</ItemGroup>

</Project>
Loading
Loading