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,64 @@
/** Properties of a Resource. */
export interface IResource {
/** Resource attributes */
attributes: IKeyValue[];
/** Resource droppedAttributesCount */
droppedAttributesCount: number;
}
/** Properties of an InstrumentationScope. */
export interface IInstrumentationScope {
/** InstrumentationScope name */
name: string;
/** InstrumentationScope version */
version?: string;
/** InstrumentationScope attributes */
attributes?: IKeyValue[];
/** InstrumentationScope droppedAttributesCount */
droppedAttributesCount?: number;
}
/** Properties of a KeyValue. */
export interface IKeyValue {
/** KeyValue key */
key: string;
/** KeyValue value */
value: IAnyValue;
}
/** Properties of an AnyValue. */
export interface IAnyValue {
/** AnyValue stringValue */
stringValue?: string | null;
/** AnyValue boolValue */
boolValue?: boolean | null;
/** AnyValue intValue */
intValue?: number | null;
/** AnyValue doubleValue */
doubleValue?: number | null;
/** AnyValue arrayValue */
arrayValue?: IArrayValue;
/** AnyValue kvlistValue */
kvlistValue?: IKeyValueList;
/** AnyValue bytesValue */
bytesValue?: Uint8Array;
}
/** Properties of an ArrayValue. */
export interface IArrayValue {
/** ArrayValue values */
values: IAnyValue[];
}
/** Properties of a KeyValueList. */
export interface IKeyValueList {
/** KeyValueList values */
values: IKeyValue[];
}
export interface LongBits {
low: number;
high: number;
}
export declare type Fixed64 = LongBits | string | number;
export interface OtlpEncodingOptions {
/** Convert trace and span IDs to hex strings. */
useHex?: boolean;
/** Convert HrTime to 2 part 64 bit values. */
useLongBits?: boolean;
}
//# sourceMappingURL=internal-types.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=internal-types.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"internal-types.js","sourceRoot":"","sources":["../../../src/common/internal-types.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\n/** Properties of a Resource. */\nexport interface IResource {\n /** Resource attributes */\n attributes: IKeyValue[];\n\n /** Resource droppedAttributesCount */\n droppedAttributesCount: number;\n}\n\n/** Properties of an InstrumentationScope. */\nexport interface IInstrumentationScope {\n /** InstrumentationScope name */\n name: string;\n\n /** InstrumentationScope version */\n version?: string;\n\n /** InstrumentationScope attributes */\n attributes?: IKeyValue[];\n\n /** InstrumentationScope droppedAttributesCount */\n droppedAttributesCount?: number;\n}\n\n/** Properties of a KeyValue. */\nexport interface IKeyValue {\n /** KeyValue key */\n key: string;\n\n /** KeyValue value */\n value: IAnyValue;\n}\n\n/** Properties of an AnyValue. */\nexport interface IAnyValue {\n /** AnyValue stringValue */\n stringValue?: string | null;\n\n /** AnyValue boolValue */\n boolValue?: boolean | null;\n\n /** AnyValue intValue */\n intValue?: number | null;\n\n /** AnyValue doubleValue */\n doubleValue?: number | null;\n\n /** AnyValue arrayValue */\n arrayValue?: IArrayValue;\n\n /** AnyValue kvlistValue */\n kvlistValue?: IKeyValueList;\n\n /** AnyValue bytesValue */\n bytesValue?: Uint8Array;\n}\n\n/** Properties of an ArrayValue. */\nexport interface IArrayValue {\n /** ArrayValue values */\n values: IAnyValue[];\n}\n\n/** Properties of a KeyValueList. */\nexport interface IKeyValueList {\n /** KeyValueList values */\n values: IKeyValue[];\n}\n\nexport interface LongBits {\n low: number;\n high: number;\n}\n\nexport type Fixed64 = LongBits | string | number;\n\nexport interface OtlpEncodingOptions {\n /** Convert trace and span IDs to hex strings. */\n useHex?: boolean;\n /** Convert HrTime to 2 part 64 bit values. */\n useLongBits?: boolean;\n}\n"]}

View File

@@ -0,0 +1,10 @@
import type { IAnyValue, IInstrumentationScope, IKeyValue, IResource } from './internal-types';
import { Attributes } from '@opentelemetry/api';
import { InstrumentationScope } from '@opentelemetry/core';
import { IResource as ISdkResource } from '@opentelemetry/resources';
export declare function createResource(resource: ISdkResource): IResource;
export declare function createInstrumentationScope(scope: InstrumentationScope): IInstrumentationScope;
export declare function toAttributes(attributes: Attributes): IKeyValue[];
export declare function toKeyValue(key: string, value: unknown): IKeyValue;
export declare function toAnyValue(value: unknown): IAnyValue;
//# sourceMappingURL=internal.d.ts.map

View File

@@ -0,0 +1,64 @@
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
export function createResource(resource) {
return {
attributes: toAttributes(resource.attributes),
droppedAttributesCount: 0,
};
}
export function createInstrumentationScope(scope) {
return {
name: scope.name,
version: scope.version,
};
}
export function toAttributes(attributes) {
return Object.keys(attributes).map(function (key) { return toKeyValue(key, attributes[key]); });
}
export function toKeyValue(key, value) {
return {
key: key,
value: toAnyValue(value),
};
}
export function toAnyValue(value) {
var t = typeof value;
if (t === 'string')
return { stringValue: value };
if (t === 'number') {
if (!Number.isInteger(value))
return { doubleValue: value };
return { intValue: value };
}
if (t === 'boolean')
return { boolValue: value };
if (value instanceof Uint8Array)
return { bytesValue: value };
if (Array.isArray(value))
return { arrayValue: { values: value.map(toAnyValue) } };
if (t === 'object' && value != null)
return {
kvlistValue: {
values: Object.entries(value).map(function (_a) {
var _b = __read(_a, 2), k = _b[0], v = _b[1];
return toKeyValue(k, v);
}),
},
};
return {};
}
//# sourceMappingURL=internal.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../../../src/common/internal.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAyBA,MAAM,UAAU,cAAc,CAAC,QAAsB;IACnD,OAAO;QACL,UAAU,EAAE,YAAY,CAAC,QAAQ,CAAC,UAAU,CAAC;QAC7C,sBAAsB,EAAE,CAAC;KAC1B,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,0BAA0B,CACxC,KAA2B;IAE3B,OAAO;QACL,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,OAAO,EAAE,KAAK,CAAC,OAAO;KACvB,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,UAAsB;IACjD,OAAO,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,UAAA,GAAG,IAAI,OAAA,UAAU,CAAC,GAAG,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC,EAAhC,CAAgC,CAAC,CAAC;AAC9E,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,GAAW,EAAE,KAAc;IACpD,OAAO;QACL,GAAG,EAAE,GAAG;QACR,KAAK,EAAE,UAAU,CAAC,KAAK,CAAC;KACzB,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,KAAc;IACvC,IAAM,CAAC,GAAG,OAAO,KAAK,CAAC;IACvB,IAAI,CAAC,KAAK,QAAQ;QAAE,OAAO,EAAE,WAAW,EAAE,KAAe,EAAE,CAAC;IAC5D,IAAI,CAAC,KAAK,QAAQ,EAAE;QAClB,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC;YAAE,OAAO,EAAE,WAAW,EAAE,KAAe,EAAE,CAAC;QACtE,OAAO,EAAE,QAAQ,EAAE,KAAe,EAAE,CAAC;KACtC;IACD,IAAI,CAAC,KAAK,SAAS;QAAE,OAAO,EAAE,SAAS,EAAE,KAAgB,EAAE,CAAC;IAC5D,IAAI,KAAK,YAAY,UAAU;QAAE,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC;IAC9D,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QACtB,OAAO,EAAE,UAAU,EAAE,EAAE,MAAM,EAAE,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,EAAE,CAAC;IAC3D,IAAI,CAAC,KAAK,QAAQ,IAAI,KAAK,IAAI,IAAI;QACjC,OAAO;YACL,WAAW,EAAE;gBACX,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,KAAe,CAAC,CAAC,GAAG,CAAC,UAAC,EAAM;wBAAN,KAAA,aAAM,EAAL,CAAC,QAAA,EAAE,CAAC,QAAA;oBAChD,OAAA,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC;gBAAhB,CAAgB,CACjB;aACF;SACF,CAAC;IAEJ,OAAO,EAAE,CAAC;AACZ,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 */\nimport type {\n IAnyValue,\n IInstrumentationScope,\n IKeyValue,\n IResource,\n} from './internal-types';\nimport { Attributes } from '@opentelemetry/api';\nimport { InstrumentationScope } from '@opentelemetry/core';\nimport { IResource as ISdkResource } from '@opentelemetry/resources';\n\nexport function createResource(resource: ISdkResource): IResource {\n return {\n attributes: toAttributes(resource.attributes),\n droppedAttributesCount: 0,\n };\n}\n\nexport function createInstrumentationScope(\n scope: InstrumentationScope\n): IInstrumentationScope {\n return {\n name: scope.name,\n version: scope.version,\n };\n}\n\nexport function toAttributes(attributes: Attributes): IKeyValue[] {\n return Object.keys(attributes).map(key => toKeyValue(key, attributes[key]));\n}\n\nexport function toKeyValue(key: string, value: unknown): IKeyValue {\n return {\n key: key,\n value: toAnyValue(value),\n };\n}\n\nexport function toAnyValue(value: unknown): IAnyValue {\n const t = typeof value;\n if (t === 'string') return { stringValue: value as string };\n if (t === 'number') {\n if (!Number.isInteger(value)) return { doubleValue: value as number };\n return { intValue: value as number };\n }\n if (t === 'boolean') return { boolValue: value as boolean };\n if (value instanceof Uint8Array) return { bytesValue: value };\n if (Array.isArray(value))\n return { arrayValue: { values: value.map(toAnyValue) } };\n if (t === 'object' && value != null)\n return {\n kvlistValue: {\n values: Object.entries(value as object).map(([k, v]) =>\n toKeyValue(k, v)\n ),\n },\n };\n\n return {};\n}\n"]}

View File

@@ -0,0 +1,8 @@
import * as protobuf from 'protobufjs';
export interface ExportType<T, R = T & {
toJSON: () => unknown;
}> {
encode(message: T, writer?: protobuf.Writer): protobuf.Writer;
decode(reader: protobuf.Reader | Uint8Array, length?: number): R;
}
//# sourceMappingURL=protobuf-export-type.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=protobuf-export-type.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"protobuf-export-type.js","sourceRoot":"","sources":["../../../../src/common/protobuf/protobuf-export-type.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 * as protobuf from 'protobufjs';\n\nexport interface ExportType<T, R = T & { toJSON: () => unknown }> {\n encode(message: T, writer?: protobuf.Writer): protobuf.Writer;\n decode(reader: protobuf.Reader | Uint8Array, length?: number): R;\n}\n"]}

View File

@@ -0,0 +1,16 @@
import type { OtlpEncodingOptions, Fixed64, LongBits } from './internal-types';
import { HrTime } from '@opentelemetry/api';
export declare function hrTimeToNanos(hrTime: HrTime): bigint;
export declare function toLongBits(value: bigint): LongBits;
export declare function encodeAsLongBits(hrTime: HrTime): LongBits;
export declare function encodeAsString(hrTime: HrTime): string;
export declare type HrTimeEncodeFunction = (hrTime: HrTime) => Fixed64;
export declare type SpanContextEncodeFunction = (spanContext: string) => string | Uint8Array;
export declare type OptionalSpanContextEncodeFunction = (spanContext: string | undefined) => string | Uint8Array | undefined;
export interface Encoder {
encodeHrTime: HrTimeEncodeFunction;
encodeSpanContext: SpanContextEncodeFunction;
encodeOptionalSpanContext: OptionalSpanContextEncodeFunction;
}
export declare function getOtlpEncoder(options?: OtlpEncodingOptions): Encoder;
//# sourceMappingURL=utils.d.ts.map

View File

@@ -0,0 +1,61 @@
/*
* 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 { hexToBinary, hrTimeToNanoseconds } from '@opentelemetry/core';
export function hrTimeToNanos(hrTime) {
var NANOSECONDS = BigInt(1000000000);
return BigInt(hrTime[0]) * NANOSECONDS + BigInt(hrTime[1]);
}
export function toLongBits(value) {
var low = Number(BigInt.asUintN(32, value));
var high = Number(BigInt.asUintN(32, value >> BigInt(32)));
return { low: low, high: high };
}
export function encodeAsLongBits(hrTime) {
var nanos = hrTimeToNanos(hrTime);
return toLongBits(nanos);
}
export function encodeAsString(hrTime) {
var nanos = hrTimeToNanos(hrTime);
return nanos.toString();
}
var encodeTimestamp = typeof BigInt !== 'undefined' ? encodeAsString : hrTimeToNanoseconds;
function identity(value) {
return value;
}
function optionalHexToBinary(str) {
if (str === undefined)
return undefined;
return hexToBinary(str);
}
var DEFAULT_ENCODER = {
encodeHrTime: encodeAsLongBits,
encodeSpanContext: hexToBinary,
encodeOptionalSpanContext: optionalHexToBinary,
};
export function getOtlpEncoder(options) {
var _a, _b;
if (options === undefined) {
return DEFAULT_ENCODER;
}
var useLongBits = (_a = options.useLongBits) !== null && _a !== void 0 ? _a : true;
var useHex = (_b = options.useHex) !== null && _b !== void 0 ? _b : false;
return {
encodeHrTime: useLongBits ? encodeAsLongBits : encodeTimestamp,
encodeSpanContext: useHex ? identity : hexToBinary,
encodeOptionalSpanContext: useHex ? identity : optionalHexToBinary,
};
}
//# sourceMappingURL=utils.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/common/utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAEvE,MAAM,UAAU,aAAa,CAAC,MAAc;IAC1C,IAAM,WAAW,GAAG,MAAM,CAAC,UAAa,CAAC,CAAC;IAC1C,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;AAC7D,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,KAAa;IACtC,IAAM,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC,CAAC;IAC9C,IAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,EAAE,KAAK,IAAI,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAC7D,OAAO,EAAE,GAAG,KAAA,EAAE,IAAI,MAAA,EAAE,CAAC;AACvB,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,MAAc;IAC7C,IAAM,KAAK,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC;IACpC,OAAO,UAAU,CAAC,KAAK,CAAC,CAAC;AAC3B,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,MAAc;IAC3C,IAAM,KAAK,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC;IACpC,OAAO,KAAK,CAAC,QAAQ,EAAE,CAAC;AAC1B,CAAC;AAED,IAAM,eAAe,GACnB,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,mBAAmB,CAAC;AAgBvE,SAAS,QAAQ,CAAI,KAAQ;IAC3B,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,mBAAmB,CAAC,GAAuB;IAClD,IAAI,GAAG,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IACxC,OAAO,WAAW,CAAC,GAAG,CAAC,CAAC;AAC1B,CAAC;AAED,IAAM,eAAe,GAAY;IAC/B,YAAY,EAAE,gBAAgB;IAC9B,iBAAiB,EAAE,WAAW;IAC9B,yBAAyB,EAAE,mBAAmB;CAC/C,CAAC;AAEF,MAAM,UAAU,cAAc,CAAC,OAA6B;;IAC1D,IAAI,OAAO,KAAK,SAAS,EAAE;QACzB,OAAO,eAAe,CAAC;KACxB;IAED,IAAM,WAAW,GAAG,MAAA,OAAO,CAAC,WAAW,mCAAI,IAAI,CAAC;IAChD,IAAM,MAAM,GAAG,MAAA,OAAO,CAAC,MAAM,mCAAI,KAAK,CAAC;IACvC,OAAO;QACL,YAAY,EAAE,WAAW,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,eAAe;QAC9D,iBAAiB,EAAE,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,WAAW;QAClD,yBAAyB,EAAE,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,mBAAmB;KACnE,CAAC;AACJ,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 type { OtlpEncodingOptions, Fixed64, LongBits } from './internal-types';\nimport { HrTime } from '@opentelemetry/api';\nimport { hexToBinary, hrTimeToNanoseconds } from '@opentelemetry/core';\n\nexport function hrTimeToNanos(hrTime: HrTime): bigint {\n const NANOSECONDS = BigInt(1_000_000_000);\n return BigInt(hrTime[0]) * NANOSECONDS + BigInt(hrTime[1]);\n}\n\nexport function toLongBits(value: bigint): LongBits {\n const low = Number(BigInt.asUintN(32, value));\n const high = Number(BigInt.asUintN(32, value >> BigInt(32)));\n return { low, high };\n}\n\nexport function encodeAsLongBits(hrTime: HrTime): LongBits {\n const nanos = hrTimeToNanos(hrTime);\n return toLongBits(nanos);\n}\n\nexport function encodeAsString(hrTime: HrTime): string {\n const nanos = hrTimeToNanos(hrTime);\n return nanos.toString();\n}\n\nconst encodeTimestamp =\n typeof BigInt !== 'undefined' ? encodeAsString : hrTimeToNanoseconds;\n\nexport type HrTimeEncodeFunction = (hrTime: HrTime) => Fixed64;\nexport type SpanContextEncodeFunction = (\n spanContext: string\n) => string | Uint8Array;\nexport type OptionalSpanContextEncodeFunction = (\n spanContext: string | undefined\n) => string | Uint8Array | undefined;\n\nexport interface Encoder {\n encodeHrTime: HrTimeEncodeFunction;\n encodeSpanContext: SpanContextEncodeFunction;\n encodeOptionalSpanContext: OptionalSpanContextEncodeFunction;\n}\n\nfunction identity<T>(value: T): T {\n return value;\n}\n\nfunction optionalHexToBinary(str: string | undefined): Uint8Array | undefined {\n if (str === undefined) return undefined;\n return hexToBinary(str);\n}\n\nconst DEFAULT_ENCODER: Encoder = {\n encodeHrTime: encodeAsLongBits,\n encodeSpanContext: hexToBinary,\n encodeOptionalSpanContext: optionalHexToBinary,\n};\n\nexport function getOtlpEncoder(options?: OtlpEncodingOptions): Encoder {\n if (options === undefined) {\n return DEFAULT_ENCODER;\n }\n\n const useLongBits = options.useLongBits ?? true;\n const useHex = options.useHex ?? false;\n return {\n encodeHrTime: useLongBits ? encodeAsLongBits : encodeTimestamp,\n encodeSpanContext: useHex ? identity : hexToBinary,\n encodeOptionalSpanContext: useHex ? identity : optionalHexToBinary,\n };\n}\n"]}

View File

@@ -0,0 +1,4 @@
export = $root;
declare var $root: $protobuf.Root;
import $protobuf = require("protobufjs/minimal");
//# sourceMappingURL=root.d.ts.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,8 @@
/**
* Serializes and deserializes the OTLP request/response to and from {@link Uint8Array}
*/
export interface ISerializer<Request, Response> {
serializeRequest(request: Request): Uint8Array | undefined;
deserializeResponse(data: Uint8Array): Response;
}
//# sourceMappingURL=i-serializer.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=i-serializer.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"i-serializer.js","sourceRoot":"","sources":["../../src/i-serializer.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\n/**\n * Serializes and deserializes the OTLP request/response to and from {@link Uint8Array}\n */\nexport interface ISerializer<Request, Response> {\n serializeRequest(request: Request): Uint8Array | undefined;\n deserializeResponse(data: Uint8Array): Response;\n}\n"]}

View File

@@ -0,0 +1,11 @@
export { IExportMetricsPartialSuccess, IExportMetricsServiceResponse, } from './metrics';
export { IExportTracePartialSuccess, IExportTraceServiceResponse, } from './trace';
export { IExportLogsServiceResponse, IExportLogsPartialSuccess } from './logs';
export { ProtobufLogsSerializer } from './logs/protobuf';
export { ProtobufMetricsSerializer } from './metrics/protobuf';
export { ProtobufTraceSerializer } from './trace/protobuf';
export { JsonLogsSerializer } from './logs/json';
export { JsonMetricsSerializer } from './metrics/json';
export { JsonTraceSerializer } from './trace/json';
export { ISerializer } from './i-serializer';
//# 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 { ProtobufLogsSerializer } from './logs/protobuf';
export { ProtobufMetricsSerializer } from './metrics/protobuf';
export { ProtobufTraceSerializer } from './trace/protobuf';
export { JsonLogsSerializer } from './logs/json';
export { JsonMetricsSerializer } from './metrics/json';
export { JsonTraceSerializer } from './trace/json';
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAYH,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAE3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,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 {\n IExportMetricsPartialSuccess,\n IExportMetricsServiceResponse,\n} from './metrics';\nexport {\n IExportTracePartialSuccess,\n IExportTraceServiceResponse,\n} from './trace';\nexport { IExportLogsServiceResponse, IExportLogsPartialSuccess } from './logs';\n\nexport { ProtobufLogsSerializer } from './logs/protobuf';\nexport { ProtobufMetricsSerializer } from './metrics/protobuf';\nexport { ProtobufTraceSerializer } from './trace/protobuf';\n\nexport { JsonLogsSerializer } from './logs/json';\nexport { JsonMetricsSerializer } from './metrics/json';\nexport { JsonTraceSerializer } from './trace/json';\n\nexport { ISerializer } from './i-serializer';\n"]}

View File

@@ -0,0 +1,11 @@
export interface IExportMetricsServiceResponse {
/** ExportMetricsServiceResponse partialSuccess */
partialSuccess?: IExportMetricsPartialSuccess;
}
export interface IExportMetricsPartialSuccess {
/** ExportMetricsPartialSuccess rejectedDataPoints */
rejectedDataPoints?: number;
/** ExportMetricsPartialSuccess errorMessage */
errorMessage?: string;
}
//# sourceMappingURL=export-response.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=export-response.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"export-response.js","sourceRoot":"","sources":["../../../src/metrics/export-response.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\nexport interface IExportMetricsServiceResponse {\n /** ExportMetricsServiceResponse partialSuccess */\n partialSuccess?: IExportMetricsPartialSuccess;\n}\n\nexport interface IExportMetricsPartialSuccess {\n /** ExportMetricsPartialSuccess rejectedDataPoints */\n rejectedDataPoints?: number;\n\n /** ExportMetricsPartialSuccess errorMessage */\n errorMessage?: string;\n}\n"]}

View File

@@ -0,0 +1,2 @@
export { IExportMetricsPartialSuccess, IExportMetricsServiceResponse, } from './export-response';
//# sourceMappingURL=index.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=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/metrics/index.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\n// IMPORTANT: exports added here are public\nexport {\n IExportMetricsPartialSuccess,\n IExportMetricsServiceResponse,\n} from './export-response';\n"]}

View File

@@ -0,0 +1,263 @@
import { Fixed64, IInstrumentationScope, IKeyValue, IResource } from '../common/internal-types';
/** Properties of an ExportMetricsServiceRequest. */
export interface IExportMetricsServiceRequest {
/** ExportMetricsServiceRequest resourceMetrics */
resourceMetrics: IResourceMetrics[];
}
/** Properties of a ResourceMetrics. */
export interface IResourceMetrics {
/** ResourceMetrics resource */
resource?: IResource;
/** ResourceMetrics scopeMetrics */
scopeMetrics: IScopeMetrics[];
/** ResourceMetrics schemaUrl */
schemaUrl?: string;
}
/** Properties of an IScopeMetrics. */
export interface IScopeMetrics {
/** ScopeMetrics scope */
scope?: IInstrumentationScope;
/** ScopeMetrics metrics */
metrics: IMetric[];
/** ScopeMetrics schemaUrl */
schemaUrl?: string;
}
/** Properties of a Metric. */
export interface IMetric {
/** Metric name */
name: string;
/** Metric description */
description?: string;
/** Metric unit */
unit?: string;
/** Metric gauge */
gauge?: IGauge;
/** Metric sum */
sum?: ISum;
/** Metric histogram */
histogram?: IHistogram;
/** Metric exponentialHistogram */
exponentialHistogram?: IExponentialHistogram;
/** Metric summary */
summary?: ISummary;
}
/** Properties of a Gauge. */
export interface IGauge {
/** Gauge dataPoints */
dataPoints: INumberDataPoint[];
}
/** Properties of a Sum. */
export interface ISum {
/** Sum dataPoints */
dataPoints: INumberDataPoint[];
/** Sum aggregationTemporality */
aggregationTemporality: EAggregationTemporality;
/** Sum isMonotonic */
isMonotonic?: boolean | null;
}
/** Properties of a Histogram. */
export interface IHistogram {
/** Histogram dataPoints */
dataPoints: IHistogramDataPoint[];
/** Histogram aggregationTemporality */
aggregationTemporality?: EAggregationTemporality;
}
/** Properties of an ExponentialHistogram. */
export interface IExponentialHistogram {
/** ExponentialHistogram dataPoints */
dataPoints: IExponentialHistogramDataPoint[];
/** ExponentialHistogram aggregationTemporality */
aggregationTemporality?: EAggregationTemporality;
}
/** Properties of a Summary. */
export interface ISummary {
/** Summary dataPoints */
dataPoints: ISummaryDataPoint[];
}
/** Properties of a NumberDataPoint. */
export interface INumberDataPoint {
/** NumberDataPoint attributes */
attributes: IKeyValue[];
/** NumberDataPoint startTimeUnixNano */
startTimeUnixNano?: Fixed64;
/** NumberDataPoint timeUnixNano */
timeUnixNano?: Fixed64;
/** NumberDataPoint asDouble */
asDouble?: number | null;
/** NumberDataPoint asInt */
asInt?: number;
/** NumberDataPoint exemplars */
exemplars?: IExemplar[];
/** NumberDataPoint flags */
flags?: number;
}
/** Properties of a HistogramDataPoint. */
export interface IHistogramDataPoint {
/** HistogramDataPoint attributes */
attributes?: IKeyValue[];
/** HistogramDataPoint startTimeUnixNano */
startTimeUnixNano?: Fixed64;
/** HistogramDataPoint timeUnixNano */
timeUnixNano?: Fixed64;
/** HistogramDataPoint count */
count?: number;
/** HistogramDataPoint sum */
sum?: number;
/** HistogramDataPoint bucketCounts */
bucketCounts?: number[];
/** HistogramDataPoint explicitBounds */
explicitBounds?: number[];
/** HistogramDataPoint exemplars */
exemplars?: IExemplar[];
/** HistogramDataPoint flags */
flags?: number;
/** HistogramDataPoint min */
min?: number;
/** HistogramDataPoint max */
max?: number;
}
/** Properties of an ExponentialHistogramDataPoint. */
export interface IExponentialHistogramDataPoint {
/** ExponentialHistogramDataPoint attributes */
attributes?: IKeyValue[];
/** ExponentialHistogramDataPoint startTimeUnixNano */
startTimeUnixNano?: Fixed64;
/** ExponentialHistogramDataPoint timeUnixNano */
timeUnixNano?: Fixed64;
/** ExponentialHistogramDataPoint count */
count?: number;
/** ExponentialHistogramDataPoint sum */
sum?: number;
/** ExponentialHistogramDataPoint scale */
scale?: number;
/** ExponentialHistogramDataPoint zeroCount */
zeroCount?: number;
/** ExponentialHistogramDataPoint positive */
positive?: IBuckets;
/** ExponentialHistogramDataPoint negative */
negative?: IBuckets;
/** ExponentialHistogramDataPoint flags */
flags?: number;
/** ExponentialHistogramDataPoint exemplars */
exemplars?: IExemplar[];
/** ExponentialHistogramDataPoint min */
min?: number;
/** ExponentialHistogramDataPoint max */
max?: number;
}
/** Properties of a SummaryDataPoint. */
export interface ISummaryDataPoint {
/** SummaryDataPoint attributes */
attributes?: IKeyValue[];
/** SummaryDataPoint startTimeUnixNano */
startTimeUnixNano?: number;
/** SummaryDataPoint timeUnixNano */
timeUnixNano?: string;
/** SummaryDataPoint count */
count?: number;
/** SummaryDataPoint sum */
sum?: number;
/** SummaryDataPoint quantileValues */
quantileValues?: IValueAtQuantile[];
/** SummaryDataPoint flags */
flags?: number;
}
/** Properties of a ValueAtQuantile. */
export interface IValueAtQuantile {
/** ValueAtQuantile quantile */
quantile?: number;
/** ValueAtQuantile value */
value?: number;
}
/** Properties of a Buckets. */
export interface IBuckets {
/** Buckets offset */
offset?: number;
/** Buckets bucketCounts */
bucketCounts?: number[];
}
/** Properties of an Exemplar. */
export interface IExemplar {
/** Exemplar filteredAttributes */
filteredAttributes?: IKeyValue[];
/** Exemplar timeUnixNano */
timeUnixNano?: string;
/** Exemplar asDouble */
asDouble?: number;
/** Exemplar asInt */
asInt?: number;
/** Exemplar spanId */
spanId?: string | Uint8Array;
/** Exemplar traceId */
traceId?: string | Uint8Array;
}
/**
* AggregationTemporality defines how a metric aggregator reports aggregated
* values. It describes how those values relate to the time interval over
* which they are aggregated.
*/
export declare const enum EAggregationTemporality {
AGGREGATION_TEMPORALITY_UNSPECIFIED = 0,
/** DELTA is an AggregationTemporality for a metric aggregator which reports
changes since last report time. Successive metrics contain aggregation of
values from continuous and non-overlapping intervals.
The values for a DELTA metric are based only on the time interval
associated with one measurement cycle. There is no dependency on
previous measurements like is the case for CUMULATIVE metrics.
For example, consider a system measuring the number of requests that
it receives and reports the sum of these requests every second as a
DELTA metric:
1. The system starts receiving at time=t_0.
2. A request is received, the system measures 1 request.
3. A request is received, the system measures 1 request.
4. A request is received, the system measures 1 request.
5. The 1 second collection cycle ends. A metric is exported for the
number of requests received over the interval of time t_0 to
t_0+1 with a value of 3.
6. A request is received, the system measures 1 request.
7. A request is received, the system measures 1 request.
8. The 1 second collection cycle ends. A metric is exported for the
number of requests received over the interval of time t_0+1 to
t_0+2 with a value of 2. */
AGGREGATION_TEMPORALITY_DELTA = 1,
/** CUMULATIVE is an AggregationTemporality for a metric aggregator which
reports changes since a fixed start time. This means that current values
of a CUMULATIVE metric depend on all previous measurements since the
start time. Because of this, the sender is required to retain this state
in some form. If this state is lost or invalidated, the CUMULATIVE metric
values MUST be reset and a new fixed start time following the last
reported measurement time sent MUST be used.
For example, consider a system measuring the number of requests that
it receives and reports the sum of these requests every second as a
CUMULATIVE metric:
1. The system starts receiving at time=t_0.
2. A request is received, the system measures 1 request.
3. A request is received, the system measures 1 request.
4. A request is received, the system measures 1 request.
5. The 1 second collection cycle ends. A metric is exported for the
number of requests received over the interval of time t_0 to
t_0+1 with a value of 3.
6. A request is received, the system measures 1 request.
7. A request is received, the system measures 1 request.
8. The 1 second collection cycle ends. A metric is exported for the
number of requests received over the interval of time t_0 to
t_0+2 with a value of 5.
9. The system experiences a fault and loses state.
10. The system recovers and resumes receiving at time=t_1.
11. A request is received, the system measures 1 request.
12. The 1 second collection cycle ends. A metric is exported for the
number of requests received over the interval of time t_1 to
t_0+1 with a value of 1.
Note: Even though, when reporting changes since last report time, using
CUMULATIVE is valid, it is not recommended. This may cause problems for
systems that do not use start_time to determine when the aggregation
value was reset (e.g. Prometheus). */
AGGREGATION_TEMPORALITY_CUMULATIVE = 2
}
//# sourceMappingURL=internal-types.d.ts.map

View File

@@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=internal-types.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,9 @@
import type { OtlpEncodingOptions } from '../common/internal-types';
import { MetricData, ResourceMetrics, ScopeMetrics } from '@opentelemetry/sdk-metrics';
import { IExportMetricsServiceRequest, IMetric, IResourceMetrics, IScopeMetrics } from './internal-types';
import { Encoder } from '../common/utils';
export declare function toResourceMetrics(resourceMetrics: ResourceMetrics, options?: OtlpEncodingOptions): IResourceMetrics;
export declare function toScopeMetrics(scopeMetrics: ScopeMetrics[], encoder: Encoder): IScopeMetrics[];
export declare function toMetric(metricData: MetricData, encoder: Encoder): IMetric;
export declare function createExportMetricsServiceRequest(resourceMetrics: ResourceMetrics[], options?: OtlpEncodingOptions): IExportMetricsServiceRequest;
//# sourceMappingURL=internal.d.ts.map

View File

@@ -0,0 +1,131 @@
import { ValueType } from '@opentelemetry/api';
import { AggregationTemporality, DataPointType, } from '@opentelemetry/sdk-metrics';
import { getOtlpEncoder } from '../common/utils';
import { createInstrumentationScope, createResource, toAttributes, } from '../common/internal';
export function toResourceMetrics(resourceMetrics, options) {
var encoder = getOtlpEncoder(options);
return {
resource: createResource(resourceMetrics.resource),
schemaUrl: undefined,
scopeMetrics: toScopeMetrics(resourceMetrics.scopeMetrics, encoder),
};
}
export function toScopeMetrics(scopeMetrics, encoder) {
return Array.from(scopeMetrics.map(function (metrics) { return ({
scope: createInstrumentationScope(metrics.scope),
metrics: metrics.metrics.map(function (metricData) { return toMetric(metricData, encoder); }),
schemaUrl: metrics.scope.schemaUrl,
}); }));
}
export function toMetric(metricData, encoder) {
var out = {
name: metricData.descriptor.name,
description: metricData.descriptor.description,
unit: metricData.descriptor.unit,
};
var aggregationTemporality = toAggregationTemporality(metricData.aggregationTemporality);
switch (metricData.dataPointType) {
case DataPointType.SUM:
out.sum = {
aggregationTemporality: aggregationTemporality,
isMonotonic: metricData.isMonotonic,
dataPoints: toSingularDataPoints(metricData, encoder),
};
break;
case DataPointType.GAUGE:
out.gauge = {
dataPoints: toSingularDataPoints(metricData, encoder),
};
break;
case DataPointType.HISTOGRAM:
out.histogram = {
aggregationTemporality: aggregationTemporality,
dataPoints: toHistogramDataPoints(metricData, encoder),
};
break;
case DataPointType.EXPONENTIAL_HISTOGRAM:
out.exponentialHistogram = {
aggregationTemporality: aggregationTemporality,
dataPoints: toExponentialHistogramDataPoints(metricData, encoder),
};
break;
}
return out;
}
function toSingularDataPoint(dataPoint, valueType, encoder) {
var out = {
attributes: toAttributes(dataPoint.attributes),
startTimeUnixNano: encoder.encodeHrTime(dataPoint.startTime),
timeUnixNano: encoder.encodeHrTime(dataPoint.endTime),
};
switch (valueType) {
case ValueType.INT:
out.asInt = dataPoint.value;
break;
case ValueType.DOUBLE:
out.asDouble = dataPoint.value;
break;
}
return out;
}
function toSingularDataPoints(metricData, encoder) {
return metricData.dataPoints.map(function (dataPoint) {
return toSingularDataPoint(dataPoint, metricData.descriptor.valueType, encoder);
});
}
function toHistogramDataPoints(metricData, encoder) {
return metricData.dataPoints.map(function (dataPoint) {
var histogram = dataPoint.value;
return {
attributes: toAttributes(dataPoint.attributes),
bucketCounts: histogram.buckets.counts,
explicitBounds: histogram.buckets.boundaries,
count: histogram.count,
sum: histogram.sum,
min: histogram.min,
max: histogram.max,
startTimeUnixNano: encoder.encodeHrTime(dataPoint.startTime),
timeUnixNano: encoder.encodeHrTime(dataPoint.endTime),
};
});
}
function toExponentialHistogramDataPoints(metricData, encoder) {
return metricData.dataPoints.map(function (dataPoint) {
var histogram = dataPoint.value;
return {
attributes: toAttributes(dataPoint.attributes),
count: histogram.count,
min: histogram.min,
max: histogram.max,
sum: histogram.sum,
positive: {
offset: histogram.positive.offset,
bucketCounts: histogram.positive.bucketCounts,
},
negative: {
offset: histogram.negative.offset,
bucketCounts: histogram.negative.bucketCounts,
},
scale: histogram.scale,
zeroCount: histogram.zeroCount,
startTimeUnixNano: encoder.encodeHrTime(dataPoint.startTime),
timeUnixNano: encoder.encodeHrTime(dataPoint.endTime),
};
});
}
function toAggregationTemporality(temporality) {
switch (temporality) {
case AggregationTemporality.DELTA:
return 1 /* AGGREGATION_TEMPORALITY_DELTA */;
case AggregationTemporality.CUMULATIVE:
return 2 /* AGGREGATION_TEMPORALITY_CUMULATIVE */;
}
}
export function createExportMetricsServiceRequest(resourceMetrics, options) {
return {
resourceMetrics: resourceMetrics.map(function (metrics) {
return toResourceMetrics(metrics, options);
}),
};
}
//# sourceMappingURL=internal.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,2 @@
export { JsonMetricsSerializer } from './metrics';
//# sourceMappingURL=index.d.ts.map

View File

@@ -0,0 +1,18 @@
/*
* 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.
*/
// IMPORTANT: exports added here are public
export { JsonMetricsSerializer } from './metrics';
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/metrics/json/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,2CAA2C;AAC3C,OAAO,EAAE,qBAAqB,EAAE,MAAM,WAAW,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\n// IMPORTANT: exports added here are public\nexport { JsonMetricsSerializer } from './metrics';\n"]}

View File

@@ -0,0 +1,5 @@
import { ISerializer } from '../../i-serializer';
import { ResourceMetrics } from '@opentelemetry/sdk-metrics';
import { IExportMetricsServiceResponse } from '../export-response';
export declare const JsonMetricsSerializer: ISerializer<ResourceMetrics, IExportMetricsServiceResponse>;
//# sourceMappingURL=metrics.d.ts.map

View File

@@ -0,0 +1,15 @@
import { createExportMetricsServiceRequest } from '../internal';
export var JsonMetricsSerializer = {
serializeRequest: function (arg) {
var request = createExportMetricsServiceRequest([arg], {
useLongBits: false,
});
var encoder = new TextEncoder();
return encoder.encode(JSON.stringify(request));
},
deserializeResponse: function (arg) {
var decoder = new TextDecoder();
return JSON.parse(decoder.decode(arg));
},
};
//# sourceMappingURL=metrics.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"metrics.js","sourceRoot":"","sources":["../../../../src/metrics/json/metrics.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,iCAAiC,EAAE,MAAM,aAAa,CAAC;AAGhE,MAAM,CAAC,IAAM,qBAAqB,GAG9B;IACF,gBAAgB,EAAE,UAAC,GAAoB;QACrC,IAAM,OAAO,GAAG,iCAAiC,CAAC,CAAC,GAAG,CAAC,EAAE;YACvD,WAAW,EAAE,KAAK;SACnB,CAAC,CAAC;QACH,IAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;QAClC,OAAO,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC;IACjD,CAAC;IACD,mBAAmB,EAAE,UAAC,GAAe;QACnC,IAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;QAClC,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAkC,CAAC;IAC1E,CAAC;CACF,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 */\nimport { ISerializer } from '../../i-serializer';\nimport { ResourceMetrics } from '@opentelemetry/sdk-metrics';\nimport { createExportMetricsServiceRequest } from '../internal';\nimport { IExportMetricsServiceResponse } from '../export-response';\n\nexport const JsonMetricsSerializer: ISerializer<\n ResourceMetrics,\n IExportMetricsServiceResponse\n> = {\n serializeRequest: (arg: ResourceMetrics) => {\n const request = createExportMetricsServiceRequest([arg], {\n useLongBits: false,\n });\n const encoder = new TextEncoder();\n return encoder.encode(JSON.stringify(request));\n },\n deserializeResponse: (arg: Uint8Array) => {\n const decoder = new TextDecoder();\n return JSON.parse(decoder.decode(arg)) as IExportMetricsServiceResponse;\n },\n};\n"]}

View File

@@ -0,0 +1,2 @@
export { ProtobufMetricsSerializer } from './metrics';
//# sourceMappingURL=index.d.ts.map

View File

@@ -0,0 +1,18 @@
/*
* 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.
*/
// IMPORTANT: exports added here are public
export { ProtobufMetricsSerializer } from './metrics';
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/metrics/protobuf/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,2CAA2C;AAC3C,OAAO,EAAE,yBAAyB,EAAE,MAAM,WAAW,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\n// IMPORTANT: exports added here are public\nexport { ProtobufMetricsSerializer } from './metrics';\n"]}

View File

@@ -0,0 +1,5 @@
import { ISerializer } from '../../i-serializer';
import { ResourceMetrics } from '@opentelemetry/sdk-metrics';
import { IExportMetricsServiceResponse } from '../export-response';
export declare const ProtobufMetricsSerializer: ISerializer<ResourceMetrics, IExportMetricsServiceResponse>;
//# sourceMappingURL=metrics.d.ts.map

View File

@@ -0,0 +1,31 @@
/*
* 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 root from '../../generated/root';
import { createExportMetricsServiceRequest } from '../internal';
var metricsResponseType = root.opentelemetry.proto.collector.metrics.v1
.ExportMetricsServiceResponse;
var metricsRequestType = root.opentelemetry.proto.collector.metrics.v1
.ExportMetricsServiceRequest;
export var ProtobufMetricsSerializer = {
serializeRequest: function (arg) {
var request = createExportMetricsServiceRequest([arg]);
return metricsRequestType.encode(request).finish();
},
deserializeResponse: function (arg) {
return metricsResponseType.decode(arg);
},
};
//# sourceMappingURL=metrics.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"metrics.js","sourceRoot":"","sources":["../../../../src/metrics/protobuf/metrics.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,IAAI,MAAM,sBAAsB,CAAC;AAI7C,OAAO,EAAE,iCAAiC,EAAE,MAAM,aAAa,CAAC;AAIhE,IAAM,mBAAmB,GAAG,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE;KACtE,4BAAyE,CAAC;AAE7E,IAAM,kBAAkB,GAAG,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE;KACrE,2BAAuE,CAAC;AAE3E,MAAM,CAAC,IAAM,yBAAyB,GAGlC;IACF,gBAAgB,EAAE,UAAC,GAAoB;QACrC,IAAM,OAAO,GAAG,iCAAiC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;QACzD,OAAO,kBAAkB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,CAAC;IACrD,CAAC;IACD,mBAAmB,EAAE,UAAC,GAAe;QACnC,OAAO,mBAAmB,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACzC,CAAC;CACF,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 * as root from '../../generated/root';\nimport { ISerializer } from '../../i-serializer';\nimport { IExportMetricsServiceRequest } from '../internal-types';\nimport { ExportType } from '../../common/protobuf/protobuf-export-type';\nimport { createExportMetricsServiceRequest } from '../internal';\nimport { ResourceMetrics } from '@opentelemetry/sdk-metrics';\nimport { IExportMetricsServiceResponse } from '../export-response';\n\nconst metricsResponseType = root.opentelemetry.proto.collector.metrics.v1\n .ExportMetricsServiceResponse as ExportType<IExportMetricsServiceResponse>;\n\nconst metricsRequestType = root.opentelemetry.proto.collector.metrics.v1\n .ExportMetricsServiceRequest as ExportType<IExportMetricsServiceRequest>;\n\nexport const ProtobufMetricsSerializer: ISerializer<\n ResourceMetrics,\n IExportMetricsServiceResponse\n> = {\n serializeRequest: (arg: ResourceMetrics) => {\n const request = createExportMetricsServiceRequest([arg]);\n return metricsRequestType.encode(request).finish();\n },\n deserializeResponse: (arg: Uint8Array) => {\n return metricsResponseType.decode(arg);\n },\n};\n"]}

View File

@@ -0,0 +1,11 @@
export interface IExportTraceServiceResponse {
/** ExportTraceServiceResponse partialSuccess */
partialSuccess?: IExportTracePartialSuccess;
}
export interface IExportTracePartialSuccess {
/** ExportLogsServiceResponse rejectedLogRecords */
rejectedSpans?: number;
/** ExportLogsServiceResponse errorMessage */
errorMessage?: string;
}
//# sourceMappingURL=export-response.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=export-response.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"export-response.js","sourceRoot":"","sources":["../../../src/trace/export-response.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\nexport interface IExportTraceServiceResponse {\n /** ExportTraceServiceResponse partialSuccess */\n partialSuccess?: IExportTracePartialSuccess;\n}\n\nexport interface IExportTracePartialSuccess {\n /** ExportLogsServiceResponse rejectedLogRecords */\n rejectedSpans?: number;\n\n /** ExportLogsServiceResponse errorMessage */\n errorMessage?: string;\n}\n"]}

View File

@@ -0,0 +1,2 @@
export { IExportTracePartialSuccess, IExportTraceServiceResponse, } from './export-response';
//# sourceMappingURL=index.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=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/trace/index.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\n// IMPORTANT: exports added here are public\nexport {\n IExportTracePartialSuccess,\n IExportTraceServiceResponse,\n} from './export-response';\n"]}

View File

@@ -0,0 +1,128 @@
import { Fixed64, IInstrumentationScope, IKeyValue, IResource } from '../common/internal-types';
/** Properties of an ExportTraceServiceRequest. */
export interface IExportTraceServiceRequest {
/** ExportTraceServiceRequest resourceSpans */
resourceSpans?: IResourceSpans[];
}
/** Properties of a ResourceSpans. */
export interface IResourceSpans {
/** ResourceSpans resource */
resource?: IResource;
/** ResourceSpans scopeSpans */
scopeSpans: IScopeSpans[];
/** ResourceSpans schemaUrl */
schemaUrl?: string;
}
/** Properties of an ScopeSpans. */
export interface IScopeSpans {
/** IScopeSpans scope */
scope?: IInstrumentationScope;
/** IScopeSpans spans */
spans?: ISpan[];
/** IScopeSpans schemaUrl */
schemaUrl?: string | null;
}
/** Properties of a Span. */
export interface ISpan {
/** Span traceId */
traceId: string | Uint8Array;
/** Span spanId */
spanId: string | Uint8Array;
/** Span traceState */
traceState?: string | null;
/** Span parentSpanId */
parentSpanId?: string | Uint8Array;
/** Span name */
name: string;
/** Span kind */
kind: ESpanKind;
/** Span startTimeUnixNano */
startTimeUnixNano: Fixed64;
/** Span endTimeUnixNano */
endTimeUnixNano: Fixed64;
/** Span attributes */
attributes: IKeyValue[];
/** Span droppedAttributesCount */
droppedAttributesCount: number;
/** Span events */
events: IEvent[];
/** Span droppedEventsCount */
droppedEventsCount: number;
/** Span links */
links: ILink[];
/** Span droppedLinksCount */
droppedLinksCount: number;
/** Span status */
status: IStatus;
}
/**
* SpanKind is the type of span. Can be used to specify additional relationships between spans
* in addition to a parent/child relationship.
*/
export declare enum ESpanKind {
/** Unspecified. Do NOT use as default. Implementations MAY assume SpanKind to be INTERNAL when receiving UNSPECIFIED. */
SPAN_KIND_UNSPECIFIED = 0,
/** Indicates that the span represents an internal operation within an application,
* as opposed to an operation happening at the boundaries. Default value.
*/
SPAN_KIND_INTERNAL = 1,
/** Indicates that the span covers server-side handling of an RPC or other
* remote network request.
*/
SPAN_KIND_SERVER = 2,
/** Indicates that the span describes a request to some remote service.
*/
SPAN_KIND_CLIENT = 3,
/** Indicates that the span describes a producer sending a message to a broker.
* Unlike CLIENT and SERVER, there is often no direct critical path latency relationship
* between producer and consumer spans. A PRODUCER span ends when the message was accepted
* by the broker while the logical processing of the message might span a much longer time.
*/
SPAN_KIND_PRODUCER = 4,
/** Indicates that the span describes consumer receiving a message from a broker.
* Like the PRODUCER kind, there is often no direct critical path latency relationship
* between producer and consumer spans.
*/
SPAN_KIND_CONSUMER = 5
}
/** Properties of a Status. */
export interface IStatus {
/** Status message */
message?: string;
/** Status code */
code: EStatusCode;
}
/** StatusCode enum. */
export declare const enum EStatusCode {
/** The default status. */
STATUS_CODE_UNSET = 0,
/** The Span has been evaluated by an Application developers or Operator to have completed successfully. */
STATUS_CODE_OK = 1,
/** The Span contains an error. */
STATUS_CODE_ERROR = 2
}
/** Properties of an Event. */
export interface IEvent {
/** Event timeUnixNano */
timeUnixNano: Fixed64;
/** Event name */
name: string;
/** Event attributes */
attributes: IKeyValue[];
/** Event droppedAttributesCount */
droppedAttributesCount: number;
}
/** Properties of a Link. */
export interface ILink {
/** Link traceId */
traceId: string | Uint8Array;
/** Link spanId */
spanId: string | Uint8Array;
/** Link traceState */
traceState?: string;
/** Link attributes */
attributes: IKeyValue[];
/** Link droppedAttributesCount */
droppedAttributesCount: number;
}
//# sourceMappingURL=internal-types.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.
*/
/**
* SpanKind is the type of span. Can be used to specify additional relationships between spans
* in addition to a parent/child relationship.
*/
export var ESpanKind;
(function (ESpanKind) {
/** Unspecified. Do NOT use as default. Implementations MAY assume SpanKind to be INTERNAL when receiving UNSPECIFIED. */
ESpanKind[ESpanKind["SPAN_KIND_UNSPECIFIED"] = 0] = "SPAN_KIND_UNSPECIFIED";
/** Indicates that the span represents an internal operation within an application,
* as opposed to an operation happening at the boundaries. Default value.
*/
ESpanKind[ESpanKind["SPAN_KIND_INTERNAL"] = 1] = "SPAN_KIND_INTERNAL";
/** Indicates that the span covers server-side handling of an RPC or other
* remote network request.
*/
ESpanKind[ESpanKind["SPAN_KIND_SERVER"] = 2] = "SPAN_KIND_SERVER";
/** Indicates that the span describes a request to some remote service.
*/
ESpanKind[ESpanKind["SPAN_KIND_CLIENT"] = 3] = "SPAN_KIND_CLIENT";
/** Indicates that the span describes a producer sending a message to a broker.
* Unlike CLIENT and SERVER, there is often no direct critical path latency relationship
* between producer and consumer spans. A PRODUCER span ends when the message was accepted
* by the broker while the logical processing of the message might span a much longer time.
*/
ESpanKind[ESpanKind["SPAN_KIND_PRODUCER"] = 4] = "SPAN_KIND_PRODUCER";
/** Indicates that the span describes consumer receiving a message from a broker.
* Like the PRODUCER kind, there is often no direct critical path latency relationship
* between producer and consumer spans.
*/
ESpanKind[ESpanKind["SPAN_KIND_CONSUMER"] = 5] = "SPAN_KIND_CONSUMER";
})(ESpanKind || (ESpanKind = {}));
//# sourceMappingURL=internal-types.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,10 @@
import type { Link } from '@opentelemetry/api';
import type { ReadableSpan, TimedEvent } from '@opentelemetry/sdk-trace-base';
import type { Encoder } from '../common/utils';
import { IEvent, IExportTraceServiceRequest, ILink, ISpan } from './internal-types';
import { OtlpEncodingOptions } from '../common/internal-types';
export declare function sdkSpanToOtlpSpan(span: ReadableSpan, encoder: Encoder): ISpan;
export declare function toOtlpLink(link: Link, encoder: Encoder): ILink;
export declare function toOtlpSpanEvent(timedEvent: TimedEvent, encoder: Encoder): IEvent;
export declare function createExportTraceServiceRequest(spans: ReadableSpan[], options?: OtlpEncodingOptions): IExportTraceServiceRequest;
//# sourceMappingURL=internal.d.ts.map

View File

@@ -0,0 +1,163 @@
var __values = (this && this.__values) || function(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) return m.call(o);
if (o && typeof o.length === "number") return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
import { createInstrumentationScope, createResource, toAttributes, } from '../common/internal';
import { getOtlpEncoder } from '../common/utils';
export function sdkSpanToOtlpSpan(span, encoder) {
var _a;
var ctx = span.spanContext();
var status = span.status;
return {
traceId: encoder.encodeSpanContext(ctx.traceId),
spanId: encoder.encodeSpanContext(ctx.spanId),
parentSpanId: encoder.encodeOptionalSpanContext(span.parentSpanId),
traceState: (_a = ctx.traceState) === null || _a === void 0 ? void 0 : _a.serialize(),
name: span.name,
// Span kind is offset by 1 because the API does not define a value for unset
kind: span.kind == null ? 0 : span.kind + 1,
startTimeUnixNano: encoder.encodeHrTime(span.startTime),
endTimeUnixNano: encoder.encodeHrTime(span.endTime),
attributes: toAttributes(span.attributes),
droppedAttributesCount: span.droppedAttributesCount,
events: span.events.map(function (event) { return toOtlpSpanEvent(event, encoder); }),
droppedEventsCount: span.droppedEventsCount,
status: {
// API and proto enums share the same values
code: status.code,
message: status.message,
},
links: span.links.map(function (link) { return toOtlpLink(link, encoder); }),
droppedLinksCount: span.droppedLinksCount,
};
}
export function toOtlpLink(link, encoder) {
var _a;
return {
attributes: link.attributes ? toAttributes(link.attributes) : [],
spanId: encoder.encodeSpanContext(link.context.spanId),
traceId: encoder.encodeSpanContext(link.context.traceId),
traceState: (_a = link.context.traceState) === null || _a === void 0 ? void 0 : _a.serialize(),
droppedAttributesCount: link.droppedAttributesCount || 0,
};
}
export function toOtlpSpanEvent(timedEvent, encoder) {
return {
attributes: timedEvent.attributes
? toAttributes(timedEvent.attributes)
: [],
name: timedEvent.name,
timeUnixNano: encoder.encodeHrTime(timedEvent.time),
droppedAttributesCount: timedEvent.droppedAttributesCount || 0,
};
}
/*
* 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 createExportTraceServiceRequest(spans, options) {
var encoder = getOtlpEncoder(options);
return {
resourceSpans: spanRecordsToResourceSpans(spans, encoder),
};
}
function createResourceMap(readableSpans) {
var e_1, _a;
var resourceMap = new Map();
try {
for (var readableSpans_1 = __values(readableSpans), readableSpans_1_1 = readableSpans_1.next(); !readableSpans_1_1.done; readableSpans_1_1 = readableSpans_1.next()) {
var record = readableSpans_1_1.value;
var ilmMap = resourceMap.get(record.resource);
if (!ilmMap) {
ilmMap = new Map();
resourceMap.set(record.resource, ilmMap);
}
// TODO this is duplicated in basic tracer. Consolidate on a common helper in core
var instrumentationLibraryKey = record.instrumentationLibrary.name + "@" + (record.instrumentationLibrary.version || '') + ":" + (record.instrumentationLibrary.schemaUrl || '');
var records = ilmMap.get(instrumentationLibraryKey);
if (!records) {
records = [];
ilmMap.set(instrumentationLibraryKey, records);
}
records.push(record);
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (readableSpans_1_1 && !readableSpans_1_1.done && (_a = readableSpans_1.return)) _a.call(readableSpans_1);
}
finally { if (e_1) throw e_1.error; }
}
return resourceMap;
}
function spanRecordsToResourceSpans(readableSpans, encoder) {
var resourceMap = createResourceMap(readableSpans);
var out = [];
var entryIterator = resourceMap.entries();
var entry = entryIterator.next();
while (!entry.done) {
var _a = __read(entry.value, 2), resource = _a[0], ilmMap = _a[1];
var scopeResourceSpans = [];
var ilmIterator = ilmMap.values();
var ilmEntry = ilmIterator.next();
while (!ilmEntry.done) {
var scopeSpans = ilmEntry.value;
if (scopeSpans.length > 0) {
var spans = scopeSpans.map(function (readableSpan) {
return sdkSpanToOtlpSpan(readableSpan, encoder);
});
scopeResourceSpans.push({
scope: createInstrumentationScope(scopeSpans[0].instrumentationLibrary),
spans: spans,
schemaUrl: scopeSpans[0].instrumentationLibrary.schemaUrl,
});
}
ilmEntry = ilmIterator.next();
}
// TODO SDK types don't provide resource schema URL at this time
var transformedSpans = {
resource: createResource(resource),
scopeSpans: scopeResourceSpans,
schemaUrl: undefined,
};
out.push(transformedSpans);
entry = entryIterator.next();
}
return out;
}
//# sourceMappingURL=internal.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,2 @@
export { JsonTraceSerializer } from './trace';
//# sourceMappingURL=index.d.ts.map

View File

@@ -0,0 +1,18 @@
/*
* 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.
*/
// IMPORTANT: exports added here are public
export { JsonTraceSerializer } from './trace';
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/trace/json/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,2CAA2C;AAC3C,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,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\n// IMPORTANT: exports added here are public\nexport { JsonTraceSerializer } from './trace';\n"]}

View File

@@ -0,0 +1,5 @@
import { ISerializer } from '../../i-serializer';
import { ReadableSpan } from '@opentelemetry/sdk-trace-base';
import { IExportTraceServiceResponse } from '../export-response';
export declare const JsonTraceSerializer: ISerializer<ReadableSpan[], IExportTraceServiceResponse>;
//# sourceMappingURL=trace.d.ts.map

View File

@@ -0,0 +1,16 @@
import { createExportTraceServiceRequest } from '../internal';
export var JsonTraceSerializer = {
serializeRequest: function (arg) {
var request = createExportTraceServiceRequest(arg, {
useHex: true,
useLongBits: false,
});
var encoder = new TextEncoder();
return encoder.encode(JSON.stringify(request));
},
deserializeResponse: function (arg) {
var decoder = new TextDecoder();
return JSON.parse(decoder.decode(arg));
},
};
//# sourceMappingURL=trace.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"trace.js","sourceRoot":"","sources":["../../../../src/trace/json/trace.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,+BAA+B,EAAE,MAAM,aAAa,CAAC;AAE9D,MAAM,CAAC,IAAM,mBAAmB,GAG5B;IACF,gBAAgB,EAAE,UAAC,GAAmB;QACpC,IAAM,OAAO,GAAG,+BAA+B,CAAC,GAAG,EAAE;YACnD,MAAM,EAAE,IAAI;YACZ,WAAW,EAAE,KAAK;SACnB,CAAC,CAAC;QACH,IAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;QAClC,OAAO,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC;IACjD,CAAC;IACD,mBAAmB,EAAE,UAAC,GAAe;QACnC,IAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;QAClC,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAgC,CAAC;IACxE,CAAC;CACF,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 */\nimport { ISerializer } from '../../i-serializer';\nimport { ReadableSpan } from '@opentelemetry/sdk-trace-base';\nimport { IExportTraceServiceResponse } from '../export-response';\nimport { createExportTraceServiceRequest } from '../internal';\n\nexport const JsonTraceSerializer: ISerializer<\n ReadableSpan[],\n IExportTraceServiceResponse\n> = {\n serializeRequest: (arg: ReadableSpan[]) => {\n const request = createExportTraceServiceRequest(arg, {\n useHex: true,\n useLongBits: false,\n });\n const encoder = new TextEncoder();\n return encoder.encode(JSON.stringify(request));\n },\n deserializeResponse: (arg: Uint8Array) => {\n const decoder = new TextDecoder();\n return JSON.parse(decoder.decode(arg)) as IExportTraceServiceResponse;\n },\n};\n"]}

View File

@@ -0,0 +1,2 @@
export { ProtobufTraceSerializer } from './trace';
//# sourceMappingURL=index.d.ts.map

View File

@@ -0,0 +1,18 @@
/*
* 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.
*/
// IMPORTANT: exports added here are public
export { ProtobufTraceSerializer } from './trace';
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/trace/protobuf/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,2CAA2C;AAC3C,OAAO,EAAE,uBAAuB,EAAE,MAAM,SAAS,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\n// IMPORTANT: exports added here are public\nexport { ProtobufTraceSerializer } from './trace';\n"]}

View File

@@ -0,0 +1,5 @@
import { ISerializer } from '../../i-serializer';
import { ReadableSpan } from '@opentelemetry/sdk-trace-base';
import { IExportTraceServiceResponse } from '../export-response';
export declare const ProtobufTraceSerializer: ISerializer<ReadableSpan[], IExportTraceServiceResponse>;
//# sourceMappingURL=trace.d.ts.map

View File

@@ -0,0 +1,31 @@
/*
* 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 root from '../../generated/root';
import { createExportTraceServiceRequest } from '../internal';
var traceResponseType = root.opentelemetry.proto.collector.trace.v1
.ExportTraceServiceResponse;
var traceRequestType = root.opentelemetry.proto.collector.trace.v1
.ExportTraceServiceRequest;
export var ProtobufTraceSerializer = {
serializeRequest: function (arg) {
var request = createExportTraceServiceRequest(arg);
return traceRequestType.encode(request).finish();
},
deserializeResponse: function (arg) {
return traceResponseType.decode(arg);
},
};
//# sourceMappingURL=trace.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"trace.js","sourceRoot":"","sources":["../../../../src/trace/protobuf/trace.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,IAAI,MAAM,sBAAsB,CAAC;AAK7C,OAAO,EAAE,+BAA+B,EAAE,MAAM,aAAa,CAAC;AAG9D,IAAM,iBAAiB,GAAG,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE;KAClE,0BAAqE,CAAC;AAEzE,IAAM,gBAAgB,GAAG,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE;KACjE,yBAAmE,CAAC;AAEvE,MAAM,CAAC,IAAM,uBAAuB,GAGhC;IACF,gBAAgB,EAAE,UAAC,GAAmB;QACpC,IAAM,OAAO,GAAG,+BAA+B,CAAC,GAAG,CAAC,CAAC;QACrD,OAAO,gBAAgB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,CAAC;IACnD,CAAC;IACD,mBAAmB,EAAE,UAAC,GAAe;QACnC,OAAO,iBAAiB,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACvC,CAAC;CACF,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 * as root from '../../generated/root';\nimport { ISerializer } from '../../i-serializer';\nimport { ExportType } from '../../common/protobuf/protobuf-export-type';\nimport { IExportTraceServiceRequest } from '../internal-types';\nimport { ReadableSpan } from '@opentelemetry/sdk-trace-base';\nimport { createExportTraceServiceRequest } from '../internal';\nimport { IExportTraceServiceResponse } from '../export-response';\n\nconst traceResponseType = root.opentelemetry.proto.collector.trace.v1\n .ExportTraceServiceResponse as ExportType<IExportTraceServiceResponse>;\n\nconst traceRequestType = root.opentelemetry.proto.collector.trace.v1\n .ExportTraceServiceRequest as ExportType<IExportTraceServiceRequest>;\n\nexport const ProtobufTraceSerializer: ISerializer<\n ReadableSpan[],\n IExportTraceServiceResponse\n> = {\n serializeRequest: (arg: ReadableSpan[]) => {\n const request = createExportTraceServiceRequest(arg);\n return traceRequestType.encode(request).finish();\n },\n deserializeResponse: (arg: Uint8Array) => {\n return traceResponseType.decode(arg);\n },\n};\n"]}