Skip to content

Commit de41f7c

Browse files
authored
Merge branch 'develop' into url-updates
Signed-off-by: Henrique Graca <[email protected]>
2 parents 5aa5598 + f6caa32 commit de41f7c

File tree

3 files changed

+85
-12
lines changed

3 files changed

+85
-12
lines changed

README.md

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@
22

33
![aws provider](https://img.shields.io/badge/provider-AWS-orange?logo=amazon-aws&color=ff9900)
44
[![Build](https://github.com/aws-powertools/powertools-lambda-dotnet/actions/workflows/build.yml/badge.svg?branch=develop)](https://github.com/aws-powertools/powertools-lambda-dotnet/actions/workflows/build.yml)
5+
[![codecov.io](https://codecov.io/github/aws-powertools/powertools-lambda-dotnet/branch/develop/graphs/badge.svg)](https://app.codecov.io/gh/aws-powertools/powertools-lambda-dotnet)
6+
[![dotnet support](https://img.shields.io/static/v1?label=dotnet&message=%20NET6.0&color=blue?style=flat-square&logo=dotnet)](https://dotnet.microsoft.com/en-us/download/dotnet/6.0)
7+
[![NuGet Downloads](https://img.shields.io/nuget/dt/AWS.Lambda.Powertools.Logging.svg)](https://www.nuget.org/packages?q=AWS.Lambda.Powertools)
58
[![Join our Discord](https://dcbadge.vercel.app/api/server/B8zZKbbyET)](https://discord.gg/B8zZKbbyET)
69

7-
Powertools is a developer toolkit to implement Serverless [best practices and increase developer velocity](https://docs.powertools.aws.dev/lambda/dotnet/#features).
10+
Powertools for AWS Lambda (.NET) is a developer toolkit to implement Serverless [best practices and increase developer velocity](https://docs.powertools.aws.dev/lambda-dotnet/#features).
811

9-
**[📜 Documentation](https://docs.powertools.aws.dev/lambda/dotnet/)** | **[NuGet](https://www.nuget.org/)** | **[Roadmap](https://github.com/aws-powertools/powertools-lambda-roadmap/projects/1)** | **[Examples](#examples)**
12+
> Also available in [Java](https://github.com/aws-powertools/powertools-lambda-java), [Typescript](https://github.com/aws-powertools/powertools-lambda-typescript), and [Python](https://github.com/aws-powertools/powertools-lambda-python).
13+
14+
**[📜 Documentation](https://docs.powertools.aws.dev/lambda-dotnet/)** | **[NuGet](https://www.nuget.org/packages?q=AWS.Lambda.Powertools)** | **[Roadmap](https://github.com/orgs/aws-powertools/projects/6)** | **[Examples](#examples)**
1015

1116
> **Join us on the AWS Developers Slack at `#lambda-powertools`** - **[Invite, if you don't have an account](https://join.slack.com/t/awsdevelopers/shared_invite/zt-gu30gquv-EhwIYq3kHhhysaZ2aIX7ew)**
1217
@@ -56,7 +61,6 @@ We have provided examples focused specifically on each of the utilities. Each so
5661
* **[Metrics example](examples/Metrics/)**
5762
* **[Tracing example](examples/Tracing/)**
5863
* **[Serverless API example](examples/ServerlessApi/)**
59-
6064
* **[Parameters example](examples/Parameters/)**
6165
* **[Idempotency example](examples/Idempotency)**
6266

@@ -68,22 +72,36 @@ Not using .NET? No problem, we have you covered. Here are the other members of t
6872
* [Powertools for AWS Lambda (Java)](https://github.com/aws-powertools/powertools-lambda-java)
6973
* [Powertools for AWS Lambda (TypeScript)](https://github.com/aws-powertools/powertools-lambda-typescript)
7074

71-
## Credits
75+
## How to support Powertools for AWS Lambda (.NET)?
7276

73-
* Structured logging initial implementation from [aws-lambda-logging](https://gitlab.com/hadrien/aws_lambda_logging)
74-
* Powertools for AWS Lambda (.NET) idea [DAZN Powertools](https://github.com/getndazn/dazn-lambda-powertools/)
77+
### Becoming a reference customer
78+
79+
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.
80+
81+
### Sharing your work
82+
83+
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/).
7584

76-
## 👋 Contributing
85+
### 👋 Contributing
7786

7887
We welcome contributions from developers of all levels to our open-source project on GitHub. If you'd like to contribute, please check our contributing guidelines and help make this project more accessible.
7988

8089
[![Star History Chart](https://api.star-history.com/svg?repos=aws-powertools/powertools-lambda-dotnet&type=Date)](https://star-history.com/#aws-powertools/powertools-lambda-dotnet&Date)
8190

91+
## Credits
92+
93+
* Structured logging initial implementation from [aws-lambda-logging](https://gitlab.com/hadrien/aws_lambda_logging)
94+
* Powertools for AWS Lambda (.NET) idea [DAZN Powertools](https://github.com/getndazn/dazn-lambda-powertools/)
95+
8296
## Connect
8397

8498
* **Powertools for AWS Lambda on Discord**: `#dotnet` - **[Invite link](https://discord.gg/B8zZKbbyET)**
8599
* **Email**: <[email protected]>
86100

101+
## Security disclosures
102+
103+
If you think you’ve found a potential security issue, please do not post it in the Issues. Instead, please follow the instructions [here](https://aws.amazon.com/security/vulnerability-reporting/) or [email AWS security directly](mailto:[email protected]).
104+
87105
## License
88106

89107
This project is licensed under the Apache-2.0 License.

libraries/src/AWS.Lambda.Powertools.Metrics/Model/MetricDirective.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ public List<List<string>> AllDimensionKeys
126126
return defaultKeys;
127127
}
128128
}
129+
130+
/// <summary>
131+
/// Shared synchronization object
132+
/// </summary>
133+
private readonly object _lockObj = new();
129134

130135
/// <summary>
131136
/// Adds metric to memory
@@ -139,11 +144,14 @@ public void AddMetric(string name, double value, MetricUnit unit, MetricResoluti
139144
{
140145
if (Metrics.Count < PowertoolsConfigurations.MaxMetrics)
141146
{
142-
var metric = Metrics.FirstOrDefault(m => m.Name == name);
143-
if (metric != null)
144-
metric.AddValue(value);
145-
else
146-
Metrics.Add(new MetricDefinition(name, unit, value, metricResolution));
147+
lock (_lockObj)
148+
{
149+
var metric = Metrics.FirstOrDefault(m => m.Name == name);
150+
if (metric != null)
151+
metric.AddValue(value);
152+
else
153+
Metrics.Add(new MetricDefinition(name, unit, value, metricResolution));
154+
}
147155
}
148156
else
149157
{

libraries/tests/AWS.Lambda.Powertools.Metrics.Tests/EMFValidationTests.cs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
using System;
1717
using System.Collections.Generic;
1818
using System.IO;
19+
using System.Threading.Tasks;
1920
using AWS.Lambda.Powertools.Common;
2021
using Moq;
2122
using Xunit;
@@ -642,5 +643,51 @@ private List<int> AllIndexesOf(string str, string value)
642643
}
643644

644645
#endregion
646+
647+
[Fact]
648+
public async Task WhenMetricsAsyncRaceConditionItemSameKeyExists_ValidateLock()
649+
{
650+
// Arrange
651+
var methodName = Guid.NewGuid().ToString();
652+
var consoleOut = new StringWriter();
653+
Console.SetOut(consoleOut);
654+
655+
var configurations = new Mock<IPowertoolsConfigurations>();
656+
657+
var metrics = new Metrics(configurations.Object,
658+
nameSpace: "dotnet-powertools-test",
659+
service: "testService");
660+
661+
var handler = new MetricsAspectHandler(metrics,
662+
false);
663+
664+
var eventArgs = new AspectEventArgs { Name = methodName };
665+
666+
// Act
667+
handler.OnEntry(eventArgs);
668+
669+
var tasks = new List<Task>();
670+
for (var i = 0; i < 100; i++)
671+
{
672+
tasks.Add(Task.Run(() =>
673+
{
674+
Metrics.AddMetric($"Metric Name", 0, MetricUnit.Count);
675+
}));
676+
}
677+
678+
await Task.WhenAll(tasks);
679+
680+
681+
handler.OnExit(eventArgs);
682+
683+
var metricsOutput = consoleOut.ToString();
684+
685+
// Assert
686+
Assert.Contains("{\"Namespace\":\"dotnet-powertools-test\",\"Metrics\":[{\"Name\":\"Metric Name\",\"Unit\":\"Count\"}],\"Dimensions\":[[\"Service\"]]",
687+
metricsOutput);
688+
689+
// Reset
690+
handler.ResetForTest();
691+
}
645692
}
646693
}

0 commit comments

Comments
 (0)