feat: Complete zCode CLI X with Telegram bot integration

- Add full Telegram bot functionality with Z.AI API integration
- Implement 4 tools: Bash, FileEdit, WebSearch, Git
- Add 3 agents: Code Reviewer, Architect, DevOps Engineer
- Add 6 skills for common coding tasks
- Add systemd service file for 24/7 operation
- Add nginx configuration for HTTPS webhook
- Add comprehensive documentation
- Implement WebSocket server for real-time updates
- Add logging system with Winston
- Add environment validation

🤖 zCode CLI X - Agentic coder with Z.AI + Telegram integration
This commit is contained in:
admin
2026-05-05 09:01:26 +00:00
Unverified
parent 4a7035dd92
commit 875c7f9b91
24688 changed files with 3224957 additions and 221 deletions

View File

@@ -0,0 +1,74 @@
import { Aggregator, SumAggregator, DropAggregator, LastValueAggregator, HistogramAggregator, ExponentialHistogramAggregator } from '../aggregator';
import { Accumulation } from '../aggregator/types';
import { InstrumentDescriptor } from '../InstrumentDescriptor';
import { Maybe } from '../utils';
/**
* Configures how measurements are combined into metrics for views.
*
* Aggregation provides a set of built-in aggregations via static methods.
*/
export declare abstract class Aggregation {
abstract createAggregator(instrument: InstrumentDescriptor): Aggregator<Maybe<Accumulation>>;
static Drop(): Aggregation;
static Sum(): Aggregation;
static LastValue(): Aggregation;
static Histogram(): Aggregation;
static ExponentialHistogram(): Aggregation;
static Default(): Aggregation;
}
/**
* The default drop aggregation.
*/
export declare class DropAggregation extends Aggregation {
private static DEFAULT_INSTANCE;
createAggregator(_instrument: InstrumentDescriptor): DropAggregator;
}
/**
* The default sum aggregation.
*/
export declare class SumAggregation extends Aggregation {
private static MONOTONIC_INSTANCE;
private static NON_MONOTONIC_INSTANCE;
createAggregator(instrument: InstrumentDescriptor): SumAggregator;
}
/**
* The default last value aggregation.
*/
export declare class LastValueAggregation extends Aggregation {
private static DEFAULT_INSTANCE;
createAggregator(_instrument: InstrumentDescriptor): LastValueAggregator;
}
/**
* The default histogram aggregation.
*/
export declare class HistogramAggregation extends Aggregation {
private static DEFAULT_INSTANCE;
createAggregator(_instrument: InstrumentDescriptor): HistogramAggregator;
}
/**
* The explicit bucket histogram aggregation.
*/
export declare class ExplicitBucketHistogramAggregation extends Aggregation {
private readonly _recordMinMax;
private _boundaries;
/**
* @param boundaries the bucket boundaries of the histogram aggregation
* @param _recordMinMax If set to true, min and max will be recorded. Otherwise, min and max will not be recorded.
*/
constructor(boundaries: number[], _recordMinMax?: boolean);
createAggregator(_instrument: InstrumentDescriptor): HistogramAggregator;
}
export declare class ExponentialHistogramAggregation extends Aggregation {
private readonly _maxSize;
private readonly _recordMinMax;
constructor(_maxSize?: number, _recordMinMax?: boolean);
createAggregator(_instrument: InstrumentDescriptor): ExponentialHistogramAggregator;
}
/**
* The default aggregation.
*/
export declare class DefaultAggregation extends Aggregation {
private _resolve;
createAggregator(instrument: InstrumentDescriptor): Aggregator<Maybe<Accumulation>>;
}
//# sourceMappingURL=Aggregation.d.ts.map

View File

@@ -0,0 +1,228 @@
/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
import * as api from '@opentelemetry/api';
import { SumAggregator, DropAggregator, LastValueAggregator, HistogramAggregator, ExponentialHistogramAggregator, } from '../aggregator';
import { InstrumentType } from '../InstrumentDescriptor';
/**
* Configures how measurements are combined into metrics for views.
*
* Aggregation provides a set of built-in aggregations via static methods.
*/
var Aggregation = /** @class */ (function () {
function Aggregation() {
}
Aggregation.Drop = function () {
return DROP_AGGREGATION;
};
Aggregation.Sum = function () {
return SUM_AGGREGATION;
};
Aggregation.LastValue = function () {
return LAST_VALUE_AGGREGATION;
};
Aggregation.Histogram = function () {
return HISTOGRAM_AGGREGATION;
};
Aggregation.ExponentialHistogram = function () {
return EXPONENTIAL_HISTOGRAM_AGGREGATION;
};
Aggregation.Default = function () {
return DEFAULT_AGGREGATION;
};
return Aggregation;
}());
export { Aggregation };
/**
* The default drop aggregation.
*/
var DropAggregation = /** @class */ (function (_super) {
__extends(DropAggregation, _super);
function DropAggregation() {
return _super !== null && _super.apply(this, arguments) || this;
}
DropAggregation.prototype.createAggregator = function (_instrument) {
return DropAggregation.DEFAULT_INSTANCE;
};
DropAggregation.DEFAULT_INSTANCE = new DropAggregator();
return DropAggregation;
}(Aggregation));
export { DropAggregation };
/**
* The default sum aggregation.
*/
var SumAggregation = /** @class */ (function (_super) {
__extends(SumAggregation, _super);
function SumAggregation() {
return _super !== null && _super.apply(this, arguments) || this;
}
SumAggregation.prototype.createAggregator = function (instrument) {
switch (instrument.type) {
case InstrumentType.COUNTER:
case InstrumentType.OBSERVABLE_COUNTER:
case InstrumentType.HISTOGRAM: {
return SumAggregation.MONOTONIC_INSTANCE;
}
default: {
return SumAggregation.NON_MONOTONIC_INSTANCE;
}
}
};
SumAggregation.MONOTONIC_INSTANCE = new SumAggregator(true);
SumAggregation.NON_MONOTONIC_INSTANCE = new SumAggregator(false);
return SumAggregation;
}(Aggregation));
export { SumAggregation };
/**
* The default last value aggregation.
*/
var LastValueAggregation = /** @class */ (function (_super) {
__extends(LastValueAggregation, _super);
function LastValueAggregation() {
return _super !== null && _super.apply(this, arguments) || this;
}
LastValueAggregation.prototype.createAggregator = function (_instrument) {
return LastValueAggregation.DEFAULT_INSTANCE;
};
LastValueAggregation.DEFAULT_INSTANCE = new LastValueAggregator();
return LastValueAggregation;
}(Aggregation));
export { LastValueAggregation };
/**
* The default histogram aggregation.
*/
var HistogramAggregation = /** @class */ (function (_super) {
__extends(HistogramAggregation, _super);
function HistogramAggregation() {
return _super !== null && _super.apply(this, arguments) || this;
}
HistogramAggregation.prototype.createAggregator = function (_instrument) {
return HistogramAggregation.DEFAULT_INSTANCE;
};
HistogramAggregation.DEFAULT_INSTANCE = new HistogramAggregator([0, 5, 10, 25, 50, 75, 100, 250, 500, 750, 1000, 2500, 5000, 7500, 10000], true);
return HistogramAggregation;
}(Aggregation));
export { HistogramAggregation };
/**
* The explicit bucket histogram aggregation.
*/
var ExplicitBucketHistogramAggregation = /** @class */ (function (_super) {
__extends(ExplicitBucketHistogramAggregation, _super);
/**
* @param boundaries the bucket boundaries of the histogram aggregation
* @param _recordMinMax If set to true, min and max will be recorded. Otherwise, min and max will not be recorded.
*/
function ExplicitBucketHistogramAggregation(boundaries, _recordMinMax) {
if (_recordMinMax === void 0) { _recordMinMax = true; }
var _this = _super.call(this) || this;
_this._recordMinMax = _recordMinMax;
if (boundaries == null) {
throw new Error('ExplicitBucketHistogramAggregation should be created with explicit boundaries, if a single bucket histogram is required, please pass an empty array');
}
// Copy the boundaries array for modification.
boundaries = boundaries.concat();
// We need to an ordered set to be able to correctly compute count for each
// boundary since we'll iterate on each in order.
boundaries = boundaries.sort(function (a, b) { return a - b; });
// Remove all Infinity from the boundaries.
var minusInfinityIndex = boundaries.lastIndexOf(-Infinity);
var infinityIndex = boundaries.indexOf(Infinity);
if (infinityIndex === -1) {
infinityIndex = undefined;
}
_this._boundaries = boundaries.slice(minusInfinityIndex + 1, infinityIndex);
return _this;
}
ExplicitBucketHistogramAggregation.prototype.createAggregator = function (_instrument) {
return new HistogramAggregator(this._boundaries, this._recordMinMax);
};
return ExplicitBucketHistogramAggregation;
}(Aggregation));
export { ExplicitBucketHistogramAggregation };
var ExponentialHistogramAggregation = /** @class */ (function (_super) {
__extends(ExponentialHistogramAggregation, _super);
function ExponentialHistogramAggregation(_maxSize, _recordMinMax) {
if (_maxSize === void 0) { _maxSize = 160; }
if (_recordMinMax === void 0) { _recordMinMax = true; }
var _this = _super.call(this) || this;
_this._maxSize = _maxSize;
_this._recordMinMax = _recordMinMax;
return _this;
}
ExponentialHistogramAggregation.prototype.createAggregator = function (_instrument) {
return new ExponentialHistogramAggregator(this._maxSize, this._recordMinMax);
};
return ExponentialHistogramAggregation;
}(Aggregation));
export { ExponentialHistogramAggregation };
/**
* The default aggregation.
*/
var DefaultAggregation = /** @class */ (function (_super) {
__extends(DefaultAggregation, _super);
function DefaultAggregation() {
return _super !== null && _super.apply(this, arguments) || this;
}
DefaultAggregation.prototype._resolve = function (instrument) {
// cast to unknown to disable complaints on the (unreachable) fallback.
switch (instrument.type) {
case InstrumentType.COUNTER:
case InstrumentType.UP_DOWN_COUNTER:
case InstrumentType.OBSERVABLE_COUNTER:
case InstrumentType.OBSERVABLE_UP_DOWN_COUNTER: {
return SUM_AGGREGATION;
}
case InstrumentType.GAUGE:
case InstrumentType.OBSERVABLE_GAUGE: {
return LAST_VALUE_AGGREGATION;
}
case InstrumentType.HISTOGRAM: {
if (instrument.advice.explicitBucketBoundaries) {
return new ExplicitBucketHistogramAggregation(instrument.advice.explicitBucketBoundaries);
}
return HISTOGRAM_AGGREGATION;
}
}
api.diag.warn("Unable to recognize instrument type: " + instrument.type);
return DROP_AGGREGATION;
};
DefaultAggregation.prototype.createAggregator = function (instrument) {
return this._resolve(instrument).createAggregator(instrument);
};
return DefaultAggregation;
}(Aggregation));
export { DefaultAggregation };
var DROP_AGGREGATION = new DropAggregation();
var SUM_AGGREGATION = new SumAggregation();
var LAST_VALUE_AGGREGATION = new LastValueAggregation();
var HISTOGRAM_AGGREGATION = new HistogramAggregation();
var EXPONENTIAL_HISTOGRAM_AGGREGATION = new ExponentialHistogramAggregation();
var DEFAULT_AGGREGATION = new DefaultAggregation();
//# sourceMappingURL=Aggregation.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,30 @@
import { Context, MetricAttributes } from '@opentelemetry/api';
/**
* The {@link AttributesProcessor} is responsible for customizing which
* attribute(s) are to be reported as metrics dimension(s) and adding
* additional dimension(s) from the {@link Context}.
*/
export declare abstract class AttributesProcessor {
/**
* Process the metric instrument attributes.
*
* @param incoming The metric instrument attributes.
* @param context The active context when the instrument is synchronous.
* `undefined` otherwise.
*/
abstract process(incoming: MetricAttributes, context?: Context): MetricAttributes;
static Noop(): NoopAttributesProcessor;
}
export declare class NoopAttributesProcessor extends AttributesProcessor {
process(incoming: MetricAttributes, _context?: Context): import("@opentelemetry/api").Attributes;
}
/**
* {@link AttributesProcessor} that filters by allowed attribute names and drops any names that are not in the
* allow list.
*/
export declare class FilteringAttributesProcessor extends AttributesProcessor {
private _allowedAttributeNames;
constructor(_allowedAttributeNames: string[]);
process(incoming: MetricAttributes, _context: Context): MetricAttributes;
}
//# sourceMappingURL=AttributesProcessor.d.ts.map

View File

@@ -0,0 +1,83 @@
/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
/**
* The {@link AttributesProcessor} is responsible for customizing which
* attribute(s) are to be reported as metrics dimension(s) and adding
* additional dimension(s) from the {@link Context}.
*/
var AttributesProcessor = /** @class */ (function () {
function AttributesProcessor() {
}
AttributesProcessor.Noop = function () {
return NOOP;
};
return AttributesProcessor;
}());
export { AttributesProcessor };
var NoopAttributesProcessor = /** @class */ (function (_super) {
__extends(NoopAttributesProcessor, _super);
function NoopAttributesProcessor() {
return _super !== null && _super.apply(this, arguments) || this;
}
NoopAttributesProcessor.prototype.process = function (incoming, _context) {
return incoming;
};
return NoopAttributesProcessor;
}(AttributesProcessor));
export { NoopAttributesProcessor };
/**
* {@link AttributesProcessor} that filters by allowed attribute names and drops any names that are not in the
* allow list.
*/
var FilteringAttributesProcessor = /** @class */ (function (_super) {
__extends(FilteringAttributesProcessor, _super);
function FilteringAttributesProcessor(_allowedAttributeNames) {
var _this = _super.call(this) || this;
_this._allowedAttributeNames = _allowedAttributeNames;
return _this;
}
FilteringAttributesProcessor.prototype.process = function (incoming, _context) {
var _this = this;
var filteredAttributes = {};
Object.keys(incoming)
.filter(function (attributeName) {
return _this._allowedAttributeNames.includes(attributeName);
})
.forEach(function (attributeName) {
return (filteredAttributes[attributeName] = incoming[attributeName]);
});
return filteredAttributes;
};
return FilteringAttributesProcessor;
}(AttributesProcessor));
export { FilteringAttributesProcessor };
var NOOP = new NoopAttributesProcessor();
//# sourceMappingURL=AttributesProcessor.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"AttributesProcessor.js","sourceRoot":"","sources":["../../../src/view/AttributesProcessor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;;;AAIH;;;;GAIG;AACH;IAAA;IAgBA,CAAC;IAHQ,wBAAI,GAAX;QACE,OAAO,IAAI,CAAC;IACd,CAAC;IACH,0BAAC;AAAD,CAAC,AAhBD,IAgBC;;AAED;IAA6C,2CAAmB;IAAhE;;IAIA,CAAC;IAHC,yCAAO,GAAP,UAAQ,QAA0B,EAAE,QAAkB;QACpD,OAAO,QAAQ,CAAC;IAClB,CAAC;IACH,8BAAC;AAAD,CAAC,AAJD,CAA6C,mBAAmB,GAI/D;;AAED;;;GAGG;AACH;IAAkD,gDAAmB;IACnE,sCAAoB,sBAAgC;QAApD,YACE,iBAAO,SACR;QAFmB,4BAAsB,GAAtB,sBAAsB,CAAU;;IAEpD,CAAC;IAED,8CAAO,GAAP,UAAQ,QAA0B,EAAE,QAAiB;QAArD,iBAWC;QAVC,IAAM,kBAAkB,GAAqB,EAAE,CAAC;QAChD,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC;aAClB,MAAM,CAAC,UAAA,aAAa;YACnB,OAAA,KAAI,CAAC,sBAAsB,CAAC,QAAQ,CAAC,aAAa,CAAC;QAAnD,CAAmD,CACpD;aACA,OAAO,CACN,UAAA,aAAa;YACX,OAAA,CAAC,kBAAkB,CAAC,aAAa,CAAC,GAAG,QAAQ,CAAC,aAAa,CAAC,CAAC;QAA7D,CAA6D,CAChE,CAAC;QACJ,OAAO,kBAAkB,CAAC;IAC5B,CAAC;IACH,mCAAC;AAAD,CAAC,AAjBD,CAAkD,mBAAmB,GAiBpE;;AAED,IAAM,IAAI,GAAG,IAAI,uBAAuB,EAAE,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Context, MetricAttributes } from '@opentelemetry/api';\n\n/**\n * The {@link AttributesProcessor} is responsible for customizing which\n * attribute(s) are to be reported as metrics dimension(s) and adding\n * additional dimension(s) from the {@link Context}.\n */\nexport abstract class AttributesProcessor {\n /**\n * Process the metric instrument attributes.\n *\n * @param incoming The metric instrument attributes.\n * @param context The active context when the instrument is synchronous.\n * `undefined` otherwise.\n */\n abstract process(\n incoming: MetricAttributes,\n context?: Context\n ): MetricAttributes;\n\n static Noop() {\n return NOOP;\n }\n}\n\nexport class NoopAttributesProcessor extends AttributesProcessor {\n process(incoming: MetricAttributes, _context?: Context) {\n return incoming;\n }\n}\n\n/**\n * {@link AttributesProcessor} that filters by allowed attribute names and drops any names that are not in the\n * allow list.\n */\nexport class FilteringAttributesProcessor extends AttributesProcessor {\n constructor(private _allowedAttributeNames: string[]) {\n super();\n }\n\n process(incoming: MetricAttributes, _context: Context): MetricAttributes {\n const filteredAttributes: MetricAttributes = {};\n Object.keys(incoming)\n .filter(attributeName =>\n this._allowedAttributeNames.includes(attributeName)\n )\n .forEach(\n attributeName =>\n (filteredAttributes[attributeName] = incoming[attributeName])\n );\n return filteredAttributes;\n }\n}\n\nconst NOOP = new NoopAttributesProcessor();\n"]}

View File

@@ -0,0 +1,17 @@
import { InstrumentType } from '../InstrumentDescriptor';
import { Predicate } from './Predicate';
export interface InstrumentSelectorCriteria {
name?: string;
type?: InstrumentType;
unit?: string;
}
export declare class InstrumentSelector {
private _nameFilter;
private _type?;
private _unitFilter;
constructor(criteria?: InstrumentSelectorCriteria);
getType(): InstrumentType | undefined;
getNameFilter(): Predicate;
getUnitFilter(): Predicate;
}
//# sourceMappingURL=InstrumentSelector.d.ts.map

View File

@@ -0,0 +1,36 @@
/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { ExactPredicate, PatternPredicate } from './Predicate';
var InstrumentSelector = /** @class */ (function () {
function InstrumentSelector(criteria) {
var _a;
this._nameFilter = new PatternPredicate((_a = criteria === null || criteria === void 0 ? void 0 : criteria.name) !== null && _a !== void 0 ? _a : '*');
this._type = criteria === null || criteria === void 0 ? void 0 : criteria.type;
this._unitFilter = new ExactPredicate(criteria === null || criteria === void 0 ? void 0 : criteria.unit);
}
InstrumentSelector.prototype.getType = function () {
return this._type;
};
InstrumentSelector.prototype.getNameFilter = function () {
return this._nameFilter;
};
InstrumentSelector.prototype.getUnitFilter = function () {
return this._unitFilter;
};
return InstrumentSelector;
}());
export { InstrumentSelector };
//# sourceMappingURL=InstrumentSelector.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"InstrumentSelector.js","sourceRoot":"","sources":["../../../src/view/InstrumentSelector.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAa,MAAM,aAAa,CAAC;AAQ1E;IAKE,4BAAY,QAAqC;;QAC/C,IAAI,CAAC,WAAW,GAAG,IAAI,gBAAgB,CAAC,MAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,IAAI,mCAAI,GAAG,CAAC,CAAC;QAC/D,IAAI,CAAC,KAAK,GAAG,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,IAAI,CAAC;QAC5B,IAAI,CAAC,WAAW,GAAG,IAAI,cAAc,CAAC,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,IAAI,CAAC,CAAC;IACxD,CAAC;IAED,oCAAO,GAAP;QACE,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAED,0CAAa,GAAb;QACE,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;IAED,0CAAa,GAAb;QACE,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;IACH,yBAAC;AAAD,CAAC,AAtBD,IAsBC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { InstrumentType } from '../InstrumentDescriptor';\nimport { ExactPredicate, PatternPredicate, Predicate } from './Predicate';\n\nexport interface InstrumentSelectorCriteria {\n name?: string;\n type?: InstrumentType;\n unit?: string;\n}\n\nexport class InstrumentSelector {\n private _nameFilter: Predicate;\n private _type?: InstrumentType;\n private _unitFilter: Predicate;\n\n constructor(criteria?: InstrumentSelectorCriteria) {\n this._nameFilter = new PatternPredicate(criteria?.name ?? '*');\n this._type = criteria?.type;\n this._unitFilter = new ExactPredicate(criteria?.unit);\n }\n\n getType() {\n return this._type;\n }\n\n getNameFilter() {\n return this._nameFilter;\n }\n\n getUnitFilter() {\n return this._unitFilter;\n }\n}\n"]}

View File

@@ -0,0 +1,19 @@
import { Predicate } from './Predicate';
export interface MeterSelectorCriteria {
name?: string;
version?: string;
schemaUrl?: string;
}
export declare class MeterSelector {
private _nameFilter;
private _versionFilter;
private _schemaUrlFilter;
constructor(criteria?: MeterSelectorCriteria);
getNameFilter(): Predicate;
/**
* TODO: semver filter? no spec yet.
*/
getVersionFilter(): Predicate;
getSchemaUrlFilter(): Predicate;
}
//# sourceMappingURL=MeterSelector.d.ts.map

View File

@@ -0,0 +1,38 @@
/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { ExactPredicate } from './Predicate';
var MeterSelector = /** @class */ (function () {
function MeterSelector(criteria) {
this._nameFilter = new ExactPredicate(criteria === null || criteria === void 0 ? void 0 : criteria.name);
this._versionFilter = new ExactPredicate(criteria === null || criteria === void 0 ? void 0 : criteria.version);
this._schemaUrlFilter = new ExactPredicate(criteria === null || criteria === void 0 ? void 0 : criteria.schemaUrl);
}
MeterSelector.prototype.getNameFilter = function () {
return this._nameFilter;
};
/**
* TODO: semver filter? no spec yet.
*/
MeterSelector.prototype.getVersionFilter = function () {
return this._versionFilter;
};
MeterSelector.prototype.getSchemaUrlFilter = function () {
return this._schemaUrlFilter;
};
return MeterSelector;
}());
export { MeterSelector };
//# sourceMappingURL=MeterSelector.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"MeterSelector.js","sourceRoot":"","sources":["../../../src/view/MeterSelector.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,cAAc,EAAa,MAAM,aAAa,CAAC;AAQxD;IAKE,uBAAY,QAAgC;QAC1C,IAAI,CAAC,WAAW,GAAG,IAAI,cAAc,CAAC,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,IAAI,CAAC,CAAC;QACtD,IAAI,CAAC,cAAc,GAAG,IAAI,cAAc,CAAC,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,OAAO,CAAC,CAAC;QAC5D,IAAI,CAAC,gBAAgB,GAAG,IAAI,cAAc,CAAC,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,SAAS,CAAC,CAAC;IAClE,CAAC;IAED,qCAAa,GAAb;QACE,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;IAED;;OAEG;IACH,wCAAgB,GAAhB;QACE,OAAO,IAAI,CAAC,cAAc,CAAC;IAC7B,CAAC;IAED,0CAAkB,GAAlB;QACE,OAAO,IAAI,CAAC,gBAAgB,CAAC;IAC/B,CAAC;IACH,oBAAC;AAAD,CAAC,AAzBD,IAyBC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { ExactPredicate, Predicate } from './Predicate';\n\nexport interface MeterSelectorCriteria {\n name?: string;\n version?: string;\n schemaUrl?: string;\n}\n\nexport class MeterSelector {\n private _nameFilter: Predicate;\n private _versionFilter: Predicate;\n private _schemaUrlFilter: Predicate;\n\n constructor(criteria?: MeterSelectorCriteria) {\n this._nameFilter = new ExactPredicate(criteria?.name);\n this._versionFilter = new ExactPredicate(criteria?.version);\n this._schemaUrlFilter = new ExactPredicate(criteria?.schemaUrl);\n }\n\n getNameFilter() {\n return this._nameFilter;\n }\n\n /**\n * TODO: semver filter? no spec yet.\n */\n getVersionFilter() {\n return this._versionFilter;\n }\n\n getSchemaUrlFilter() {\n return this._schemaUrlFilter;\n }\n}\n"]}

View File

@@ -0,0 +1,21 @@
export interface Predicate {
match(str: string): boolean;
}
/**
* Wildcard pattern predicate, supports patterns like `*`, `foo*`, `*bar`.
*/
export declare class PatternPredicate implements Predicate {
private _matchAll;
private _regexp;
constructor(pattern: string);
match(str: string): boolean;
static escapePattern(pattern: string): string;
static hasWildcard(pattern: string): boolean;
}
export declare class ExactPredicate implements Predicate {
private _matchAll;
private _pattern?;
constructor(pattern?: string);
match(str: string): boolean;
}
//# sourceMappingURL=Predicate.d.ts.map

View File

@@ -0,0 +1,66 @@
/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// https://tc39.es/proposal-regex-escaping
// escape ^ $ \ . + ? ( ) [ ] { } |
// do not need to escape * as we interpret it as wildcard
var ESCAPE = /[\^$\\.+?()[\]{}|]/g;
/**
* Wildcard pattern predicate, supports patterns like `*`, `foo*`, `*bar`.
*/
var PatternPredicate = /** @class */ (function () {
function PatternPredicate(pattern) {
if (pattern === '*') {
this._matchAll = true;
this._regexp = /.*/;
}
else {
this._matchAll = false;
this._regexp = new RegExp(PatternPredicate.escapePattern(pattern));
}
}
PatternPredicate.prototype.match = function (str) {
if (this._matchAll) {
return true;
}
return this._regexp.test(str);
};
PatternPredicate.escapePattern = function (pattern) {
return "^" + pattern.replace(ESCAPE, '\\$&').replace('*', '.*') + "$";
};
PatternPredicate.hasWildcard = function (pattern) {
return pattern.includes('*');
};
return PatternPredicate;
}());
export { PatternPredicate };
var ExactPredicate = /** @class */ (function () {
function ExactPredicate(pattern) {
this._matchAll = pattern === undefined;
this._pattern = pattern;
}
ExactPredicate.prototype.match = function (str) {
if (this._matchAll) {
return true;
}
if (str === this._pattern) {
return true;
}
return false;
};
return ExactPredicate;
}());
export { ExactPredicate };
//# sourceMappingURL=Predicate.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"Predicate.js","sourceRoot":"","sources":["../../../src/view/Predicate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,0CAA0C;AAC1C,oCAAoC;AACpC,yDAAyD;AACzD,IAAM,MAAM,GAAG,qBAAqB,CAAC;AAMrC;;GAEG;AACH;IAIE,0BAAY,OAAe;QACzB,IAAI,OAAO,KAAK,GAAG,EAAE;YACnB,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;YACtB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;SACrB;aAAM;YACL,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC;YACvB,IAAI,CAAC,OAAO,GAAG,IAAI,MAAM,CAAC,gBAAgB,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC;SACpE;IACH,CAAC;IAED,gCAAK,GAAL,UAAM,GAAW;QACf,IAAI,IAAI,CAAC,SAAS,EAAE;YAClB,OAAO,IAAI,CAAC;SACb;QAED,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAChC,CAAC;IAEM,8BAAa,GAApB,UAAqB,OAAe;QAClC,OAAO,MAAI,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,IAAI,CAAC,MAAG,CAAC;IACnE,CAAC;IAEM,4BAAW,GAAlB,UAAmB,OAAe;QAChC,OAAO,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;IAC/B,CAAC;IACH,uBAAC;AAAD,CAAC,AA7BD,IA6BC;;AAED;IAIE,wBAAY,OAAgB;QAC1B,IAAI,CAAC,SAAS,GAAG,OAAO,KAAK,SAAS,CAAC;QACvC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IAC1B,CAAC;IAED,8BAAK,GAAL,UAAM,GAAW;QACf,IAAI,IAAI,CAAC,SAAS,EAAE;YAClB,OAAO,IAAI,CAAC;SACb;QACD,IAAI,GAAG,KAAK,IAAI,CAAC,QAAQ,EAAE;YACzB,OAAO,IAAI,CAAC;SACb;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IACH,qBAAC;AAAD,CAAC,AAlBD,IAkBC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// https://tc39.es/proposal-regex-escaping\n// escape ^ $ \\ . + ? ( ) [ ] { } |\n// do not need to escape * as we interpret it as wildcard\nconst ESCAPE = /[\\^$\\\\.+?()[\\]{}|]/g;\n\nexport interface Predicate {\n match(str: string): boolean;\n}\n\n/**\n * Wildcard pattern predicate, supports patterns like `*`, `foo*`, `*bar`.\n */\nexport class PatternPredicate implements Predicate {\n private _matchAll: boolean;\n private _regexp: RegExp;\n\n constructor(pattern: string) {\n if (pattern === '*') {\n this._matchAll = true;\n this._regexp = /.*/;\n } else {\n this._matchAll = false;\n this._regexp = new RegExp(PatternPredicate.escapePattern(pattern));\n }\n }\n\n match(str: string): boolean {\n if (this._matchAll) {\n return true;\n }\n\n return this._regexp.test(str);\n }\n\n static escapePattern(pattern: string): string {\n return `^${pattern.replace(ESCAPE, '\\\\$&').replace('*', '.*')}$`;\n }\n\n static hasWildcard(pattern: string): boolean {\n return pattern.includes('*');\n }\n}\n\nexport class ExactPredicate implements Predicate {\n private _matchAll: boolean;\n private _pattern?: string;\n\n constructor(pattern?: string) {\n this._matchAll = pattern === undefined;\n this._pattern = pattern;\n }\n\n match(str: string): boolean {\n if (this._matchAll) {\n return true;\n }\n if (str === this._pattern) {\n return true;\n }\n return false;\n }\n}\n"]}

View File

@@ -0,0 +1,8 @@
import { InstrumentDescriptor } from '../InstrumentDescriptor';
export declare function getIncompatibilityDetails(existing: InstrumentDescriptor, otherDescriptor: InstrumentDescriptor): string;
export declare function getValueTypeConflictResolutionRecipe(existing: InstrumentDescriptor, otherDescriptor: InstrumentDescriptor): string;
export declare function getUnitConflictResolutionRecipe(existing: InstrumentDescriptor, otherDescriptor: InstrumentDescriptor): string;
export declare function getTypeConflictResolutionRecipe(existing: InstrumentDescriptor, otherDescriptor: InstrumentDescriptor): string;
export declare function getDescriptionResolutionRecipe(existing: InstrumentDescriptor, otherDescriptor: InstrumentDescriptor): string;
export declare function getConflictResolutionRecipe(existing: InstrumentDescriptor, otherDescriptor: InstrumentDescriptor): string;
//# sourceMappingURL=RegistrationConflicts.d.ts.map

View File

@@ -0,0 +1,74 @@
/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export function getIncompatibilityDetails(existing, otherDescriptor) {
var incompatibility = '';
if (existing.unit !== otherDescriptor.unit) {
incompatibility += "\t- Unit '" + existing.unit + "' does not match '" + otherDescriptor.unit + "'\n";
}
if (existing.type !== otherDescriptor.type) {
incompatibility += "\t- Type '" + existing.type + "' does not match '" + otherDescriptor.type + "'\n";
}
if (existing.valueType !== otherDescriptor.valueType) {
incompatibility += "\t- Value Type '" + existing.valueType + "' does not match '" + otherDescriptor.valueType + "'\n";
}
if (existing.description !== otherDescriptor.description) {
incompatibility += "\t- Description '" + existing.description + "' does not match '" + otherDescriptor.description + "'\n";
}
return incompatibility;
}
export function getValueTypeConflictResolutionRecipe(existing, otherDescriptor) {
return "\t- use valueType '" + existing.valueType + "' on instrument creation or use an instrument name other than '" + otherDescriptor.name + "'";
}
export function getUnitConflictResolutionRecipe(existing, otherDescriptor) {
return "\t- use unit '" + existing.unit + "' on instrument creation or use an instrument name other than '" + otherDescriptor.name + "'";
}
export function getTypeConflictResolutionRecipe(existing, otherDescriptor) {
var selector = {
name: otherDescriptor.name,
type: otherDescriptor.type,
unit: otherDescriptor.unit,
};
var selectorString = JSON.stringify(selector);
return "\t- create a new view with a name other than '" + existing.name + "' and InstrumentSelector '" + selectorString + "'";
}
export function getDescriptionResolutionRecipe(existing, otherDescriptor) {
var selector = {
name: otherDescriptor.name,
type: otherDescriptor.type,
unit: otherDescriptor.unit,
};
var selectorString = JSON.stringify(selector);
return "\t- create a new view with a name other than '" + existing.name + "' and InstrumentSelector '" + selectorString + "'\n \t- OR - create a new view with the name " + existing.name + " and description '" + existing.description + "' and InstrumentSelector " + selectorString + "\n \t- OR - create a new view with the name " + otherDescriptor.name + " and description '" + existing.description + "' and InstrumentSelector " + selectorString;
}
export function getConflictResolutionRecipe(existing, otherDescriptor) {
// Conflicts that cannot be solved via views.
if (existing.valueType !== otherDescriptor.valueType) {
return getValueTypeConflictResolutionRecipe(existing, otherDescriptor);
}
if (existing.unit !== otherDescriptor.unit) {
return getUnitConflictResolutionRecipe(existing, otherDescriptor);
}
// Conflicts that can be solved via views.
if (existing.type !== otherDescriptor.type) {
// this will automatically solve possible description conflicts.
return getTypeConflictResolutionRecipe(existing, otherDescriptor);
}
if (existing.description !== otherDescriptor.description) {
return getDescriptionResolutionRecipe(existing, otherDescriptor);
}
return '';
}
//# sourceMappingURL=RegistrationConflicts.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,176 @@
import { AttributesProcessor } from './AttributesProcessor';
import { InstrumentSelector } from './InstrumentSelector';
import { MeterSelector } from './MeterSelector';
import { Aggregation } from './Aggregation';
import { InstrumentType } from '../InstrumentDescriptor';
export declare type ViewOptions = {
/**
* Alters the metric stream:
* This will be used as the name of the metrics stream.
* If not provided, the original Instrument name will be used.
*/
name?: string;
/**
* Alters the metric stream:
* This will be used as the description of the metrics stream.
* If not provided, the original Instrument description will be used by default.
*
* @example <caption>changes the description of all selected instruments to 'sample description'</caption>
* description: 'sample description'
*/
description?: string;
/**
* Alters the metric stream:
* If provided, the attributes that are not in the list will be ignored.
* If not provided, all attribute keys will be used by default.
*
* @example <caption>drops all attributes with top-level keys except for 'myAttr' and 'myOtherAttr'</caption>
* attributeKeys: ['myAttr', 'myOtherAttr']
* @example <caption>drops all attributes</caption>
* attributeKeys: []
*/
attributeKeys?: string[];
/**
* Alters the metric stream:
* Alters the {@link Aggregation} of the metric stream.
*
* @example <caption>changes the aggregation of the selected instrument(s) to ExplicitBucketHistogramAggregation</caption>
* aggregation: new ExplicitBucketHistogramAggregation([1, 10, 100])
* @example <caption>changes the aggregation of the selected instrument(s) to LastValueAggregation</caption>
* aggregation: new LastValueAggregation()
*/
aggregation?: Aggregation;
/**
* Alters the metric stream:
* Sets a limit on the number of unique attribute combinations (cardinality) that can be aggregated.
* If not provided, the default limit will be used.
*
* @example <caption>sets the cardinality limit to 1000</caption>
* aggregationCardinalityLimit: 1000
*/
aggregationCardinalityLimit?: number;
/**
* Instrument selection criteria:
* The original type of the Instrument(s).
*
* @example <caption>selects all counters</caption>
* instrumentType: InstrumentType.COUNTER
* @example <caption>selects all histograms</caption>
* instrumentType: InstrumentType.HISTOGRAM
*/
instrumentType?: InstrumentType;
/**
* Instrument selection criteria:
* Original name of the Instrument(s) with wildcard support.
*
* @example <caption>select all instruments</caption>
* instrumentName: '*'
* @example <caption>select all instruments starting with 'my.instruments.'</caption>
* instrumentName: 'my.instruments.*'
* @example <caption>select all instruments named 'my.instrument.requests' exactly</caption>
* instrumentName: 'my.instruments.requests'
*/
instrumentName?: string;
/**
* Instrument selection criteria:
* The unit of the Instrument(s).
*
* @example <caption>select all instruments with unit 'ms'</caption>
* instrumentUnit: 'ms'
*/
instrumentUnit?: string;
/**
* Instrument selection criteria:
* The name of the Meter. No wildcard support, name must match the meter exactly.
*
* @example <caption>select all meters named 'example.component.app' exactly</caption>
* meterName: 'example.component.app'
*/
meterName?: string;
/**
* Instrument selection criteria:
* The version of the Meter. No wildcard support, version must match exactly.
*
* @example
* meterVersion: '1.0.1'
*/
meterVersion?: string;
/**
* Instrument selection criteria:
* The schema URL of the Meter. No wildcard support, schema URL must match exactly.
*
* @example <caption>Select all meters with schema URL 'https://example.com/schema' exactly.</caption>
* meterSchemaUrl: 'https://example.com/schema'
*/
meterSchemaUrl?: string;
};
/**
* Can be passed to a {@link MeterProvider} to select instruments and alter their metric stream.
*/
export declare class View {
readonly name?: string;
readonly description?: string;
readonly aggregation: Aggregation;
readonly attributesProcessor: AttributesProcessor;
readonly instrumentSelector: InstrumentSelector;
readonly meterSelector: MeterSelector;
readonly aggregationCardinalityLimit?: number;
/**
* Create a new {@link View} instance.
*
* Parameters can be categorized as two types:
* Instrument selection criteria: Used to describe the instrument(s) this view will be applied to.
* Will be treated as additive (the Instrument has to meet all the provided criteria to be selected).
*
* Metric stream altering: Alter the metric stream of instruments selected by instrument selection criteria.
*
* @param viewOptions {@link ViewOptions} for altering the metric stream and instrument selection.
* @param viewOptions.name
* Alters the metric stream:
* This will be used as the name of the metrics stream.
* If not provided, the original Instrument name will be used.
* @param viewOptions.description
* Alters the metric stream:
* This will be used as the description of the metrics stream.
* If not provided, the original Instrument description will be used by default.
* @param viewOptions.attributeKeys
* Alters the metric stream:
* If provided, the attributes that are not in the list will be ignored.
* If not provided, all attribute keys will be used by default.
* @param viewOptions.aggregationCardinalityLimit
* Alters the metric stream:
* Sets a limit on the number of unique attribute combinations (cardinality) that can be aggregated.
* If not provided, the default limit of 2000 will be used.
* @param viewOptions.aggregation
* Alters the metric stream:
* Alters the {@link Aggregation} of the metric stream.
* @param viewOptions.instrumentName
* Instrument selection criteria:
* Original name of the Instrument(s) with wildcard support.
* @param viewOptions.instrumentType
* Instrument selection criteria:
* The original type of the Instrument(s).
* @param viewOptions.instrumentUnit
* Instrument selection criteria:
* The unit of the Instrument(s).
* @param viewOptions.meterName
* Instrument selection criteria:
* The name of the Meter. No wildcard support, name must match the meter exactly.
* @param viewOptions.meterVersion
* Instrument selection criteria:
* The version of the Meter. No wildcard support, version must match exactly.
* @param viewOptions.meterSchemaUrl
* Instrument selection criteria:
* The schema URL of the Meter. No wildcard support, schema URL must match exactly.
*
* @example
* // Create a view that changes the Instrument 'my.instrument' to use to an
* // ExplicitBucketHistogramAggregation with the boundaries [20, 30, 40]
* new View({
* aggregation: new ExplicitBucketHistogramAggregation([20, 30, 40]),
* instrumentName: 'my.instrument'
* })
*/
constructor(viewOptions: ViewOptions);
}
//# sourceMappingURL=View.d.ts.map

View File

@@ -0,0 +1,128 @@
/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { PatternPredicate } from './Predicate';
import { AttributesProcessor, FilteringAttributesProcessor, } from './AttributesProcessor';
import { InstrumentSelector } from './InstrumentSelector';
import { MeterSelector } from './MeterSelector';
import { Aggregation } from './Aggregation';
function isSelectorNotProvided(options) {
return (options.instrumentName == null &&
options.instrumentType == null &&
options.instrumentUnit == null &&
options.meterName == null &&
options.meterVersion == null &&
options.meterSchemaUrl == null);
}
/**
* Can be passed to a {@link MeterProvider} to select instruments and alter their metric stream.
*/
var View = /** @class */ (function () {
/**
* Create a new {@link View} instance.
*
* Parameters can be categorized as two types:
* Instrument selection criteria: Used to describe the instrument(s) this view will be applied to.
* Will be treated as additive (the Instrument has to meet all the provided criteria to be selected).
*
* Metric stream altering: Alter the metric stream of instruments selected by instrument selection criteria.
*
* @param viewOptions {@link ViewOptions} for altering the metric stream and instrument selection.
* @param viewOptions.name
* Alters the metric stream:
* This will be used as the name of the metrics stream.
* If not provided, the original Instrument name will be used.
* @param viewOptions.description
* Alters the metric stream:
* This will be used as the description of the metrics stream.
* If not provided, the original Instrument description will be used by default.
* @param viewOptions.attributeKeys
* Alters the metric stream:
* If provided, the attributes that are not in the list will be ignored.
* If not provided, all attribute keys will be used by default.
* @param viewOptions.aggregationCardinalityLimit
* Alters the metric stream:
* Sets a limit on the number of unique attribute combinations (cardinality) that can be aggregated.
* If not provided, the default limit of 2000 will be used.
* @param viewOptions.aggregation
* Alters the metric stream:
* Alters the {@link Aggregation} of the metric stream.
* @param viewOptions.instrumentName
* Instrument selection criteria:
* Original name of the Instrument(s) with wildcard support.
* @param viewOptions.instrumentType
* Instrument selection criteria:
* The original type of the Instrument(s).
* @param viewOptions.instrumentUnit
* Instrument selection criteria:
* The unit of the Instrument(s).
* @param viewOptions.meterName
* Instrument selection criteria:
* The name of the Meter. No wildcard support, name must match the meter exactly.
* @param viewOptions.meterVersion
* Instrument selection criteria:
* The version of the Meter. No wildcard support, version must match exactly.
* @param viewOptions.meterSchemaUrl
* Instrument selection criteria:
* The schema URL of the Meter. No wildcard support, schema URL must match exactly.
*
* @example
* // Create a view that changes the Instrument 'my.instrument' to use to an
* // ExplicitBucketHistogramAggregation with the boundaries [20, 30, 40]
* new View({
* aggregation: new ExplicitBucketHistogramAggregation([20, 30, 40]),
* instrumentName: 'my.instrument'
* })
*/
function View(viewOptions) {
var _a;
// If no criteria is provided, the SDK SHOULD treat it as an error.
// It is recommended that the SDK implementations fail fast.
if (isSelectorNotProvided(viewOptions)) {
throw new Error('Cannot create view with no selector arguments supplied');
}
// the SDK SHOULD NOT allow Views with a specified name to be declared with instrument selectors that
// may select more than one instrument (e.g. wild card instrument name) in the same Meter.
if (viewOptions.name != null &&
((viewOptions === null || viewOptions === void 0 ? void 0 : viewOptions.instrumentName) == null ||
PatternPredicate.hasWildcard(viewOptions.instrumentName))) {
throw new Error('Views with a specified name must be declared with an instrument selector that selects at most one instrument per meter.');
}
// Create AttributesProcessor if attributeKeys are defined set.
if (viewOptions.attributeKeys != null) {
this.attributesProcessor = new FilteringAttributesProcessor(viewOptions.attributeKeys);
}
else {
this.attributesProcessor = AttributesProcessor.Noop();
}
this.name = viewOptions.name;
this.description = viewOptions.description;
this.aggregation = (_a = viewOptions.aggregation) !== null && _a !== void 0 ? _a : Aggregation.Default();
this.instrumentSelector = new InstrumentSelector({
name: viewOptions.instrumentName,
type: viewOptions.instrumentType,
unit: viewOptions.instrumentUnit,
});
this.meterSelector = new MeterSelector({
name: viewOptions.meterName,
version: viewOptions.meterVersion,
schemaUrl: viewOptions.meterSchemaUrl,
});
this.aggregationCardinalityLimit = viewOptions.aggregationCardinalityLimit;
}
return View;
}());
export { View };
//# sourceMappingURL=View.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,11 @@
import { InstrumentationScope } from '@opentelemetry/core';
import { InstrumentDescriptor } from '../InstrumentDescriptor';
import { View } from './View';
export declare class ViewRegistry {
private _registeredViews;
addView(view: View): void;
findViews(instrument: InstrumentDescriptor, meter: InstrumentationScope): View[];
private _matchInstrument;
private _matchMeter;
}
//# sourceMappingURL=ViewRegistry.d.ts.map

View File

@@ -0,0 +1,47 @@
/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var ViewRegistry = /** @class */ (function () {
function ViewRegistry() {
this._registeredViews = [];
}
ViewRegistry.prototype.addView = function (view) {
this._registeredViews.push(view);
};
ViewRegistry.prototype.findViews = function (instrument, meter) {
var _this = this;
var views = this._registeredViews.filter(function (registeredView) {
return (_this._matchInstrument(registeredView.instrumentSelector, instrument) &&
_this._matchMeter(registeredView.meterSelector, meter));
});
return views;
};
ViewRegistry.prototype._matchInstrument = function (selector, instrument) {
return ((selector.getType() === undefined ||
instrument.type === selector.getType()) &&
selector.getNameFilter().match(instrument.name) &&
selector.getUnitFilter().match(instrument.unit));
};
ViewRegistry.prototype._matchMeter = function (selector, meter) {
return (selector.getNameFilter().match(meter.name) &&
(meter.version === undefined ||
selector.getVersionFilter().match(meter.version)) &&
(meter.schemaUrl === undefined ||
selector.getSchemaUrlFilter().match(meter.schemaUrl)));
};
return ViewRegistry;
}());
export { ViewRegistry };
//# sourceMappingURL=ViewRegistry.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"ViewRegistry.js","sourceRoot":"","sources":["../../../src/view/ViewRegistry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAQH;IAAA;QACU,qBAAgB,GAAW,EAAE,CAAC;IA4CxC,CAAC;IA1CC,8BAAO,GAAP,UAAQ,IAAU;QAChB,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACnC,CAAC;IAED,gCAAS,GAAT,UACE,UAAgC,EAChC,KAA2B;QAF7B,iBAYC;QARC,IAAM,KAAK,GAAG,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,UAAA,cAAc;YACvD,OAAO,CACL,KAAI,CAAC,gBAAgB,CAAC,cAAc,CAAC,kBAAkB,EAAE,UAAU,CAAC;gBACpE,KAAI,CAAC,WAAW,CAAC,cAAc,CAAC,aAAa,EAAE,KAAK,CAAC,CACtD,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,OAAO,KAAK,CAAC;IACf,CAAC;IAEO,uCAAgB,GAAxB,UACE,QAA4B,EAC5B,UAAgC;QAEhC,OAAO,CACL,CAAC,QAAQ,CAAC,OAAO,EAAE,KAAK,SAAS;YAC/B,UAAU,CAAC,IAAI,KAAK,QAAQ,CAAC,OAAO,EAAE,CAAC;YACzC,QAAQ,CAAC,aAAa,EAAE,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC;YAC/C,QAAQ,CAAC,aAAa,EAAE,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,CAChD,CAAC;IACJ,CAAC;IAEO,kCAAW,GAAnB,UACE,QAAuB,EACvB,KAA2B;QAE3B,OAAO,CACL,QAAQ,CAAC,aAAa,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC;YAC1C,CAAC,KAAK,CAAC,OAAO,KAAK,SAAS;gBAC1B,QAAQ,CAAC,gBAAgB,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YACnD,CAAC,KAAK,CAAC,SAAS,KAAK,SAAS;gBAC5B,QAAQ,CAAC,kBAAkB,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CACxD,CAAC;IACJ,CAAC;IACH,mBAAC;AAAD,CAAC,AA7CD,IA6CC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { InstrumentationScope } from '@opentelemetry/core';\nimport { InstrumentDescriptor } from '../InstrumentDescriptor';\nimport { InstrumentSelector } from './InstrumentSelector';\nimport { MeterSelector } from './MeterSelector';\nimport { View } from './View';\n\nexport class ViewRegistry {\n private _registeredViews: View[] = [];\n\n addView(view: View) {\n this._registeredViews.push(view);\n }\n\n findViews(\n instrument: InstrumentDescriptor,\n meter: InstrumentationScope\n ): View[] {\n const views = this._registeredViews.filter(registeredView => {\n return (\n this._matchInstrument(registeredView.instrumentSelector, instrument) &&\n this._matchMeter(registeredView.meterSelector, meter)\n );\n });\n\n return views;\n }\n\n private _matchInstrument(\n selector: InstrumentSelector,\n instrument: InstrumentDescriptor\n ): boolean {\n return (\n (selector.getType() === undefined ||\n instrument.type === selector.getType()) &&\n selector.getNameFilter().match(instrument.name) &&\n selector.getUnitFilter().match(instrument.unit)\n );\n }\n\n private _matchMeter(\n selector: MeterSelector,\n meter: InstrumentationScope\n ): boolean {\n return (\n selector.getNameFilter().match(meter.name) &&\n (meter.version === undefined ||\n selector.getVersionFilter().match(meter.version)) &&\n (meter.schemaUrl === undefined ||\n selector.getSchemaUrlFilter().match(meter.schemaUrl))\n );\n }\n}\n"]}