Skip to content

Commit f7f7a22

Browse files
authored
Merge pull request #637 from aws-powertools/develop
chore: Sync Main with Develop release 1.13
2 parents 0d0e5c9 + 04cbc46 commit f7f7a22

File tree

12 files changed

+227
-58
lines changed

12 files changed

+227
-58
lines changed

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ Not using .NET? No problem, we have you covered. Here are the other members of t
8585

8686
Knowing which companies are using this library is important to help prioritize the project internally. If your company is using Powertools for AWS Lambda (.NET), you can request to have your name and logo added to the README file by raising a [Support Powertools for AWS Lambda (.NET) (become a reference)](https://github.com/aws-powertools/powertools-lambda-dotnet/issues/new?assignees=&labels=customer-reference&template=support_powertools.yml&title=%5BSupport+Lambda+Powertools%5D%3A+%3Cyour+organization+name%3E) issue.
8787

88+
The following companies, among others, use Powertools:
89+
90+
* [Caylent](https://caylent.com/)
91+
* [Pushpay](https://pushpay.com/)
92+
8893
### Sharing your work
8994

9095
Share what you did with Powertools for AWS Lambda (.NET) 💞💞. Blog post, workshops, presentation, sample apps and others. Check out what the community has already shared about Powertools for AWS Lambda (.NET) [here](https://docs.powertools.aws.dev/lambda/dotnet/we_made_this/).

docs/core/tracing.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ These improvements offer the potential to eliminate build-time trimming warnings
287287

288288
For the Tracing utility to work correctly and without trim warnings please add the following to your `.csproj` file
289289

290-
```xaml
290+
```xml
291291
<ItemGroup>
292292
<TrimmerRootAssembly Include="AWSSDK.Core" />
293293
<TrimmerRootAssembly Include="AWSXRayRecorder.Core" />
@@ -298,4 +298,4 @@ For the Tracing utility to work correctly and without trim warnings please add t
298298

299299
Note that when you receive a trim warning, adding the class that generates the warning to TrimmerRootAssembly might not resolve the issue. A trim warning indicates that the class is trying to access some other class that can't be determined until runtime. To avoid runtime errors, add this second class to TrimmerRootAssembly.
300300

301-
To learn more about managing trim warnings, see [Introduction to trim warnings](https://learn.microsoft.com/en-us/dotnet/core/deploying/trimming/fixing-warnings) in the Microsoft .NET documentation.
301+
To learn more about managing trim warnings, see [Introduction to trim warnings](https://learn.microsoft.com/en-us/dotnet/core/deploying/trimming/fixing-warnings) in the Microsoft .NET documentation.

docs/index.md

+45-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,51 @@ We have provided a few examples that should you how to use the each of the core
120120
## Connect
121121

122122
* **Powertools for AWS Lambda (.NET) on Discord**: `#dotnet` - **[Invite link](https://discord.gg/B8zZKbbyET){target="_blank"}**
123-
* **Email**: [email protected]
123+
* **Email**: [email protected]
124+
125+
## Support Powertools for AWS Lambda (.NET)
126+
127+
There are many ways you can help us gain future investments to improve everyone's experience:
128+
129+
<div class="grid cards" markdown>
130+
131+
- :heart:{ .lg .middle } __Become a public reference__
132+
133+
---
134+
135+
Add your company name and logo on our [landing page](https://powertools.aws.dev).
136+
137+
[:octicons-arrow-right-24: GitHub Issue template](https://github.com/aws-powertools/powertools-lambda-dotnet/issues/new?assignees=&labels=customer-reference&template=support_powertools.yml&title=%5BSupport+Lambda+Powertools%5D%3A+%3Cyour+organization+name%3E){target="_blank"}
138+
139+
- :mega:{ .lg .middle } __Share your work__
140+
141+
---
142+
143+
Blog posts, video, and sample projects about Powertools for AWS Lambda.
144+
145+
[:octicons-arrow-right-24: GitHub Issue template](https://github.com/aws-powertools/powertools-lambda-dotnet/issues/new?assignees=&labels=customer-reference&template=support_powertools.yml&title=%5BSupport+Lambda+Powertools%5D%3A+%3Cyour+organization+name%3E){target="_blank"}
146+
147+
- :partying_face:{ .lg .middle } __Join the community__
148+
149+
---
150+
151+
Connect, ask questions, and share what features you use.
152+
153+
[:octicons-arrow-right-24: Discord invite](https://discord.gg/B8zZKbbyET){target="blank"}
154+
155+
</div>
156+
157+
### Becoming a reference customer
158+
159+
Knowing which companies are using this library is important to help prioritize the project internally. The following companies, among others, use Powertools:
160+
161+
<div class="grid" style="text-align:center;" markdown>
162+
163+
[**Caylent**](https://caylent.com/){target="_blank" rel="nofollow"}
164+
{ .card }
165+
166+
[**Pushpay**](https://pushpay.com/){target="_blank" rel="nofollow"}
167+
{ .card }
124168
125169
## Tenets
126170

libraries/src/AWS.Lambda.Powertools.BatchProcessing/RecordHandlerResult.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class RecordHandlerResult
2323
/// <summary>
2424
/// Returns an empty <see cref="RecordHandlerResult"/> value.
2525
/// </summary>
26-
public static readonly RecordHandlerResult None = new();
26+
public static RecordHandlerResult None { get; } = null!;
2727

2828
/// <summary>
2929
/// Convenience method for the creation of a <see cref="RecordHandlerResult"/>.

libraries/src/AWS.Lambda.Powertools.Tracing/Internal/TracingAspect.cs

+30-32
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
using System;
1717
using System.Linq;
18-
using System.Reflection;
1918
using System.Runtime.ExceptionServices;
2019
using System.Text;
2120
using AspectInjector.Broker;
@@ -39,7 +38,7 @@ public class TracingAspect
3938
/// X-Ray Recorder
4039
/// </summary>
4140
private readonly IXRayRecorder _xRayRecorder;
42-
41+
4342
/// <summary>
4443
/// If true, then is cold start
4544
/// </summary>
@@ -49,17 +48,17 @@ public class TracingAspect
4948
/// If true, capture annotations
5049
/// </summary>
5150
private static bool _captureAnnotations = true;
52-
51+
5352
/// <summary>
5453
/// If true, annotations have been captured
5554
/// </summary>
5655
private bool _isAnnotationsCaptured;
57-
56+
5857
/// <summary>
5958
/// Tracing namespace
6059
/// </summary>
6160
private string _namespace;
62-
61+
6362
/// <summary>
6463
/// The capture mode
6564
/// </summary>
@@ -73,18 +72,14 @@ public TracingAspect()
7372
_xRayRecorder = XRayRecorder.Instance;
7473
_powertoolsConfigurations = PowertoolsConfigurations.Instance;
7574
}
76-
75+
7776
/// <summary>
7877
/// the code is executed instead of the target method.
7978
/// The call to original method is wrapped around the following code
8079
/// the original code is called with var result = target(args);
8180
/// </summary>
82-
/// <param name="instance"></param>
8381
/// <param name="name"></param>
8482
/// <param name="args"></param>
85-
/// <param name="hostType"></param>
86-
/// <param name="method"></param>
87-
/// <param name="returnType"></param>
8883
/// <param name="target"></param>
8984
/// <param name="triggers"></param>
9085
/// <returns></returns>
@@ -97,38 +92,39 @@ public object Around(
9792
{
9893
// Before running Function
9994

95+
var trigger = triggers.OfType<TracingAttribute>().First();
10096
try
10197
{
102-
var trigger = triggers.OfType<TracingAttribute>().First();
103-
104-
if(TracingDisabled())
98+
if (TracingDisabled())
10599
return target(args);
106100

107101
_namespace = trigger.Namespace;
108-
_captureMode = trigger.CaptureMode;
109-
102+
110103
var segmentName = !string.IsNullOrWhiteSpace(trigger.SegmentName) ? trigger.SegmentName : $"## {name}";
111104
var nameSpace = GetNamespace();
112105

113106
_xRayRecorder.BeginSubsegment(segmentName);
114107
_xRayRecorder.SetNamespace(nameSpace);
115108

116-
if (_captureAnnotations)
109+
if (_captureAnnotations)
117110
{
118111
_xRayRecorder.AddAnnotation("ColdStart", _isColdStart);
119-
112+
120113
_captureAnnotations = false;
121114
_isAnnotationsCaptured = true;
122115

123116
if (_powertoolsConfigurations.IsServiceDefined)
124117
_xRayRecorder.AddAnnotation("Service", _powertoolsConfigurations.Service);
125118
}
126-
119+
127120
_isColdStart = false;
128-
121+
129122
// return of the handler
130123
var result = target(args);
131-
124+
125+
// must get capture after all subsegments run
126+
_captureMode = trigger.CaptureMode;
127+
132128
if (CaptureResponse())
133129
{
134130
_xRayRecorder.AddMetadata
@@ -138,12 +134,13 @@ public object Around(
138134
result
139135
);
140136
}
141-
137+
142138
// after
143139
return result;
144140
}
145141
catch (Exception e)
146142
{
143+
_captureMode = trigger.CaptureMode;
147144
HandleException(e, name);
148145
throw;
149146
}
@@ -153,16 +150,17 @@ public object Around(
153150
/// the code is injected after the method ends.
154151
/// </summary>
155152
[Advice(Kind.After)]
156-
public void OnExit() {
157-
if(TracingDisabled())
153+
public void OnExit()
154+
{
155+
if (TracingDisabled())
158156
return;
159157

160158
if (_isAnnotationsCaptured)
161159
_captureAnnotations = true;
162160

163161
_xRayRecorder.EndSubsegment();
164162
}
165-
163+
166164
/// <summary>
167165
/// Code that handles when exceptions occur in the client method
168166
/// </summary>
@@ -173,7 +171,7 @@ private void HandleException(Exception exception, string name)
173171
if (CaptureError())
174172
{
175173
var nameSpace = GetNamespace();
176-
174+
177175
var sb = new StringBuilder();
178176
sb.AppendLine($"Exception type: {exception.GetType()}");
179177
sb.AppendLine($"Exception message: {exception.Message}");
@@ -187,7 +185,7 @@ private void HandleException(Exception exception, string name)
187185
sb.AppendLine($"Stack trace: {exception.InnerException.StackTrace}");
188186
sb.AppendLine("---END Inner Exception");
189187
}
190-
188+
191189
_xRayRecorder.AddMetadata
192190
(
193191
nameSpace,
@@ -209,7 +207,7 @@ private string GetNamespace()
209207
{
210208
return !string.IsNullOrWhiteSpace(_namespace) ? _namespace : _powertoolsConfigurations.Service;
211209
}
212-
210+
213211
/// <summary>
214212
/// Method that checks if tracing is disabled
215213
/// </summary>
@@ -230,7 +228,7 @@ private bool TracingDisabled()
230228

231229
return false;
232230
}
233-
231+
234232
/// <summary>
235233
/// Captures the response.
236234
/// </summary>
@@ -250,16 +248,16 @@ private bool CaptureResponse()
250248
return false;
251249
}
252250
}
253-
251+
254252
/// <summary>
255253
/// Captures the error.
256254
/// </summary>
257255
/// <returns><c>true</c> if tracing should capture errors, <c>false</c> otherwise.</returns>
258256
private bool CaptureError()
259257
{
260-
if(TracingDisabled())
258+
if (TracingDisabled())
261259
return false;
262-
260+
263261
switch (_captureMode)
264262
{
265263
case TracingCaptureMode.EnvironmentVariable:
@@ -273,7 +271,7 @@ private bool CaptureError()
273271
return false;
274272
}
275273
}
276-
274+
277275
/// <summary>
278276
/// Resets static variables for test.
279277
/// </summary>

libraries/src/AWS.Lambda.Powertools.Tracing/Internal/XRayRecorder.cs

+24-7
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
@@ -41,7 +41,8 @@ internal class XRayRecorder : IXRayRecorder
4141
/// Gets the instance.
4242
/// </summary>
4343
/// <value>The instance.</value>
44-
public static IXRayRecorder Instance => _instance ??= new XRayRecorder(AWSXRayRecorder.Instance, PowertoolsConfigurations.Instance);
44+
public static IXRayRecorder Instance =>
45+
_instance ??= new XRayRecorder(AWSXRayRecorder.Instance, PowertoolsConfigurations.Instance);
4546

4647
public XRayRecorder(IAWSXRayRecorder awsxRayRecorder, IPowertoolsConfigurations powertoolsConfigurations)
4748
{
@@ -56,7 +57,7 @@ public XRayRecorder(IAWSXRayRecorder awsxRayRecorder, IPowertoolsConfigurations
5657
/// Checks whether current execution is in AWS Lambda.
5758
/// </summary>
5859
/// <returns>Returns true if current execution is in AWS Lambda.</returns>
59-
private static bool _isLambda;
60+
private static bool _isLambda;
6061

6162
/// <summary>
6263
/// Gets the emitter.
@@ -112,14 +113,30 @@ public void AddMetadata(string nameSpace, string key, object value)
112113
if (_isLambda)
113114
_awsxRayRecorder.AddMetadata(nameSpace, key, value);
114115
}
115-
116+
116117
/// <summary>
117118
/// Ends the subsegment.
118119
/// </summary>
119120
public void EndSubsegment()
120121
{
121-
if (_isLambda)
122+
if (!_isLambda) return;
123+
try
124+
{
125+
_awsxRayRecorder.EndSubsegment();
126+
}
127+
catch (Exception e)
128+
{
129+
// if it fails at this stage the data is lost
130+
// so lets create a new subsegment with the error
131+
132+
Console.WriteLine("Error in Tracing utility - see Exceptions tab in Cloudwatch Traces");
133+
134+
_awsxRayRecorder.TraceContext.ClearEntity();
135+
_awsxRayRecorder.BeginSubsegment("Error in Tracing utility - see Exceptions tab");
136+
_awsxRayRecorder.AddException(e);
137+
_awsxRayRecorder.MarkError();
122138
_awsxRayRecorder.EndSubsegment();
139+
}
123140
}
124141

125142
/// <summary>

libraries/src/Directory.Build.targets

-11
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,4 @@
1212
<Compile Remove="..\AWS.Lambda.Powertools.Common\obj\**" />
1313
</ItemGroup>
1414

15-
16-
<ItemGroup Condition="'$(MSBuildProjectName)' == 'AWS.Lambda.Powertools.Idempotency' AND '$(Configuration)'=='Release'">
17-
18-
<ProjectReference Remove="..\AWS.Lambda.Powertools.JMESPath\AWS.Lambda.Powertools.JMESPath.csproj" />
19-
20-
<Compile Include="..\AWS.Lambda.Powertools.JMESPath\**\*.cs">
21-
<Link>JMESPath\%(RecursiveDir)%(Filename)%(Extension)</Link>
22-
</Compile>
23-
<Compile Remove="..\AWS.Lambda.Powertools.JMESPath\obj\**" />
24-
</ItemGroup>
25-
2615
</Project>

0 commit comments

Comments
 (0)