@opentelemetry/sdk-metrics
Version:
94 lines • 3.36 kB
JavaScript
;
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.createDenyListAttributesProcessor = exports.createAllowListAttributesProcessor = exports.createMultiAttributesProcessor = exports.createNoopAttributesProcessor = void 0;
class NoopAttributesProcessor {
process(incoming, _context) {
return incoming;
}
}
class MultiAttributesProcessor {
_processors;
constructor(processors) {
this._processors = processors;
}
process(incoming, context) {
let filteredAttributes = incoming;
for (const processor of this._processors) {
filteredAttributes = processor.process(filteredAttributes, context);
}
return filteredAttributes;
}
}
class AllowListProcessor {
_allowedAttributeNames;
constructor(allowedAttributeNames) {
this._allowedAttributeNames = new Set(allowedAttributeNames);
}
process(incoming, _context) {
const filteredAttributes = {};
for (const attributeName in incoming) {
if (Object.prototype.hasOwnProperty.call(incoming, attributeName) &&
this._allowedAttributeNames.has(attributeName)) {
filteredAttributes[attributeName] = incoming[attributeName];
}
}
return filteredAttributes;
}
}
class DenyListProcessor {
_deniedAttributeNames;
constructor(deniedAttributeNames) {
this._deniedAttributeNames = new Set(deniedAttributeNames);
}
process(incoming, _context) {
const filteredAttributes = {};
for (const attributeName in incoming) {
if (Object.prototype.hasOwnProperty.call(incoming, attributeName) &&
!this._deniedAttributeNames.has(attributeName)) {
filteredAttributes[attributeName] = incoming[attributeName];
}
}
return filteredAttributes;
}
}
/**
* @internal
*
* Create an {@link IAttributesProcessor} that acts as a simple pass-through for attributes.
*/
function createNoopAttributesProcessor() {
return NOOP;
}
exports.createNoopAttributesProcessor = createNoopAttributesProcessor;
/**
* @internal
*
* Create an {@link IAttributesProcessor} that applies all processors from the provided list in order.
*
* @param processors Processors to apply in order.
*/
function createMultiAttributesProcessor(processors) {
return new MultiAttributesProcessor(processors);
}
exports.createMultiAttributesProcessor = createMultiAttributesProcessor;
/**
* Create an {@link IAttributesProcessor} that filters by allowed attribute names and drops any names that are not in the
* allow list.
*/
function createAllowListAttributesProcessor(attributeAllowList) {
return new AllowListProcessor(attributeAllowList);
}
exports.createAllowListAttributesProcessor = createAllowListAttributesProcessor;
/**
* Create an {@link IAttributesProcessor} that drops attributes based on the names provided in the deny list
*/
function createDenyListAttributesProcessor(attributeDenyList) {
return new DenyListProcessor(attributeDenyList);
}
exports.createDenyListAttributesProcessor = createDenyListAttributesProcessor;
const NOOP = new NoopAttributesProcessor();
//# sourceMappingURL=AttributesProcessor.js.map