UNPKG

@vtex/diagnostics-nodejs

Version:

Diagnostics library for Node.js applications

75 lines 2.23 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SamplerMetadata = void 0; exports.newSamplerMetadata = newSamplerMetadata; const sdk_trace_base_1 = require("@opentelemetry/sdk-trace-base"); class SamplerMetadata { constructor(samplerType) { this.decision = ''; this.reason = ''; this.extra = {}; this.samplerType = samplerType; } setDecision(decision, reason) { this.decision = this.mapDecision(decision); this.reason = reason; return this; } setRate(rate) { this.extra['rate'] = rate; return this; } setRule(ruleName) { this.extra['rule'] = ruleName; return this; } setTrigger(trigger) { this.extra['trigger'] = trigger; return this; } addExtra(key, value) { this.extra[key] = value; return this; } mapDecision(decision) { switch (decision) { case sdk_trace_base_1.SamplingDecision.RECORD_AND_SAMPLED: return 'record_and_sample'; case sdk_trace_base_1.SamplingDecision.NOT_RECORD: return 'drop'; default: return 'unknown'; } } toAttributes() { const attrs = { 'sampler.type': this.samplerType }; if (this.decision) { attrs['sampler.decision'] = this.decision; } if (this.reason) { attrs['sampler.reason'] = this.reason; } if (this.extra.rate !== undefined) { attrs['sampler.rate'] = this.extra.rate; } if (this.extra.rule) { attrs['sampler.rule'] = this.extra.rule; } if (this.extra.trigger) { attrs['sampler.trigger'] = this.extra.trigger; } for (const [key, value] of Object.entries(this.extra)) { if (!['rate', 'rule', 'trigger'].includes(key)) { attrs[`sampler.${key}`] = value; } } return attrs; } } exports.SamplerMetadata = SamplerMetadata; function newSamplerMetadata(samplerType) { return new SamplerMetadata(samplerType); } //# sourceMappingURL=metadata.js.map