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,168 @@
/*
* 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 * 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.
*/
export class Aggregation {
static Drop() {
return DROP_AGGREGATION;
}
static Sum() {
return SUM_AGGREGATION;
}
static LastValue() {
return LAST_VALUE_AGGREGATION;
}
static Histogram() {
return HISTOGRAM_AGGREGATION;
}
static ExponentialHistogram() {
return EXPONENTIAL_HISTOGRAM_AGGREGATION;
}
static Default() {
return DEFAULT_AGGREGATION;
}
}
/**
* The default drop aggregation.
*/
export class DropAggregation extends Aggregation {
createAggregator(_instrument) {
return DropAggregation.DEFAULT_INSTANCE;
}
}
DropAggregation.DEFAULT_INSTANCE = new DropAggregator();
/**
* The default sum aggregation.
*/
export class SumAggregation extends Aggregation {
createAggregator(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);
/**
* The default last value aggregation.
*/
export class LastValueAggregation extends Aggregation {
createAggregator(_instrument) {
return LastValueAggregation.DEFAULT_INSTANCE;
}
}
LastValueAggregation.DEFAULT_INSTANCE = new LastValueAggregator();
/**
* The default histogram aggregation.
*/
export class HistogramAggregation extends Aggregation {
createAggregator(_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);
/**
* The explicit bucket histogram aggregation.
*/
export class ExplicitBucketHistogramAggregation extends Aggregation {
/**
* @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, _recordMinMax = true) {
super();
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((a, b) => a - b);
// Remove all Infinity from the boundaries.
const minusInfinityIndex = boundaries.lastIndexOf(-Infinity);
let infinityIndex = boundaries.indexOf(Infinity);
if (infinityIndex === -1) {
infinityIndex = undefined;
}
this._boundaries = boundaries.slice(minusInfinityIndex + 1, infinityIndex);
}
createAggregator(_instrument) {
return new HistogramAggregator(this._boundaries, this._recordMinMax);
}
}
export class ExponentialHistogramAggregation extends Aggregation {
constructor(_maxSize = 160, _recordMinMax = true) {
super();
this._maxSize = _maxSize;
this._recordMinMax = _recordMinMax;
}
createAggregator(_instrument) {
return new ExponentialHistogramAggregator(this._maxSize, this._recordMinMax);
}
}
/**
* The default aggregation.
*/
export class DefaultAggregation extends Aggregation {
_resolve(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;
}
createAggregator(instrument) {
return this._resolve(instrument).createAggregator(instrument);
}
}
const DROP_AGGREGATION = new DropAggregation();
const SUM_AGGREGATION = new SumAggregation();
const LAST_VALUE_AGGREGATION = new LastValueAggregation();
const HISTOGRAM_AGGREGATION = new HistogramAggregation();
const EXPONENTIAL_HISTOGRAM_AGGREGATION = new ExponentialHistogramAggregation();
const 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,49 @@
/*
* 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.
*/
/**
* 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 class AttributesProcessor {
static Noop() {
return NOOP;
}
}
export class NoopAttributesProcessor extends AttributesProcessor {
process(incoming, _context) {
return incoming;
}
}
/**
* {@link AttributesProcessor} that filters by allowed attribute names and drops any names that are not in the
* allow list.
*/
export class FilteringAttributesProcessor extends AttributesProcessor {
constructor(_allowedAttributeNames) {
super();
this._allowedAttributeNames = _allowedAttributeNames;
}
process(incoming, _context) {
const filteredAttributes = {};
Object.keys(incoming)
.filter(attributeName => this._allowedAttributeNames.includes(attributeName))
.forEach(attributeName => (filteredAttributes[attributeName] = incoming[attributeName]));
return filteredAttributes;
}
}
const 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,MAAM,OAAgB,mBAAmB;IAavC,MAAM,CAAC,IAAI;QACT,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAED,MAAM,OAAO,uBAAwB,SAAQ,mBAAmB;IAC9D,OAAO,CAAC,QAA0B,EAAE,QAAkB;QACpD,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,OAAO,4BAA6B,SAAQ,mBAAmB;IACnE,YAAoB,sBAAgC;QAClD,KAAK,EAAE,CAAC;QADU,2BAAsB,GAAtB,sBAAsB,CAAU;IAEpD,CAAC;IAED,OAAO,CAAC,QAA0B,EAAE,QAAiB;QACnD,MAAM,kBAAkB,GAAqB,EAAE,CAAC;QAChD,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC;aAClB,MAAM,CAAC,aAAa,CAAC,EAAE,CACtB,IAAI,CAAC,sBAAsB,CAAC,QAAQ,CAAC,aAAa,CAAC,CACpD;aACA,OAAO,CACN,aAAa,CAAC,EAAE,CACd,CAAC,kBAAkB,CAAC,aAAa,CAAC,GAAG,QAAQ,CAAC,aAAa,CAAC,CAAC,CAChE,CAAC;QACJ,OAAO,kBAAkB,CAAC;IAC5B,CAAC;CACF;AAED,MAAM,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,34 @@
/*
* 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';
export class InstrumentSelector {
constructor(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);
}
getType() {
return this._type;
}
getNameFilter() {
return this._nameFilter;
}
getUnitFilter() {
return this._unitFilter;
}
}
//# 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,MAAM,OAAO,kBAAkB;IAK7B,YAAY,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,OAAO;QACL,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAED,aAAa;QACX,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;IAED,aAAa;QACX,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;CACF","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,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 } from './Predicate';
export class MeterSelector {
constructor(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);
}
getNameFilter() {
return this._nameFilter;
}
/**
* TODO: semver filter? no spec yet.
*/
getVersionFilter() {
return this._versionFilter;
}
getSchemaUrlFilter() {
return this._schemaUrlFilter;
}
}
//# 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,MAAM,OAAO,aAAa;IAKxB,YAAY,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,aAAa;QACX,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;IAED;;OAEG;IACH,gBAAgB;QACd,OAAO,IAAI,CAAC,cAAc,CAAC;IAC7B,CAAC;IAED,kBAAkB;QAChB,OAAO,IAAI,CAAC,gBAAgB,CAAC;IAC/B,CAAC;CACF","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,62 @@
/*
* 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
const ESCAPE = /[\^$\\.+?()[\]{}|]/g;
/**
* Wildcard pattern predicate, supports patterns like `*`, `foo*`, `*bar`.
*/
export class PatternPredicate {
constructor(pattern) {
if (pattern === '*') {
this._matchAll = true;
this._regexp = /.*/;
}
else {
this._matchAll = false;
this._regexp = new RegExp(PatternPredicate.escapePattern(pattern));
}
}
match(str) {
if (this._matchAll) {
return true;
}
return this._regexp.test(str);
}
static escapePattern(pattern) {
return `^${pattern.replace(ESCAPE, '\\$&').replace('*', '.*')}$`;
}
static hasWildcard(pattern) {
return pattern.includes('*');
}
}
export class ExactPredicate {
constructor(pattern) {
this._matchAll = pattern === undefined;
this._pattern = pattern;
}
match(str) {
if (this._matchAll) {
return true;
}
if (str === this._pattern) {
return true;
}
return false;
}
}
//# 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,MAAM,MAAM,GAAG,qBAAqB,CAAC;AAMrC;;GAEG;AACH,MAAM,OAAO,gBAAgB;IAI3B,YAAY,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,KAAK,CAAC,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;IAED,MAAM,CAAC,aAAa,CAAC,OAAe;QAClC,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC;IACnE,CAAC;IAED,MAAM,CAAC,WAAW,CAAC,OAAe;QAChC,OAAO,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;IAC/B,CAAC;CACF;AAED,MAAM,OAAO,cAAc;IAIzB,YAAY,OAAgB;QAC1B,IAAI,CAAC,SAAS,GAAG,OAAO,KAAK,SAAS,CAAC;QACvC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IAC1B,CAAC;IAED,KAAK,CAAC,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;CACF","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,76 @@
/*
* 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) {
let 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) {
const selector = {
name: otherDescriptor.name,
type: otherDescriptor.type,
unit: otherDescriptor.unit,
};
const 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) {
const selector = {
name: otherDescriptor.name,
type: otherDescriptor.type,
unit: otherDescriptor.unit,
};
const selectorString = JSON.stringify(selector);
return `\t- create a new view with a name other than '${existing.name}' and InstrumentSelector '${selectorString}'
\t- OR - create a new view with the name ${existing.name} and description '${existing.description}' and InstrumentSelector ${selectorString}
\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,126 @@
/*
* 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.
*/
export class View {
/**
* 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) {
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;
}
}
//# 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,44 @@
/*
* 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 class ViewRegistry {
constructor() {
this._registeredViews = [];
}
addView(view) {
this._registeredViews.push(view);
}
findViews(instrument, meter) {
const views = this._registeredViews.filter(registeredView => {
return (this._matchInstrument(registeredView.instrumentSelector, instrument) &&
this._matchMeter(registeredView.meterSelector, meter));
});
return views;
}
_matchInstrument(selector, instrument) {
return ((selector.getType() === undefined ||
instrument.type === selector.getType()) &&
selector.getNameFilter().match(instrument.name) &&
selector.getUnitFilter().match(instrument.unit));
}
_matchMeter(selector, meter) {
return (selector.getNameFilter().match(meter.name) &&
(meter.version === undefined ||
selector.getVersionFilter().match(meter.version)) &&
(meter.schemaUrl === undefined ||
selector.getSchemaUrlFilter().match(meter.schemaUrl)));
}
}
//# 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,MAAM,OAAO,YAAY;IAAzB;QACU,qBAAgB,GAAW,EAAE,CAAC;IA4CxC,CAAC;IA1CC,OAAO,CAAC,IAAU;QAChB,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACnC,CAAC;IAED,SAAS,CACP,UAAgC,EAChC,KAA2B;QAE3B,MAAM,KAAK,GAAG,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,cAAc,CAAC,EAAE;YAC1D,OAAO,CACL,IAAI,CAAC,gBAAgB,CAAC,cAAc,CAAC,kBAAkB,EAAE,UAAU,CAAC;gBACpE,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC,aAAa,EAAE,KAAK,CAAC,CACtD,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,OAAO,KAAK,CAAC;IACf,CAAC;IAEO,gBAAgB,CACtB,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,WAAW,CACjB,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;CACF","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"]}