Skip to content

Commit 2e7b4fa

Browse files
author
Mark Kuhn
committed
add documentation comments
add exceptions to readme
1 parent df44f05 commit 2e7b4fa

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ The `MetricsLogger` is the interface you will use to publish embedded metrics.
162162

163163
Adds a new metric to the current logger context. Multiple metrics using the same key will be appended to an array of values. The Embedded Metric Format supports a maxumum of 100 metrics per key.
164164

165-
Units must meet CloudWatch Metrics unit requirements, if not it will default to None. See [MetricDatum](https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_MetricDatum.html) for valid values.
165+
Units must meet CloudWatch Metrics unit requirements, otherwise it will throw a `InvalidMetricException`. See [MetricDatum](https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_MetricDatum.html) for valid values.
166166

167167
Example:
168168

@@ -196,7 +196,7 @@ Adds a new set of dimensions that will be associated with all metric values.
196196
If the cardinality of a particular value is expected to be high, you should consider
197197
using `setProperty` instead.
198198

199-
Dimensions must meet CloudWatch Dimensions requirements. See [Dimensions](https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_Dimension.html) for valid values.
199+
Dimensions must meet CloudWatch Dimensions requirements, otherwise it will throw a `InvalidDimensionException`. See [Dimensions](https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_Dimension.html) for valid values.
200200

201201
Example:
202202

@@ -216,7 +216,7 @@ Explicitly override all dimensions. This will remove the default dimensions unle
216216
If the cardinality of a particular value is expected to be high, you should consider
217217
using `setProperty` instead.
218218

219-
Dimensions must meet CloudWatch Dimensions requirements. See [Dimensions](https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_Dimension.html) for valid values.
219+
Dimensions must meet CloudWatch Dimensions requirements, otherwise it will throw a `InvalidDimensionException`. See [Dimensions](https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_Dimension.html) for valid values.
220220

221221
Examples:
222222

@@ -241,6 +241,7 @@ Explicitly clear all custom dimensions. Set `useDefault` to `true` to keep using
241241
- MetricsLogger **SetNamespace**(string logNamespace)
242242

243243
Sets the CloudWatch [namespace](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/cloudwatch_concepts.html#Namespace) that extracted metrics should be published to. If not set, a default value of aws-embedded-metrics will be used.
244+
Namespaces must meet CloudWatch Namespace requirements, otherwise it will throw a `InvalidNamespaceException`. See [Namespace](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/cloudwatch_concepts.html#Namespace) for valid values.
244245

245246
Example:
246247

src/Amazon.CloudWatch.EMF/Utils/Validator.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ namespace Amazon.CloudWatch.EMF.Utils
55
{
66
public class Validator
77
{
8+
/// <summary>
9+
/// Validates dimension set.
10+
/// </summary>
11+
/// <param name="dimensionName">Dimension name</param>
12+
/// <param name="dimensionValue">Dimension value</param>
13+
/// <exception cref="InvalidDimensionException">Thrown when dimension name or value is invalid</exception>
814
internal static void ValidateDimensionSet(in string dimensionName, in string dimensionValue)
915
{
1016
if (dimensionName == null || dimensionName.Trim().Length == 0)
@@ -43,6 +49,12 @@ internal static void ValidateDimensionSet(in string dimensionName, in string dim
4349
}
4450
}
4551

52+
/// <summary>
53+
/// Validates metric name.
54+
/// </summary>
55+
/// <param name="name">Metric name</param>
56+
/// <param name="value">Metric value</param>
57+
/// <exception cref="InvalidMetricException">Thrown when metric name or value is invalid</exception>
4658
internal static void ValidateMetric(in string name, in double value)
4759
{
4860
if (name == null || name.Trim().Length == 0)
@@ -61,6 +73,11 @@ internal static void ValidateMetric(in string name, in double value)
6173
}
6274
}
6375

76+
/// <summary>
77+
/// Validates namespace.
78+
/// </summary>
79+
/// <param name="@namespace">Namespace</param>
80+
/// <exception cref="InvalidNamespaceException">Thrown when namespace is invalid</exception>
6481
internal static void ValidateNamespace(in string @namespace)
6582
{
6683
if (@namespace == null || @namespace.Trim().Length == 0)
@@ -79,6 +96,11 @@ internal static void ValidateNamespace(in string @namespace)
7996
}
8097
}
8198

99+
/// <summary>
100+
/// Checks if given string is only ASCII.
101+
/// </summary>
102+
/// <param name="str">String to check</param>
103+
/// <returns>True if string is only ASCII, false otherwise</returns>
82104
private static bool IsAscii(in string str)
83105
{
84106
return Encoding.UTF8.GetByteCount(str) == str.Length;

0 commit comments

Comments
 (0)