@@ -45,6 +45,11 @@ public class Metrics : IMetrics
4545 /// If true, Powertools will throw an exception on empty metrics when trying to flush
4646 /// </summary>
4747 private readonly bool _raiseOnEmptyMetrics ;
48+
49+ /// <summary>
50+ /// The capture cold start enabled
51+ /// </summary>
52+ private readonly bool _captureColdStartEnabled ;
4853
4954 /// <summary>
5055 /// Creates a Metrics object that provides features to send metrics to Amazon Cloudwatch using the Embedded metric
@@ -55,14 +60,16 @@ public class Metrics : IMetrics
5560 /// <param name="nameSpace">Metrics Namespace Identifier</param>
5661 /// <param name="service">Metrics Service Name</param>
5762 /// <param name="raiseOnEmptyMetrics">Instructs metrics validation to throw exception if no metrics are provided</param>
63+ /// <param name="captureColdStartEnabled">Instructs metrics capturing the ColdStart is enabled</param>
5864 internal Metrics ( IPowertoolsConfigurations powertoolsConfigurations , string nameSpace = null , string service = null ,
59- bool raiseOnEmptyMetrics = false )
65+ bool raiseOnEmptyMetrics = false , bool captureColdStartEnabled = false )
6066 {
6167 if ( _instance != null ) return ;
6268
6369 _instance = this ;
6470 _powertoolsConfigurations = powertoolsConfigurations ;
6571 _raiseOnEmptyMetrics = raiseOnEmptyMetrics ;
72+ _captureColdStartEnabled = captureColdStartEnabled ;
6673 _context = InitializeContext ( nameSpace , service , null ) ;
6774 }
6875
@@ -80,7 +87,7 @@ void IMetrics.AddMetric(string key, double value, MetricUnit unit)
8087 {
8188 if ( string . IsNullOrWhiteSpace ( key ) )
8289 throw new ArgumentNullException (
83- "'AddMetric' method requires a valid metrics key. 'Null' or empty values are not allowed." ) ;
90+ $ "'AddMetric' method requires a valid metrics key. 'Null' or empty values are not allowed.") ;
8491
8592 if ( value < 0 ) {
8693 throw new ArgumentException (
@@ -132,7 +139,7 @@ void IMetrics.AddDimension(string key, string value)
132139 {
133140 if ( string . IsNullOrWhiteSpace ( key ) )
134141 throw new ArgumentNullException (
135- "'AddDimension' method requires a valid dimension key. 'Null' or empty values are not allowed." ) ;
142+ $ "'AddDimension' method requires a valid dimension key. 'Null' or empty values are not allowed.") ;
136143
137144 _context . AddDimension ( key , value ) ;
138145 }
@@ -150,7 +157,7 @@ void IMetrics.AddMetadata(string key, object value)
150157 {
151158 if ( string . IsNullOrWhiteSpace ( key ) )
152159 throw new ArgumentNullException (
153- "'AddMetadata' method requires a valid metadata key. 'Null' or empty values are not allowed." ) ;
160+ $ "'AddMetadata' method requires a valid metadata key. 'Null' or empty values are not allowed.") ;
154161
155162 _context . AddMetadata ( key , value ) ;
156163 }
@@ -168,7 +175,7 @@ void IMetrics.SetDefaultDimensions(Dictionary<string, string> defaultDimensions)
168175 foreach ( var item in defaultDimensions )
169176 if ( string . IsNullOrWhiteSpace ( item . Key ) || string . IsNullOrWhiteSpace ( item . Value ) )
170177 throw new ArgumentNullException (
171- "'SetDefaultDimensions' method requires a valid key pair. 'Null' or empty values are not allowed." ) ;
178+ $ "'SetDefaultDimensions' method requires a valid key pair. 'Null' or empty values are not allowed.") ;
172179
173180 _context . SetDefaultDimensions ( DictionaryToList ( defaultDimensions ) ) ;
174181 }
@@ -197,8 +204,9 @@ void IMetrics.Flush(bool metricsOverflow)
197204 }
198205 else
199206 {
200- Console . WriteLine (
201- "##WARNING## Metrics and Metadata have not been specified. No data will be sent to Cloudwatch Metrics." ) ;
207+ if ( ! _captureColdStartEnabled )
208+ Console . WriteLine (
209+ "##WARNING## Metrics and Metadata have not been specified. No data will be sent to Cloudwatch Metrics." ) ;
202210 }
203211 }
204212
@@ -230,7 +238,7 @@ void IMetrics.PushSingleMetric(string metricName, double value, MetricUnit unit,
230238 {
231239 if ( string . IsNullOrWhiteSpace ( metricName ) )
232240 throw new ArgumentNullException (
233- "'PushSingleMetric' method requires a valid metrics key. 'Null' or empty values are not allowed." ) ;
241+ $ "'PushSingleMetric' method requires a valid metrics key. 'Null' or empty values are not allowed.") ;
234242
235243 using var context = InitializeContext ( nameSpace , service , defaultDimensions ) ;
236244 context . AddMetric ( metricName , value , unit ) ;
0 commit comments