Skip to content
This repository was archived by the owner on Sep 13, 2022. It is now read-only.

Commit 7a9c100

Browse files
Artem Rutsyurishkuro
Artem Ruts
authored andcommitted
Allow overriding codec's default baggage prefix. (#310)
Signed-off-by: Artem Ruts <[email protected]>
1 parent 9b1e1ff commit 7a9c100

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

src/configuration.js

+1
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ export default class Configuration {
226226

227227
return new Tracer(config.serviceName, reporter, sampler, {
228228
contextKey: options.contextKey,
229+
baggagePrefix: options.baggagePrefix,
229230
metrics: options.metrics,
230231
logger: options.logger,
231232
tags: options.tags,

src/tracer.js

+2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export default class Tracer {
5555
* @param {Object} [options.logger] - a logger matching NullLogger API from ./logger.js.
5656
* @param {Object} [options.baggageRestrictionManager] - a baggageRestrictionManager matching
5757
* @param {Object} [options.contextKey] - a name of the key to extract/inject context from headers
58+
* @param {Object} [options.baggagePrefix] - a name of the context baggage key prefix
5859
* BaggageRestrictionManager API from ./baggage.js.
5960
*/
6061
constructor(
@@ -84,6 +85,7 @@ export default class Tracer {
8485

8586
let codecOptions = {
8687
contextKey: options.contextKey || null,
88+
baggagePrefix: options.baggagePrefix || null,
8789
urlEncoding: false,
8890
metrics: this._metrics,
8991
};

test/init_tracer.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -210,12 +210,16 @@ describe('initTracer', () => {
210210
x: 'y',
211211
},
212212
contextKey: 'custom-header',
213+
baggagePrefix: 'prfx-',
213214
}
214215
);
215216
assert.equal(tracer._logger, logger);
216217
assert.equal(tracer._metrics._factory, metrics);
217218
assert.equal(tracer._tags['x'], 'y');
218-
assert.equal(tracer._injectors[opentracing.FORMAT_TEXT_MAP]._contextKey, 'custom-header');
219+
220+
const textMapInjector = tracer._injectors[opentracing.FORMAT_TEXT_MAP];
221+
assert.equal(textMapInjector._contextKey, 'custom-header');
222+
assert.equal(textMapInjector._baggagePrefix, 'prfx-');
219223
tracer.close(done);
220224
});
221225

0 commit comments

Comments
 (0)