@@ -122,12 +122,16 @@ Subsegment.prototype.addPrecursorId = function(id) {
122122 */
123123
124124Subsegment . prototype . addAnnotation = function ( key , value ) {
125- if ( ! ( typeof value === 'boolean' || typeof value === 'string' || ( typeof value === 'number' && isFinite ( value ) ) ) ) {
126- throw new Error ( 'Failed to add annotation key: ' + key + ' value: ' + value + ' to subsegment ' +
125+ if ( typeof value !== 'boolean' && typeof value !== 'string' && ! isFinite ( value ) ) {
126+ logger . getLogger ( ) . error ( 'Failed to add annotation key: ' + key + ' value: ' + value + ' to subsegment ' +
127127 this . name + '. Value must be of type string, number or boolean.' ) ;
128- } else if ( typeof key !== 'string' ) {
129- throw new Error ( 'Failed to add annotation key: ' + key + ' value: ' + value + ' to subsegment ' +
128+ return ;
129+ }
130+
131+ if ( typeof key !== 'string' ) {
132+ logger . getLogger ( ) . error ( 'Failed to add annotation key: ' + key + ' value: ' + value + ' to subsegment ' +
130133 this . name + '. Key must be of type string.' ) ;
134+ return ;
131135 }
132136
133137 if ( this . annotations === undefined ) {
@@ -147,11 +151,15 @@ Subsegment.prototype.addAnnotation = function(key, value) {
147151
148152Subsegment . prototype . addMetadata = function ( key , value , namespace ) {
149153 if ( typeof key !== 'string' ) {
150- throw new Error ( 'Failed to add annotation key: ' + key + ' value: ' + value + ' to subsegment ' +
154+ logger . getLogger ( ) . error ( 'Failed to add metadata key: ' + key + ' value: ' + value + ' to subsegment ' +
151155 this . name + '. Key must be of type string.' ) ;
152- } else if ( namespace && typeof namespace !== 'string' ) {
153- throw new Error ( 'Failed to add annotation key: ' + key + ' value: ' + value + 'namespace: ' + namespace + ' to subsegment ' +
156+ return ;
157+ }
158+
159+ if ( namespace && typeof namespace !== 'string' ) {
160+ logger . getLogger ( ) . error ( 'Failed to add metadata key: ' + key + ' value: ' + value + ' to subsegment ' +
154161 this . name + '. Namespace must be of type string.' ) ;
162+ return ;
155163 }
156164
157165 var ns = namespace || 'default' ;
@@ -164,7 +172,7 @@ Subsegment.prototype.addMetadata = function(key, value, namespace) {
164172 this . metadata [ ns ] = { } ;
165173 }
166174
167- this . metadata [ ns ] [ key ] = value ;
175+ this . metadata [ ns ] [ key ] = value !== null && value !== undefined ? value : '' ;
168176} ;
169177
170178Subsegment . prototype . addSqlData = function addSqlData ( sqlData ) {
@@ -182,8 +190,9 @@ Subsegment.prototype.addSqlData = function addSqlData(sqlData) {
182190
183191Subsegment . prototype . addError = function addError ( err , remote ) {
184192 if ( err == null || typeof err !== 'object' && typeof ( err ) !== 'string' ) {
185- throw new Error ( 'Failed to add error:' + err + ' to subsegment "' + this . name +
186- '". Not an object or string literal.' ) ;
193+ logger . getLogger ( ) . error ( 'Failed to add error:' + err + ' to subsegment "' + this . name +
194+ '". Not an object or string literal.' ) ;
195+ return ;
187196 }
188197
189198 this . addFaultFlag ( ) ;
@@ -323,8 +332,9 @@ Subsegment.prototype.isClosed = function isClosed() {
323332
324333Subsegment . prototype . flush = function flush ( ) {
325334 if ( ! this . parent || ! this . segment ) {
326- throw new Error ( 'Failed to flush subsegment: ' + this . name + '. Subsegment must be added ' +
335+ logger . getLogger ( ) . error ( 'Failed to flush subsegment: ' + this . name + '. Subsegment must be added ' +
327336 'to a segment chain to flush.' ) ;
337+ return ;
328338 }
329339
330340 if ( this . segment . trace_id ) {
0 commit comments