Subsegment.prototype.addMetadata = function()

in packages/core/lib/segments/attributes/subsegment.js [168:194]


Subsegment.prototype.addMetadata = function(key, value, namespace) {
  if (typeof key !== 'string') {
    logger.getLogger().error('Failed to add metadata key: ' + key + ' value: ' + value + ' to subsegment ' +
      this.name + '. Key must be of type string.');
    return;
  }

  if (namespace && typeof namespace !== 'string') {
    logger.getLogger().error('Failed to add metadata key: ' + key + ' value: ' + value + ' to subsegment ' +
      this.name + '. Namespace must be of type string.');
    return;
  }

  var ns = namespace || 'default';

  if (!this.metadata) {
    this.metadata = {};
  }

  if (!this.metadata[ns]) {
    this.metadata[ns] = {};
  }

  if (ns !== '__proto__') {
    this.metadata[ns][key] = value !== null && value !== undefined ? value : '';
  }
};