@opentelemetry/core
Version:
OpenTelemetry Core provides constants and utilities shared by all OpenTelemetry SDK packages.
63 lines (62 loc) • 2.18 kB
JavaScript
let _opentelemetry_api = require("@opentelemetry/api");
//#region src/propagation/composite.ts
/** Combines multiple propagators into a single propagator. */
var CompositePropagator = class {
_propagators;
_fields;
/**
* Construct a composite propagator from a list of propagators.
*
* @param [config] Configuration object for composite propagator
*/
constructor(config = {}) {
this._propagators = config.propagators ?? [];
const fields = /* @__PURE__ */ new Set();
for (const propagator of this._propagators) {
const propagatorFields = typeof propagator.fields === "function" ? propagator.fields() : [];
for (const field of propagatorFields) fields.add(field);
}
this._fields = Array.from(fields);
}
/**
* Run each of the configured propagators with the given context and carrier.
* Propagators are run in the order they are configured, so if multiple
* propagators write the same carrier key, the propagator later in the list
* will "win".
*
* @param context Context to inject
* @param carrier Carrier into which context will be injected
*/
inject(context, carrier, setter) {
for (const propagator of this._propagators) try {
propagator.inject(context, carrier, setter);
} catch (err) {
_opentelemetry_api.diag.warn(`Failed to inject with ${propagator.constructor.name}. Err: ${err.message}`);
}
}
/**
* Run each of the configured propagators with the given context and carrier.
* Propagators are run in the order they are configured, so if multiple
* propagators write the same context key, the propagator later in the list
* will "win".
*
* @param context Context to add values to
* @param carrier Carrier from which to extract context
*/
extract(context, carrier, getter) {
return this._propagators.reduce((ctx, propagator) => {
try {
return propagator.extract(ctx, carrier, getter);
} catch (err) {
_opentelemetry_api.diag.warn(`Failed to extract with ${propagator.constructor.name}. Err: ${err.message}`);
}
return ctx;
}, context);
}
fields() {
return this._fields.slice();
}
};
//#endregion
exports.CompositePropagator = CompositePropagator;
//# sourceMappingURL=composite.cjs.map