Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions libraries/src/AWS.Lambda.Powertools.Metrics/Metrics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ void IMetrics.AddMetric(string key, double value, MetricUnit unit, MetricResolut
throw new ArgumentNullException(
nameof(key),
"'AddMetric' method requires a valid metrics key. 'Null' or empty values are not allowed.");
if (key.Length > 255)
throw new ArgumentOutOfRangeException(
nameof(key),
"'AddMetric' method requires a valid metrics key. Key exceeds the allowed length constraint.");

if (value < 0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,21 @@ public void When_AddMetric_With_InvalidKey_Should_ThrowArgumentNullException(str
exception.Message);
}

[Fact]
public void When_AddMetric_With_TooLongKey_Should_ThrowArgumentOutOfRangeException()
{
// Arrange
Substitute.For<IMetrics>();
var powertoolsConfigMock = Substitute.For<IPowertoolsConfigurations>();
IMetrics metrics = new Metrics(powertoolsConfigMock);

// Act & Assert
var exception = Assert.Throws<ArgumentOutOfRangeException>(() => metrics.AddMetric("Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem.", 1.0));
Assert.Equal("key", exception.ParamName);
Assert.Contains("'AddMetric' method requires a valid metrics key. Key exceeds the allowed length constraint.",
exception.Message);
}

[Fact]
public void When_SetDefaultDimensions_With_InvalidKeyOrValue_Should_ThrowArgumentNullException()
{
Expand Down
Loading