diff --git a/packages/dd-trace/src/opentracing/propagation/text_map.js b/packages/dd-trace/src/opentracing/propagation/text_map.js index 8d2beebad3f..4c67cfa5957 100644 --- a/packages/dd-trace/src/opentracing/propagation/text_map.js +++ b/packages/dd-trace/src/opentracing/propagation/text_map.js @@ -128,11 +128,11 @@ class TextMapPropagator { let byteCounter = 0 for (const [key, value] of Object.entries(spanContext._baggageItems)) { - let item = `${this._encodeOtelBaggageKey(String(key).trim())}=${encodeURIComponent(String(value).trim())},` - itemCounter += 1 - byteCounter += item.length - if (itemCounter > this._config.baggageMaxItems || byteCounter > this._config.baggageMaxBytes) break - baggage += item + const item = `${this._encodeOtelBaggageKey(String(key).trim())}=${encodeURIComponent(String(value).trim())},` + itemCounter += 1 + byteCounter += item.length + if (itemCounter > this._config.baggageMaxItems || byteCounter > this._config.baggageMaxBytes) break + baggage += item } baggage = baggage.slice(0, baggage.length - 1) diff --git a/packages/dd-trace/test/opentracing/propagation/text_map.spec.js b/packages/dd-trace/test/opentracing/propagation/text_map.spec.js index 9aac799f6ed..45ddc905ee4 100644 --- a/packages/dd-trace/test/opentracing/propagation/text_map.spec.js +++ b/packages/dd-trace/test/opentracing/propagation/text_map.spec.js @@ -108,6 +108,7 @@ describe('TextMapPropagator', () => { const spanContext = createContext({ baggageItems }) propagator.inject(spanContext, carrier) + // eslint-disable-next-line max-len expect(carrier.baggage).to.be.equal('%22%2C%3B%5C%28%29%2F%3A%3C%3D%3E%3F%40%5B%5D%7B%7D%F0%9F%90%B6%C3%A9%E6%88%91=%22%2C%3B%5C%F0%9F%90%B6%C3%A9%E6%88%91') })