@@ -45,6 +45,11 @@ public class Metrics : IMetrics
45
45
/// If true, Powertools will throw an exception on empty metrics when trying to flush
46
46
/// </summary>
47
47
private readonly bool _raiseOnEmptyMetrics ;
48
+
49
+ /// <summary>
50
+ /// The capture cold start enabled
51
+ /// </summary>
52
+ private readonly bool _captureColdStartEnabled ;
48
53
49
54
/// <summary>
50
55
/// 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
55
60
/// <param name="nameSpace">Metrics Namespace Identifier</param>
56
61
/// <param name="service">Metrics Service Name</param>
57
62
/// <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>
58
64
internal Metrics ( IPowertoolsConfigurations powertoolsConfigurations , string nameSpace = null , string service = null ,
59
- bool raiseOnEmptyMetrics = false )
65
+ bool raiseOnEmptyMetrics = false , bool captureColdStartEnabled = false )
60
66
{
61
67
if ( _instance != null ) return ;
62
68
63
69
_instance = this ;
64
70
_powertoolsConfigurations = powertoolsConfigurations ;
65
71
_raiseOnEmptyMetrics = raiseOnEmptyMetrics ;
72
+ _captureColdStartEnabled = captureColdStartEnabled ;
66
73
_context = InitializeContext ( nameSpace , service , null ) ;
67
74
}
68
75
@@ -80,7 +87,7 @@ void IMetrics.AddMetric(string key, double value, MetricUnit unit)
80
87
{
81
88
if ( string . IsNullOrWhiteSpace ( key ) )
82
89
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.") ;
84
91
85
92
if ( value < 0 ) {
86
93
throw new ArgumentException (
@@ -132,7 +139,7 @@ void IMetrics.AddDimension(string key, string value)
132
139
{
133
140
if ( string . IsNullOrWhiteSpace ( key ) )
134
141
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.") ;
136
143
137
144
_context . AddDimension ( key , value ) ;
138
145
}
@@ -150,7 +157,7 @@ void IMetrics.AddMetadata(string key, object value)
150
157
{
151
158
if ( string . IsNullOrWhiteSpace ( key ) )
152
159
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.") ;
154
161
155
162
_context . AddMetadata ( key , value ) ;
156
163
}
@@ -168,7 +175,7 @@ void IMetrics.SetDefaultDimensions(Dictionary<string, string> defaultDimensions)
168
175
foreach ( var item in defaultDimensions )
169
176
if ( string . IsNullOrWhiteSpace ( item . Key ) || string . IsNullOrWhiteSpace ( item . Value ) )
170
177
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.") ;
172
179
173
180
_context . SetDefaultDimensions ( DictionaryToList ( defaultDimensions ) ) ;
174
181
}
@@ -197,8 +204,9 @@ void IMetrics.Flush(bool metricsOverflow)
197
204
}
198
205
else
199
206
{
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." ) ;
202
210
}
203
211
}
204
212
@@ -230,7 +238,7 @@ void IMetrics.PushSingleMetric(string metricName, double value, MetricUnit unit,
230
238
{
231
239
if ( string . IsNullOrWhiteSpace ( metricName ) )
232
240
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.") ;
234
242
235
243
using var context = InitializeContext ( nameSpace , service , defaultDimensions ) ;
236
244
context . AddMetric ( metricName , value , unit ) ;
0 commit comments