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,14 @@
import { Context, HrTime, Attributes } from '@opentelemetry/api';
import { FixedSizeExemplarReservoirBase } from './ExemplarReservoir';
/**
* AlignedHistogramBucketExemplarReservoir takes the same boundaries
* configuration of a Histogram. This algorithm keeps the last seen measurement
* that falls within a histogram bucket.
*/
export declare class AlignedHistogramBucketExemplarReservoir extends FixedSizeExemplarReservoirBase {
private _boundaries;
constructor(boundaries: number[]);
private _findBucketIndex;
offer(value: number, timestamp: HrTime, attributes: Attributes, ctx: Context): void;
}
//# sourceMappingURL=AlignedHistogramBucketExemplarReservoir.d.ts.map

View File

@@ -0,0 +1,40 @@
/*
* 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 { FixedSizeExemplarReservoirBase } from './ExemplarReservoir';
/**
* AlignedHistogramBucketExemplarReservoir takes the same boundaries
* configuration of a Histogram. This algorithm keeps the last seen measurement
* that falls within a histogram bucket.
*/
export class AlignedHistogramBucketExemplarReservoir extends FixedSizeExemplarReservoirBase {
constructor(boundaries) {
super(boundaries.length + 1);
this._boundaries = boundaries;
}
_findBucketIndex(value, _timestamp, _attributes, _ctx) {
for (let i = 0; i < this._boundaries.length; i++) {
if (value <= this._boundaries[i]) {
return i;
}
}
return this._boundaries.length;
}
offer(value, timestamp, attributes, ctx) {
const index = this._findBucketIndex(value, timestamp, attributes, ctx);
this._reservoirStorage[index].offer(value, timestamp, attributes, ctx);
}
}
//# sourceMappingURL=AlignedHistogramBucketExemplarReservoir.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"AlignedHistogramBucketExemplarReservoir.js","sourceRoot":"","sources":["../../../src/exemplar/AlignedHistogramBucketExemplarReservoir.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,EAAE,8BAA8B,EAAE,MAAM,qBAAqB,CAAC;AAErE;;;;GAIG;AACH,MAAM,OAAO,uCAAwC,SAAQ,8BAA8B;IAEzF,YAAY,UAAoB;QAC9B,KAAK,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QAC7B,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;IAChC,CAAC;IAEO,gBAAgB,CACtB,KAAa,EACb,UAAkB,EAClB,WAAuB,EACvB,IAAa;QAEb,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YAChD,IAAI,KAAK,IAAI,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE;gBAChC,OAAO,CAAC,CAAC;aACV;SACF;QACD,OAAO,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC;IACjC,CAAC;IAED,KAAK,CACH,KAAa,EACb,SAAiB,EACjB,UAAsB,EACtB,GAAY;QAEZ,MAAM,KAAK,GAAG,IAAI,CAAC,gBAAgB,CAAC,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,GAAG,CAAC,CAAC;QACvE,IAAI,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,GAAG,CAAC,CAAC;IACzE,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 { Context, HrTime, Attributes } from '@opentelemetry/api';\nimport { FixedSizeExemplarReservoirBase } from './ExemplarReservoir';\n\n/**\n * AlignedHistogramBucketExemplarReservoir takes the same boundaries\n * configuration of a Histogram. This algorithm keeps the last seen measurement\n * that falls within a histogram bucket.\n */\nexport class AlignedHistogramBucketExemplarReservoir extends FixedSizeExemplarReservoirBase {\n private _boundaries: number[];\n constructor(boundaries: number[]) {\n super(boundaries.length + 1);\n this._boundaries = boundaries;\n }\n\n private _findBucketIndex(\n value: number,\n _timestamp: HrTime,\n _attributes: Attributes,\n _ctx: Context\n ) {\n for (let i = 0; i < this._boundaries.length; i++) {\n if (value <= this._boundaries[i]) {\n return i;\n }\n }\n return this._boundaries.length;\n }\n\n offer(\n value: number,\n timestamp: HrTime,\n attributes: Attributes,\n ctx: Context\n ): void {\n const index = this._findBucketIndex(value, timestamp, attributes, ctx);\n this._reservoirStorage[index].offer(value, timestamp, attributes, ctx);\n }\n}\n"]}

View File

@@ -0,0 +1,6 @@
import { Context, HrTime, Attributes } from '@opentelemetry/api';
import { ExemplarFilter } from './ExemplarFilter';
export declare class AlwaysSampleExemplarFilter implements ExemplarFilter {
shouldSample(_value: number, _timestamp: HrTime, _attributes: Attributes, _ctx: Context): boolean;
}
//# sourceMappingURL=AlwaysSampleExemplarFilter.d.ts.map

View File

@@ -0,0 +1,21 @@
/*
* 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 AlwaysSampleExemplarFilter {
shouldSample(_value, _timestamp, _attributes, _ctx) {
return true;
}
}
//# sourceMappingURL=AlwaysSampleExemplarFilter.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"AlwaysSampleExemplarFilter.js","sourceRoot":"","sources":["../../../src/exemplar/AlwaysSampleExemplarFilter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAKH,MAAM,OAAO,0BAA0B;IACrC,YAAY,CACV,MAAc,EACd,UAAkB,EAClB,WAAuB,EACvB,IAAa;QAEb,OAAO,IAAI,CAAC;IACd,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 { Context, HrTime, Attributes } from '@opentelemetry/api';\nimport { ExemplarFilter } from './ExemplarFilter';\n\nexport class AlwaysSampleExemplarFilter implements ExemplarFilter {\n shouldSample(\n _value: number,\n _timestamp: HrTime,\n _attributes: Attributes,\n _ctx: Context\n ): boolean {\n return true;\n }\n}\n"]}

View File

@@ -0,0 +1,15 @@
import { HrTime, Attributes } from '@opentelemetry/api';
/**
* A representation of an exemplar, which is a sample input measurement.
* Exemplars also hold information about the environment when the measurement
* was recorded, for example the span and trace ID of the active span when the
* exemplar was recorded.
*/
export declare type Exemplar = {
filteredAttributes: Attributes;
value: number;
timestamp: HrTime;
spanId?: string;
traceId?: string;
};
//# sourceMappingURL=Exemplar.d.ts.map

View File

@@ -0,0 +1,17 @@
/*
* 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 {};
//# sourceMappingURL=Exemplar.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"Exemplar.js","sourceRoot":"","sources":["../../../src/exemplar/Exemplar.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG","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 { HrTime, Attributes } from '@opentelemetry/api';\n\n/**\n * A representation of an exemplar, which is a sample input measurement.\n * Exemplars also hold information about the environment when the measurement\n * was recorded, for example the span and trace ID of the active span when the\n * exemplar was recorded.\n */\nexport type Exemplar = {\n // The set of key/value pairs that were filtered out by the aggregator, but\n // recorded alongside the original measurement. Only key/value pairs that were\n // filtered out by the aggregator should be included\n filteredAttributes: Attributes;\n\n // The value of the measurement that was recorded.\n value: number;\n\n // timestamp is the exact time when this exemplar was recorded\n timestamp: HrTime;\n\n // (Optional) Span ID of the exemplar trace.\n // span_id may be missing if the measurement is not recorded inside a trace\n // or if the trace is not sampled.\n spanId?: string;\n\n // (Optional) Trace ID of the exemplar trace.\n // trace_id may be missing if the measurement is not recorded inside a trace\n // or if the trace is not sampled.\n traceId?: string;\n};\n"]}

View File

@@ -0,0 +1,18 @@
import { Context, HrTime, Attributes } from '@opentelemetry/api';
/**
* This interface represents a ExemplarFilter. Exemplar filters are
* used to filter measurements before attempting to store them in a
* reservoir.
*/
export interface ExemplarFilter {
/**
* Returns whether or not a reservoir should attempt to filter a measurement.
*
* @param value The value of the measurement
* @param timestamp A timestamp that best represents when the measurement was taken
* @param attributes The complete set of Attributes of the measurement
* @param ctx The Context of the measurement
*/
shouldSample(value: number, timestamp: HrTime, attributes: Attributes, ctx: Context): boolean;
}
//# sourceMappingURL=ExemplarFilter.d.ts.map

View File

@@ -0,0 +1,17 @@
/*
* 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 {};
//# sourceMappingURL=ExemplarFilter.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"ExemplarFilter.js","sourceRoot":"","sources":["../../../src/exemplar/ExemplarFilter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG","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, HrTime, Attributes } from '@opentelemetry/api';\n\n/**\n * This interface represents a ExemplarFilter. Exemplar filters are\n * used to filter measurements before attempting to store them in a\n * reservoir.\n */\nexport interface ExemplarFilter {\n /**\n * Returns whether or not a reservoir should attempt to filter a measurement.\n *\n * @param value The value of the measurement\n * @param timestamp A timestamp that best represents when the measurement was taken\n * @param attributes The complete set of Attributes of the measurement\n * @param ctx The Context of the measurement\n */\n shouldSample(\n value: number,\n timestamp: HrTime,\n attributes: Attributes,\n ctx: Context\n ): boolean;\n}\n"]}

View File

@@ -0,0 +1,43 @@
import { Context, HrTime, Attributes } from '@opentelemetry/api';
import { Exemplar } from './Exemplar';
/**
* An interface for an exemplar reservoir of samples.
*/
export interface ExemplarReservoir {
/** Offers a measurement to be sampled. */
offer(value: number, timestamp: HrTime, attributes: Attributes, ctx: Context): void;
/**
* Returns accumulated Exemplars and also resets the reservoir
* for the next sampling period
*
* @param pointAttributes The attributes associated with metric point.
*
* @returns a list of {@link Exemplar}s. Returned exemplars contain the attributes that were filtered out by the
* aggregator, but recorded alongside the original measurement.
*/
collect(pointAttributes: Attributes): Exemplar[];
}
declare class ExemplarBucket {
private value;
private attributes;
private timestamp;
private spanId?;
private traceId?;
private _offered;
offer(value: number, timestamp: HrTime, attributes: Attributes, ctx: Context): void;
collect(pointAttributes: Attributes): Exemplar | null;
}
export declare abstract class FixedSizeExemplarReservoirBase implements ExemplarReservoir {
protected _reservoirStorage: ExemplarBucket[];
protected _size: number;
constructor(size: number);
abstract offer(value: number, timestamp: HrTime, attributes: Attributes, ctx: Context): void;
maxSize(): number;
/**
* Resets the reservoir
*/
protected reset(): void;
collect(pointAttributes: Attributes): Exemplar[];
}
export {};
//# sourceMappingURL=ExemplarReservoir.d.ts.map

View File

@@ -0,0 +1,88 @@
/*
* 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 { isSpanContextValid, trace, } from '@opentelemetry/api';
class ExemplarBucket {
constructor() {
this.value = 0;
this.attributes = {};
this.timestamp = [0, 0];
this._offered = false;
}
offer(value, timestamp, attributes, ctx) {
this.value = value;
this.timestamp = timestamp;
this.attributes = attributes;
const spanContext = trace.getSpanContext(ctx);
if (spanContext && isSpanContextValid(spanContext)) {
this.spanId = spanContext.spanId;
this.traceId = spanContext.traceId;
}
this._offered = true;
}
collect(pointAttributes) {
if (!this._offered)
return null;
const currentAttributes = this.attributes;
// filter attributes
Object.keys(pointAttributes).forEach(key => {
if (pointAttributes[key] === currentAttributes[key]) {
delete currentAttributes[key];
}
});
const retVal = {
filteredAttributes: currentAttributes,
value: this.value,
timestamp: this.timestamp,
spanId: this.spanId,
traceId: this.traceId,
};
this.attributes = {};
this.value = 0;
this.timestamp = [0, 0];
this.spanId = undefined;
this.traceId = undefined;
this._offered = false;
return retVal;
}
}
export class FixedSizeExemplarReservoirBase {
constructor(size) {
this._size = size;
this._reservoirStorage = new Array(size);
for (let i = 0; i < this._size; i++) {
this._reservoirStorage[i] = new ExemplarBucket();
}
}
maxSize() {
return this._size;
}
/**
* Resets the reservoir
*/
reset() { }
collect(pointAttributes) {
const exemplars = [];
this._reservoirStorage.forEach(storageItem => {
const res = storageItem.collect(pointAttributes);
if (res !== null) {
exemplars.push(res);
}
});
this.reset();
return exemplars;
}
}
//# sourceMappingURL=ExemplarReservoir.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,6 @@
import { Context, HrTime, Attributes } from '@opentelemetry/api';
import { ExemplarFilter } from './ExemplarFilter';
export declare class NeverSampleExemplarFilter implements ExemplarFilter {
shouldSample(_value: number, _timestamp: HrTime, _attributes: Attributes, _ctx: Context): boolean;
}
//# sourceMappingURL=NeverSampleExemplarFilter.d.ts.map

View File

@@ -0,0 +1,21 @@
/*
* 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 NeverSampleExemplarFilter {
shouldSample(_value, _timestamp, _attributes, _ctx) {
return false;
}
}
//# sourceMappingURL=NeverSampleExemplarFilter.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"NeverSampleExemplarFilter.js","sourceRoot":"","sources":["../../../src/exemplar/NeverSampleExemplarFilter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAKH,MAAM,OAAO,yBAAyB;IACpC,YAAY,CACV,MAAc,EACd,UAAkB,EAClB,WAAuB,EACvB,IAAa;QAEb,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\nimport { Context, HrTime, Attributes } from '@opentelemetry/api';\nimport { ExemplarFilter } from './ExemplarFilter';\n\nexport class NeverSampleExemplarFilter implements ExemplarFilter {\n shouldSample(\n _value: number,\n _timestamp: HrTime,\n _attributes: Attributes,\n _ctx: Context\n ): boolean {\n return false;\n }\n}\n"]}

View File

@@ -0,0 +1,16 @@
import { Context, HrTime, Attributes } from '@opentelemetry/api';
import { FixedSizeExemplarReservoirBase } from './ExemplarReservoir';
/**
* Fixed size reservoir that uses equivalent of naive reservoir sampling
* algorithm to accept measurements.
*
*/
export declare class SimpleFixedSizeExemplarReservoir extends FixedSizeExemplarReservoirBase {
private _numMeasurementsSeen;
constructor(size: number);
private getRandomInt;
private _findBucketIndex;
offer(value: number, timestamp: HrTime, attributes: Attributes, ctx: Context): void;
reset(): void;
}
//# sourceMappingURL=SimpleFixedSizeExemplarReservoir.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.
*/
import { FixedSizeExemplarReservoirBase } from './ExemplarReservoir';
/**
* Fixed size reservoir that uses equivalent of naive reservoir sampling
* algorithm to accept measurements.
*
*/
export class SimpleFixedSizeExemplarReservoir extends FixedSizeExemplarReservoirBase {
constructor(size) {
super(size);
this._numMeasurementsSeen = 0;
}
getRandomInt(min, max) {
//[min, max)
return Math.floor(Math.random() * (max - min) + min);
}
_findBucketIndex(_value, _timestamp, _attributes, _ctx) {
if (this._numMeasurementsSeen < this._size)
return this._numMeasurementsSeen++;
const index = this.getRandomInt(0, ++this._numMeasurementsSeen);
return index < this._size ? index : -1;
}
offer(value, timestamp, attributes, ctx) {
const index = this._findBucketIndex(value, timestamp, attributes, ctx);
if (index !== -1) {
this._reservoirStorage[index].offer(value, timestamp, attributes, ctx);
}
}
reset() {
this._numMeasurementsSeen = 0;
}
}
//# sourceMappingURL=SimpleFixedSizeExemplarReservoir.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"SimpleFixedSizeExemplarReservoir.js","sourceRoot":"","sources":["../../../src/exemplar/SimpleFixedSizeExemplarReservoir.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,EAAE,8BAA8B,EAAE,MAAM,qBAAqB,CAAC;AAErE;;;;GAIG;AACH,MAAM,OAAO,gCAAiC,SAAQ,8BAA8B;IAElF,YAAY,IAAY;QACtB,KAAK,CAAC,IAAI,CAAC,CAAC;QACZ,IAAI,CAAC,oBAAoB,GAAG,CAAC,CAAC;IAChC,CAAC;IAEO,YAAY,CAAC,GAAW,EAAE,GAAW;QAC3C,YAAY;QACZ,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC;IACvD,CAAC;IAEO,gBAAgB,CACtB,MAAc,EACd,UAAkB,EAClB,WAAuB,EACvB,IAAa;QAEb,IAAI,IAAI,CAAC,oBAAoB,GAAG,IAAI,CAAC,KAAK;YACxC,OAAO,IAAI,CAAC,oBAAoB,EAAE,CAAC;QACrC,MAAM,KAAK,GAAG,IAAI,CAAC,YAAY,CAAC,CAAC,EAAE,EAAE,IAAI,CAAC,oBAAoB,CAAC,CAAC;QAChE,OAAO,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACzC,CAAC;IAED,KAAK,CACH,KAAa,EACb,SAAiB,EACjB,UAAsB,EACtB,GAAY;QAEZ,MAAM,KAAK,GAAG,IAAI,CAAC,gBAAgB,CAAC,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,GAAG,CAAC,CAAC;QACvE,IAAI,KAAK,KAAK,CAAC,CAAC,EAAE;YAChB,IAAI,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,GAAG,CAAC,CAAC;SACxE;IACH,CAAC;IAEQ,KAAK;QACZ,IAAI,CAAC,oBAAoB,GAAG,CAAC,CAAC;IAChC,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 { Context, HrTime, Attributes } from '@opentelemetry/api';\nimport { FixedSizeExemplarReservoirBase } from './ExemplarReservoir';\n\n/**\n * Fixed size reservoir that uses equivalent of naive reservoir sampling\n * algorithm to accept measurements.\n *\n */\nexport class SimpleFixedSizeExemplarReservoir extends FixedSizeExemplarReservoirBase {\n private _numMeasurementsSeen: number;\n constructor(size: number) {\n super(size);\n this._numMeasurementsSeen = 0;\n }\n\n private getRandomInt(min: number, max: number) {\n //[min, max)\n return Math.floor(Math.random() * (max - min) + min);\n }\n\n private _findBucketIndex(\n _value: number,\n _timestamp: HrTime,\n _attributes: Attributes,\n _ctx: Context\n ) {\n if (this._numMeasurementsSeen < this._size)\n return this._numMeasurementsSeen++;\n const index = this.getRandomInt(0, ++this._numMeasurementsSeen);\n return index < this._size ? index : -1;\n }\n\n offer(\n value: number,\n timestamp: HrTime,\n attributes: Attributes,\n ctx: Context\n ): void {\n const index = this._findBucketIndex(value, timestamp, attributes, ctx);\n if (index !== -1) {\n this._reservoirStorage[index].offer(value, timestamp, attributes, ctx);\n }\n }\n\n override reset() {\n this._numMeasurementsSeen = 0;\n }\n}\n"]}

View File

@@ -0,0 +1,6 @@
import { Context, HrTime, Attributes } from '@opentelemetry/api';
import { ExemplarFilter } from './ExemplarFilter';
export declare class WithTraceExemplarFilter implements ExemplarFilter {
shouldSample(value: number, timestamp: HrTime, attributes: Attributes, ctx: Context): boolean;
}
//# sourceMappingURL=WithTraceExemplarFilter.d.ts.map

View File

@@ -0,0 +1,25 @@
/*
* 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 { isSpanContextValid, trace, TraceFlags, } from '@opentelemetry/api';
export class WithTraceExemplarFilter {
shouldSample(value, timestamp, attributes, ctx) {
const spanContext = trace.getSpanContext(ctx);
if (!spanContext || !isSpanContextValid(spanContext))
return false;
return spanContext.traceFlags & TraceFlags.SAMPLED ? true : false;
}
}
//# sourceMappingURL=WithTraceExemplarFilter.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"WithTraceExemplarFilter.js","sourceRoot":"","sources":["../../../src/exemplar/WithTraceExemplarFilter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAGL,kBAAkB,EAClB,KAAK,EACL,UAAU,GAEX,MAAM,oBAAoB,CAAC;AAG5B,MAAM,OAAO,uBAAuB;IAClC,YAAY,CACV,KAAa,EACb,SAAiB,EACjB,UAAsB,EACtB,GAAY;QAEZ,MAAM,WAAW,GAAG,KAAK,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC;QAC9C,IAAI,CAAC,WAAW,IAAI,CAAC,kBAAkB,CAAC,WAAW,CAAC;YAAE,OAAO,KAAK,CAAC;QACnE,OAAO,WAAW,CAAC,UAAU,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC;IACpE,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 {\n Context,\n HrTime,\n isSpanContextValid,\n trace,\n TraceFlags,\n Attributes,\n} from '@opentelemetry/api';\nimport { ExemplarFilter } from './ExemplarFilter';\n\nexport class WithTraceExemplarFilter implements ExemplarFilter {\n shouldSample(\n value: number,\n timestamp: HrTime,\n attributes: Attributes,\n ctx: Context\n ): boolean {\n const spanContext = trace.getSpanContext(ctx);\n if (!spanContext || !isSpanContextValid(spanContext)) return false;\n return spanContext.traceFlags & TraceFlags.SAMPLED ? true : false;\n }\n}\n"]}

View File

@@ -0,0 +1,9 @@
export { Exemplar } from './Exemplar';
export { ExemplarFilter } from './ExemplarFilter';
export { AlwaysSampleExemplarFilter } from './AlwaysSampleExemplarFilter';
export { NeverSampleExemplarFilter } from './NeverSampleExemplarFilter';
export { WithTraceExemplarFilter } from './WithTraceExemplarFilter';
export { ExemplarReservoir, FixedSizeExemplarReservoirBase, } from './ExemplarReservoir';
export { AlignedHistogramBucketExemplarReservoir } from './AlignedHistogramBucketExemplarReservoir';
export { SimpleFixedSizeExemplarReservoir } from './SimpleFixedSizeExemplarReservoir';
//# sourceMappingURL=index.d.ts.map

View File

@@ -0,0 +1,22 @@
/*
* 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 { AlwaysSampleExemplarFilter } from './AlwaysSampleExemplarFilter';
export { NeverSampleExemplarFilter } from './NeverSampleExemplarFilter';
export { WithTraceExemplarFilter } from './WithTraceExemplarFilter';
export { FixedSizeExemplarReservoirBase, } from './ExemplarReservoir';
export { AlignedHistogramBucketExemplarReservoir } from './AlignedHistogramBucketExemplarReservoir';
export { SimpleFixedSizeExemplarReservoir } from './SimpleFixedSizeExemplarReservoir';
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/exemplar/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AACxE,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EAEL,8BAA8B,GAC/B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,uCAAuC,EAAE,MAAM,2CAA2C,CAAC;AACpG,OAAO,EAAE,gCAAgC,EAAE,MAAM,oCAAoC,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\nexport { Exemplar } from './Exemplar';\nexport { ExemplarFilter } from './ExemplarFilter';\nexport { AlwaysSampleExemplarFilter } from './AlwaysSampleExemplarFilter';\nexport { NeverSampleExemplarFilter } from './NeverSampleExemplarFilter';\nexport { WithTraceExemplarFilter } from './WithTraceExemplarFilter';\nexport {\n ExemplarReservoir,\n FixedSizeExemplarReservoirBase,\n} from './ExemplarReservoir';\nexport { AlignedHistogramBucketExemplarReservoir } from './AlignedHistogramBucketExemplarReservoir';\nexport { SimpleFixedSizeExemplarReservoir } from './SimpleFixedSizeExemplarReservoir';\n"]}