@@ -101,11 +101,6 @@ export const MetricsProcessor = (
101
101
} ;
102
102
103
103
const _summarize = ( ) : Metrics | unknown => {
104
- if ( ! data ) {
105
- log . debug ( 'No metrics data!' ) ;
106
- return ;
107
- }
108
-
109
104
const targetData : TargetData [ ] = [ ] ;
110
105
const metricsData : MetricsData [ ] = [ ] ;
111
106
@@ -184,30 +179,34 @@ export const MetricsProcessor = (
184
179
185
180
const _send = ( ) : void => {
186
181
if ( closed ) {
182
+ log . debug ( 'SDK has been closed before metrics can be sent' ) ;
183
+ return ;
184
+ }
185
+
186
+ if ( data . size == 0 ) {
187
+ log . debug ( 'No metrics to send in this interval' ) ;
187
188
return ;
188
189
}
189
190
190
191
const metrics : Metrics = _summarize ( ) ;
191
192
192
- if ( metrics && metrics . metricsData . length && metrics . targetData . length ) {
193
- log . debug ( 'Start sending metrics data' ) ;
194
- api
195
- . postMetrics ( environment , cluster , metrics )
196
- . then ( ( response ) => {
197
- log . debug ( 'Metrics server returns: ' , response . status ) ;
198
- infoMetricsSuccess ( log ) ;
199
- if ( response . status >= 400 ) {
200
- log . error (
201
- 'Error while sending metrics data with status code: ' ,
202
- response . status ,
203
- ) ;
204
- }
205
- } )
206
- . catch ( ( error : Error ) => {
207
- warnPostMetricsFailed ( `${ error } ` , log ) ;
208
- log . debug ( 'Metrics server returns error: ' , error ) ;
209
- } ) ;
210
- }
193
+ log . debug ( 'Start sending metrics data' ) ;
194
+ api
195
+ . postMetrics ( environment , cluster , metrics )
196
+ . then ( ( response ) => {
197
+ log . debug ( 'Metrics server returns: ' , response . status ) ;
198
+ infoMetricsSuccess ( log ) ;
199
+ if ( response . status >= 400 ) {
200
+ log . error (
201
+ 'Error while sending metrics data with status code: ' ,
202
+ response . status ,
203
+ ) ;
204
+ }
205
+ } )
206
+ . catch ( ( error : Error ) => {
207
+ warnPostMetricsFailed ( `${ error } ` , log ) ;
208
+ log . debug ( 'Metrics server returns error: ' , error ) ;
209
+ } ) ;
211
210
} ;
212
211
213
212
const start = ( ) : void => {
0 commit comments