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,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
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
http://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.

View File

@@ -0,0 +1,73 @@
# OpenTelemetry Core
[![NPM Published Version][npm-img]][npm-url]
[![Apache License][license-image]][license-image]
This package provides default implementations of the OpenTelemetry API for trace and metrics. It's intended for use both on the server and in the browser.
## Built-in Implementations
- [OpenTelemetry Core](#opentelemetry-core)
- [Built-in Implementations](#built-in-implementations)
- [Built-in Propagators](#built-in-propagators)
- [W3CTraceContextPropagator Propagator](#w3ctracecontextpropagator-propagator)
- [Composite Propagator](#composite-propagator)
- [Baggage Propagator](#baggage-propagator)
- [Useful links](#useful-links)
- [License](#license)
### Built-in Propagators
#### W3CTraceContextPropagator Propagator
OpenTelemetry provides a text-based approach to propagate context to remote services using the [W3C Trace Context](https://www.w3.org/TR/trace-context/) HTTP headers.
```js
const api = require("@opentelemetry/api");
const { W3CTraceContextPropagator } = require("@opentelemetry/core");
/* Set Global Propagator */
api.propagation.setGlobalPropagator(new W3CTraceContextPropagator());
```
#### Composite Propagator
Combines multiple propagators into a single propagator.
> This is used as a default Propagator
```js
const api = require("@opentelemetry/api");
const { CompositePropagator } = require("@opentelemetry/core");
/* Set Global Propagator */
api.propagation.setGlobalPropagator(new CompositePropagator());
```
#### Baggage Propagator
Provides a text-based approach to propagate [baggage](https://w3c.github.io/baggage/) to remote services using the [OpenTelemetry Baggage Propagation](https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/baggage/api.md#baggage-propagation) HTTP headers.
```js
const api = require("@opentelemetry/api");
const { W3CBaggagePropagator } = require("@opentelemetry/core");
/* Set Global Propagator */
api.propagation.setGlobalPropagator(new W3CBaggagePropagator());
```
## Useful links
- For more information on OpenTelemetry, visit: <https://opentelemetry.io/>
- For more about OpenTelemetry JavaScript: <https://github.com/open-telemetry/opentelemetry-js>
- For help or feedback on this project, join us in [GitHub Discussions][discussions-url]
## License
Apache 2.0 - See [LICENSE][license-url] for more information.
[discussions-url]: https://github.com/open-telemetry/opentelemetry-js/discussions
[license-url]: https://github.com/open-telemetry/opentelemetry-js/blob/main/LICENSE
[license-image]: https://img.shields.io/badge/license-Apache_2.0-green.svg?style=flat
[npm-url]: https://www.npmjs.com/package/@opentelemetry/core
[npm-img]: https://badge.fury.io/js/%40opentelemetry%2Fcore.svg

View File

@@ -0,0 +1,9 @@
export interface ExportResult {
code: ExportResultCode;
error?: Error;
}
export declare enum ExportResultCode {
SUCCESS = 0,
FAILED = 1
}
//# sourceMappingURL=ExportResult.d.ts.map

View File

@@ -0,0 +1,10 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
export var ExportResultCode;
(function (ExportResultCode) {
ExportResultCode[ExportResultCode["SUCCESS"] = 0] = "SUCCESS";
ExportResultCode[ExportResultCode["FAILED"] = 1] = "FAILED";
})(ExportResultCode || (ExportResultCode = {}));
//# sourceMappingURL=ExportResult.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"ExportResult.js","sourceRoot":"","sources":["../../src/ExportResult.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAOH,MAAM,CAAN,IAAY,gBAGX;AAHD,WAAY,gBAAgB;IAC1B,6DAAO,CAAA;IACP,2DAAM,CAAA;AACR,CAAC,EAHW,gBAAgB,KAAhB,gBAAgB,QAG3B","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nexport interface ExportResult {\n code: ExportResultCode;\n error?: Error;\n}\n\nexport enum ExportResultCode {\n SUCCESS,\n FAILED,\n}\n"]}

View File

@@ -0,0 +1,8 @@
export declare const BAGGAGE_KEY_PAIR_SEPARATOR = "=";
export declare const BAGGAGE_PROPERTIES_SEPARATOR = ";";
export declare const BAGGAGE_ITEMS_SEPARATOR = ",";
export declare const BAGGAGE_HEADER = "baggage";
export declare const BAGGAGE_MAX_NAME_VALUE_PAIRS = 180;
export declare const BAGGAGE_MAX_PER_NAME_VALUE_PAIRS = 4096;
export declare const BAGGAGE_MAX_TOTAL_LENGTH = 8192;
//# sourceMappingURL=constants.d.ts.map

View File

@@ -0,0 +1,16 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
export const BAGGAGE_KEY_PAIR_SEPARATOR = '=';
export const BAGGAGE_PROPERTIES_SEPARATOR = ';';
export const BAGGAGE_ITEMS_SEPARATOR = ',';
// Name of the http header used to propagate the baggage
export const BAGGAGE_HEADER = 'baggage';
// Maximum number of name-value pairs allowed by w3c spec
export const BAGGAGE_MAX_NAME_VALUE_PAIRS = 180;
// Maximum number of bytes per a single name-value pair allowed by w3c spec
export const BAGGAGE_MAX_PER_NAME_VALUE_PAIRS = 4096;
// Maximum total length of all name-value pairs allowed by w3c spec
export const BAGGAGE_MAX_TOTAL_LENGTH = 8192;
//# sourceMappingURL=constants.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/baggage/constants.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,CAAC,MAAM,0BAA0B,GAAG,GAAG,CAAC;AAC9C,MAAM,CAAC,MAAM,4BAA4B,GAAG,GAAG,CAAC;AAChD,MAAM,CAAC,MAAM,uBAAuB,GAAG,GAAG,CAAC;AAE3C,wDAAwD;AACxD,MAAM,CAAC,MAAM,cAAc,GAAG,SAAS,CAAC;AACxC,yDAAyD;AACzD,MAAM,CAAC,MAAM,4BAA4B,GAAG,GAAG,CAAC;AAChD,2EAA2E;AAC3E,MAAM,CAAC,MAAM,gCAAgC,GAAG,IAAI,CAAC;AACrD,mEAAmE;AACnE,MAAM,CAAC,MAAM,wBAAwB,GAAG,IAAI,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nexport const BAGGAGE_KEY_PAIR_SEPARATOR = '=';\nexport const BAGGAGE_PROPERTIES_SEPARATOR = ';';\nexport const BAGGAGE_ITEMS_SEPARATOR = ',';\n\n// Name of the http header used to propagate the baggage\nexport const BAGGAGE_HEADER = 'baggage';\n// Maximum number of name-value pairs allowed by w3c spec\nexport const BAGGAGE_MAX_NAME_VALUE_PAIRS = 180;\n// Maximum number of bytes per a single name-value pair allowed by w3c spec\nexport const BAGGAGE_MAX_PER_NAME_VALUE_PAIRS = 4096;\n// Maximum total length of all name-value pairs allowed by w3c spec\nexport const BAGGAGE_MAX_TOTAL_LENGTH = 8192;\n"]}

View File

@@ -0,0 +1,13 @@
import type { Context, TextMapGetter, TextMapPropagator, TextMapSetter } from '@opentelemetry/api';
/**
* Propagates {@link Baggage} through Context format propagation.
*
* Based on the Baggage specification:
* https://w3c.github.io/baggage/
*/
export declare class W3CBaggagePropagator implements TextMapPropagator {
inject(context: Context, carrier: unknown, setter: TextMapSetter): void;
extract(context: Context, carrier: unknown, getter: TextMapGetter): Context;
fields(): string[];
}
//# sourceMappingURL=W3CBaggagePropagator.d.ts.map

View File

@@ -0,0 +1,61 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
import { propagation } from '@opentelemetry/api';
import { isTracingSuppressed } from '../../trace/suppress-tracing';
import { BAGGAGE_HEADER, BAGGAGE_ITEMS_SEPARATOR, BAGGAGE_MAX_NAME_VALUE_PAIRS, BAGGAGE_MAX_PER_NAME_VALUE_PAIRS, } from '../constants';
import { getKeyPairs, parsePairKeyValue, serializeKeyPairs } from '../utils';
/**
* Propagates {@link Baggage} through Context format propagation.
*
* Based on the Baggage specification:
* https://w3c.github.io/baggage/
*/
export class W3CBaggagePropagator {
inject(context, carrier, setter) {
const baggage = propagation.getBaggage(context);
if (!baggage || isTracingSuppressed(context))
return;
const keyPairs = getKeyPairs(baggage)
.filter((pair) => {
return pair.length <= BAGGAGE_MAX_PER_NAME_VALUE_PAIRS;
})
.slice(0, BAGGAGE_MAX_NAME_VALUE_PAIRS);
const headerValue = serializeKeyPairs(keyPairs);
if (headerValue.length > 0) {
setter.set(carrier, BAGGAGE_HEADER, headerValue);
}
}
extract(context, carrier, getter) {
const headerValue = getter.get(carrier, BAGGAGE_HEADER);
const baggageString = Array.isArray(headerValue)
? headerValue.join(BAGGAGE_ITEMS_SEPARATOR)
: headerValue;
if (!baggageString)
return context;
const baggage = {};
if (baggageString.length === 0) {
return context;
}
const pairs = baggageString.split(BAGGAGE_ITEMS_SEPARATOR);
pairs.forEach(entry => {
const keyPair = parsePairKeyValue(entry);
if (keyPair) {
const baggageEntry = { value: keyPair.value };
if (keyPair.metadata) {
baggageEntry.metadata = keyPair.metadata;
}
baggage[keyPair.key] = baggageEntry;
}
});
if (Object.entries(baggage).length === 0) {
return context;
}
return propagation.setBaggage(context, propagation.createBaggage(baggage));
}
fields() {
return [BAGGAGE_HEADER];
}
}
//# sourceMappingURL=W3CBaggagePropagator.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"W3CBaggagePropagator.js","sourceRoot":"","sources":["../../../../src/baggage/propagation/W3CBaggagePropagator.ts"],"names":[],"mappings":"AAAA;;;GAGG;AASH,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EACL,cAAc,EACd,uBAAuB,EACvB,4BAA4B,EAC5B,gCAAgC,GACjC,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAE7E;;;;;GAKG;AACH,MAAM,OAAO,oBAAoB;IAC/B,MAAM,CAAC,OAAgB,EAAE,OAAgB,EAAE,MAAqB;QAC9D,MAAM,OAAO,GAAG,WAAW,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;QAChD,IAAI,CAAC,OAAO,IAAI,mBAAmB,CAAC,OAAO,CAAC;YAAE,OAAO;QACrD,MAAM,QAAQ,GAAG,WAAW,CAAC,OAAO,CAAC;aAClC,MAAM,CAAC,CAAC,IAAY,EAAE,EAAE;YACvB,OAAO,IAAI,CAAC,MAAM,IAAI,gCAAgC,CAAC;QACzD,CAAC,CAAC;aACD,KAAK,CAAC,CAAC,EAAE,4BAA4B,CAAC,CAAC;QAC1C,MAAM,WAAW,GAAG,iBAAiB,CAAC,QAAQ,CAAC,CAAC;QAChD,IAAI,WAAW,CAAC,MAAM,GAAG,CAAC,EAAE;YAC1B,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,cAAc,EAAE,WAAW,CAAC,CAAC;SAClD;IACH,CAAC;IAED,OAAO,CAAC,OAAgB,EAAE,OAAgB,EAAE,MAAqB;QAC/D,MAAM,WAAW,GAAG,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC;QACxD,MAAM,aAAa,GAAG,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC;YAC9C,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,uBAAuB,CAAC;YAC3C,CAAC,CAAC,WAAW,CAAC;QAChB,IAAI,CAAC,aAAa;YAAE,OAAO,OAAO,CAAC;QACnC,MAAM,OAAO,GAAiC,EAAE,CAAC;QACjD,IAAI,aAAa,CAAC,MAAM,KAAK,CAAC,EAAE;YAC9B,OAAO,OAAO,CAAC;SAChB;QACD,MAAM,KAAK,GAAG,aAAa,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAC;QAC3D,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;YACpB,MAAM,OAAO,GAAG,iBAAiB,CAAC,KAAK,CAAC,CAAC;YACzC,IAAI,OAAO,EAAE;gBACX,MAAM,YAAY,GAAiB,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC;gBAC5D,IAAI,OAAO,CAAC,QAAQ,EAAE;oBACpB,YAAY,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;iBAC1C;gBACD,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,YAAY,CAAC;aACrC;QACH,CAAC,CAAC,CAAC;QACH,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE;YACxC,OAAO,OAAO,CAAC;SAChB;QACD,OAAO,WAAW,CAAC,UAAU,CAAC,OAAO,EAAE,WAAW,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC;IAC7E,CAAC;IAED,MAAM;QACJ,OAAO,CAAC,cAAc,CAAC,CAAC;IAC1B,CAAC;CACF","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type {\n BaggageEntry,\n Context,\n TextMapGetter,\n TextMapPropagator,\n TextMapSetter,\n} from '@opentelemetry/api';\nimport { propagation } from '@opentelemetry/api';\n\nimport { isTracingSuppressed } from '../../trace/suppress-tracing';\nimport {\n BAGGAGE_HEADER,\n BAGGAGE_ITEMS_SEPARATOR,\n BAGGAGE_MAX_NAME_VALUE_PAIRS,\n BAGGAGE_MAX_PER_NAME_VALUE_PAIRS,\n} from '../constants';\nimport { getKeyPairs, parsePairKeyValue, serializeKeyPairs } from '../utils';\n\n/**\n * Propagates {@link Baggage} through Context format propagation.\n *\n * Based on the Baggage specification:\n * https://w3c.github.io/baggage/\n */\nexport class W3CBaggagePropagator implements TextMapPropagator {\n inject(context: Context, carrier: unknown, setter: TextMapSetter): void {\n const baggage = propagation.getBaggage(context);\n if (!baggage || isTracingSuppressed(context)) return;\n const keyPairs = getKeyPairs(baggage)\n .filter((pair: string) => {\n return pair.length <= BAGGAGE_MAX_PER_NAME_VALUE_PAIRS;\n })\n .slice(0, BAGGAGE_MAX_NAME_VALUE_PAIRS);\n const headerValue = serializeKeyPairs(keyPairs);\n if (headerValue.length > 0) {\n setter.set(carrier, BAGGAGE_HEADER, headerValue);\n }\n }\n\n extract(context: Context, carrier: unknown, getter: TextMapGetter): Context {\n const headerValue = getter.get(carrier, BAGGAGE_HEADER);\n const baggageString = Array.isArray(headerValue)\n ? headerValue.join(BAGGAGE_ITEMS_SEPARATOR)\n : headerValue;\n if (!baggageString) return context;\n const baggage: Record<string, BaggageEntry> = {};\n if (baggageString.length === 0) {\n return context;\n }\n const pairs = baggageString.split(BAGGAGE_ITEMS_SEPARATOR);\n pairs.forEach(entry => {\n const keyPair = parsePairKeyValue(entry);\n if (keyPair) {\n const baggageEntry: BaggageEntry = { value: keyPair.value };\n if (keyPair.metadata) {\n baggageEntry.metadata = keyPair.metadata;\n }\n baggage[keyPair.key] = baggageEntry;\n }\n });\n if (Object.entries(baggage).length === 0) {\n return context;\n }\n return propagation.setBaggage(context, propagation.createBaggage(baggage));\n }\n\n fields(): string[] {\n return [BAGGAGE_HEADER];\n }\n}\n"]}

View File

@@ -0,0 +1,16 @@
import type { Baggage, BaggageEntryMetadata } from '@opentelemetry/api';
type ParsedBaggageKeyValue = {
key: string;
value: string;
metadata: BaggageEntryMetadata | undefined;
};
export declare function serializeKeyPairs(keyPairs: string[]): string;
export declare function getKeyPairs(baggage: Baggage): string[];
export declare function parsePairKeyValue(entry: string): ParsedBaggageKeyValue | undefined;
/**
* Parse a string serialized in the baggage HTTP Format (without metadata):
* https://github.com/w3c/baggage/blob/master/baggage/HTTP_HEADER_FORMAT.md
*/
export declare function parseKeyPairsIntoRecord(value?: string): Record<string, string>;
export {};
//# sourceMappingURL=utils.d.ts.map

View File

@@ -0,0 +1,67 @@
import { baggageEntryMetadataFromString } from '@opentelemetry/api';
import { BAGGAGE_ITEMS_SEPARATOR, BAGGAGE_PROPERTIES_SEPARATOR, BAGGAGE_KEY_PAIR_SEPARATOR, BAGGAGE_MAX_TOTAL_LENGTH, } from './constants';
export function serializeKeyPairs(keyPairs) {
return keyPairs.reduce((hValue, current) => {
const value = `${hValue}${hValue !== '' ? BAGGAGE_ITEMS_SEPARATOR : ''}${current}`;
return value.length > BAGGAGE_MAX_TOTAL_LENGTH ? hValue : value;
}, '');
}
export function getKeyPairs(baggage) {
return baggage.getAllEntries().map(([key, value]) => {
let entry = `${encodeURIComponent(key)}=${encodeURIComponent(value.value)}`;
// include opaque metadata if provided
// NOTE: we intentionally don't URI-encode the metadata - that responsibility falls on the metadata implementation
if (value.metadata !== undefined) {
entry += BAGGAGE_PROPERTIES_SEPARATOR + value.metadata.toString();
}
return entry;
});
}
export function parsePairKeyValue(entry) {
if (!entry)
return;
const metadataSeparatorIndex = entry.indexOf(BAGGAGE_PROPERTIES_SEPARATOR);
const keyPairPart = metadataSeparatorIndex === -1
? entry
: entry.substring(0, metadataSeparatorIndex);
const separatorIndex = keyPairPart.indexOf(BAGGAGE_KEY_PAIR_SEPARATOR);
if (separatorIndex <= 0)
return;
const rawKey = keyPairPart.substring(0, separatorIndex).trim();
const rawValue = keyPairPart.substring(separatorIndex + 1).trim();
if (!rawKey || !rawValue)
return;
let key;
let value;
try {
key = decodeURIComponent(rawKey);
value = decodeURIComponent(rawValue);
}
catch {
return;
}
let metadata;
if (metadataSeparatorIndex !== -1 &&
metadataSeparatorIndex < entry.length - 1) {
const metadataString = entry.substring(metadataSeparatorIndex + 1);
metadata = baggageEntryMetadataFromString(metadataString);
}
return { key, value, metadata };
}
/**
* Parse a string serialized in the baggage HTTP Format (without metadata):
* https://github.com/w3c/baggage/blob/master/baggage/HTTP_HEADER_FORMAT.md
*/
export function parseKeyPairsIntoRecord(value) {
const result = {};
if (typeof value === 'string' && value.length > 0) {
value.split(BAGGAGE_ITEMS_SEPARATOR).forEach(entry => {
const keyPair = parsePairKeyValue(entry);
if (keyPair !== undefined && keyPair.value.length > 0) {
result[keyPair.key] = keyPair.value;
}
});
}
return result;
}
//# sourceMappingURL=utils.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,41 @@
export interface Clock {
/**
* Return the current time in milliseconds from some epoch such as the Unix epoch or process start
*/
now(): number;
}
/**
* A utility for returning wall times anchored to a given point in time. Wall time measurements will
* not be taken from the system, but instead are computed by adding a monotonic clock time
* to the anchor point.
*
* This is needed because the system time can change and result in unexpected situations like
* spans ending before they are started. Creating an anchored clock for each local root span
* ensures that span timings and durations are accurate while preventing span times from drifting
* too far from the system clock.
*
* Only creating an anchored clock once per local trace ensures span times are correct relative
* to each other. For example, a child span will never have a start time before its parent even
* if the system clock is corrected during the local trace.
*
* Heavily inspired by the OTel Java anchored clock
* https://github.com/open-telemetry/opentelemetry-java/blob/main/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/AnchoredClock.java
*/
export declare class AnchoredClock implements Clock {
private _monotonicClock;
private _epochMillis;
private _performanceMillis;
/**
* Create a new AnchoredClock anchored to the current time returned by systemClock.
*
* @param systemClock should be a clock that returns the number of milliseconds since January 1 1970 such as Date
* @param monotonicClock should be a clock that counts milliseconds monotonically such as window.performance or perf_hooks.performance
*/
constructor(systemClock: Clock, monotonicClock: Clock);
/**
* Returns the current time by adding the number of milliseconds since the
* AnchoredClock was created to the creation epoch time
*/
now(): number;
}
//# sourceMappingURL=anchored-clock.d.ts.map

View File

@@ -0,0 +1,46 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
/**
* A utility for returning wall times anchored to a given point in time. Wall time measurements will
* not be taken from the system, but instead are computed by adding a monotonic clock time
* to the anchor point.
*
* This is needed because the system time can change and result in unexpected situations like
* spans ending before they are started. Creating an anchored clock for each local root span
* ensures that span timings and durations are accurate while preventing span times from drifting
* too far from the system clock.
*
* Only creating an anchored clock once per local trace ensures span times are correct relative
* to each other. For example, a child span will never have a start time before its parent even
* if the system clock is corrected during the local trace.
*
* Heavily inspired by the OTel Java anchored clock
* https://github.com/open-telemetry/opentelemetry-java/blob/main/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/AnchoredClock.java
*/
export class AnchoredClock {
_monotonicClock;
_epochMillis;
_performanceMillis;
/**
* Create a new AnchoredClock anchored to the current time returned by systemClock.
*
* @param systemClock should be a clock that returns the number of milliseconds since January 1 1970 such as Date
* @param monotonicClock should be a clock that counts milliseconds monotonically such as window.performance or perf_hooks.performance
*/
constructor(systemClock, monotonicClock) {
this._monotonicClock = monotonicClock;
this._epochMillis = systemClock.now();
this._performanceMillis = monotonicClock.now();
}
/**
* Returns the current time by adding the number of milliseconds since the
* AnchoredClock was created to the creation epoch time
*/
now() {
const delta = this._monotonicClock.now() - this._performanceMillis;
return this._epochMillis + delta;
}
}
//# sourceMappingURL=anchored-clock.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"anchored-clock.js","sourceRoot":"","sources":["../../../src/common/anchored-clock.ts"],"names":[],"mappings":"AAAA;;;GAGG;AASH;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,OAAO,aAAa;IAChB,eAAe,CAAQ;IACvB,YAAY,CAAS;IACrB,kBAAkB,CAAS;IAEnC;;;;;OAKG;IACH,YAAmB,WAAkB,EAAE,cAAqB;QAC1D,IAAI,CAAC,eAAe,GAAG,cAAc,CAAC;QACtC,IAAI,CAAC,YAAY,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;QACtC,IAAI,CAAC,kBAAkB,GAAG,cAAc,CAAC,GAAG,EAAE,CAAC;IACjD,CAAC;IAED;;;OAGG;IACI,GAAG;QACR,MAAM,KAAK,GAAG,IAAI,CAAC,eAAe,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,kBAAkB,CAAC;QACnE,OAAO,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC;IACnC,CAAC;CACF","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nexport interface Clock {\n /**\n * Return the current time in milliseconds from some epoch such as the Unix epoch or process start\n */\n now(): number;\n}\n\n/**\n * A utility for returning wall times anchored to a given point in time. Wall time measurements will\n * not be taken from the system, but instead are computed by adding a monotonic clock time\n * to the anchor point.\n *\n * This is needed because the system time can change and result in unexpected situations like\n * spans ending before they are started. Creating an anchored clock for each local root span\n * ensures that span timings and durations are accurate while preventing span times from drifting\n * too far from the system clock.\n *\n * Only creating an anchored clock once per local trace ensures span times are correct relative\n * to each other. For example, a child span will never have a start time before its parent even\n * if the system clock is corrected during the local trace.\n *\n * Heavily inspired by the OTel Java anchored clock\n * https://github.com/open-telemetry/opentelemetry-java/blob/main/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/AnchoredClock.java\n */\nexport class AnchoredClock implements Clock {\n private _monotonicClock: Clock;\n private _epochMillis: number;\n private _performanceMillis: number;\n\n /**\n * Create a new AnchoredClock anchored to the current time returned by systemClock.\n *\n * @param systemClock should be a clock that returns the number of milliseconds since January 1 1970 such as Date\n * @param monotonicClock should be a clock that counts milliseconds monotonically such as window.performance or perf_hooks.performance\n */\n public constructor(systemClock: Clock, monotonicClock: Clock) {\n this._monotonicClock = monotonicClock;\n this._epochMillis = systemClock.now();\n this._performanceMillis = monotonicClock.now();\n }\n\n /**\n * Returns the current time by adding the number of milliseconds since the\n * AnchoredClock was created to the creation epoch time\n */\n public now(): number {\n const delta = this._monotonicClock.now() - this._performanceMillis;\n return this._epochMillis + delta;\n }\n}\n"]}

View File

@@ -0,0 +1,5 @@
import type { AttributeValue, Attributes } from '@opentelemetry/api';
export declare function sanitizeAttributes(attributes: unknown): Attributes;
export declare function isAttributeKey(key: unknown): key is string;
export declare function isAttributeValue(val: unknown): val is AttributeValue;
//# sourceMappingURL=attributes.d.ts.map

View File

@@ -0,0 +1,76 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
import { diag } from '@opentelemetry/api';
export function sanitizeAttributes(attributes) {
const out = {};
if (typeof attributes !== 'object' || attributes == null) {
return out;
}
for (const key in attributes) {
if (!Object.prototype.hasOwnProperty.call(attributes, key)) {
continue;
}
if (!isAttributeKey(key)) {
diag.warn(`Invalid attribute key: ${key}`);
continue;
}
const val = attributes[key];
if (!isAttributeValue(val)) {
diag.warn(`Invalid attribute value set for key: ${key}`);
continue;
}
if (Array.isArray(val)) {
out[key] = val.slice();
}
else {
out[key] = val;
}
}
return out;
}
export function isAttributeKey(key) {
return typeof key === 'string' && key !== '';
}
export function isAttributeValue(val) {
if (val == null) {
return true;
}
if (Array.isArray(val)) {
return isHomogeneousAttributeValueArray(val);
}
return isValidPrimitiveAttributeValueType(typeof val);
}
function isHomogeneousAttributeValueArray(arr) {
let type;
for (const element of arr) {
// null/undefined elements are allowed
if (element == null)
continue;
const elementType = typeof element;
if (elementType === type) {
continue;
}
if (!type) {
if (isValidPrimitiveAttributeValueType(elementType)) {
type = elementType;
continue;
}
// encountered an invalid primitive
return false;
}
return false;
}
return true;
}
function isValidPrimitiveAttributeValueType(valType) {
switch (valType) {
case 'number':
case 'boolean':
case 'string':
return true;
}
return false;
}
//# sourceMappingURL=attributes.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"attributes.js","sourceRoot":"","sources":["../../../src/common/attributes.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAE1C,MAAM,UAAU,kBAAkB,CAAC,UAAmB;IACpD,MAAM,GAAG,GAAe,EAAE,CAAC;IAE3B,IAAI,OAAO,UAAU,KAAK,QAAQ,IAAI,UAAU,IAAI,IAAI,EAAE;QACxD,OAAO,GAAG,CAAC;KACZ;IAED,KAAK,MAAM,GAAG,IAAI,UAAU,EAAE;QAC5B,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,UAAU,EAAE,GAAG,CAAC,EAAE;YAC1D,SAAS;SACV;QACD,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE;YACxB,IAAI,CAAC,IAAI,CAAC,0BAA0B,GAAG,EAAE,CAAC,CAAC;YAC3C,SAAS;SACV;QACD,MAAM,GAAG,GAAI,UAAsC,CAAC,GAAG,CAAC,CAAC;QACzD,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,EAAE;YAC1B,IAAI,CAAC,IAAI,CAAC,wCAAwC,GAAG,EAAE,CAAC,CAAC;YACzD,SAAS;SACV;QACD,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;YACtB,GAAG,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,KAAK,EAAE,CAAC;SACxB;aAAM;YACL,GAAG,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC;SAChB;KACF;IAED,OAAO,GAAG,CAAC;AACb,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,GAAY;IACzC,OAAO,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,EAAE,CAAC;AAC/C,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,GAAY;IAC3C,IAAI,GAAG,IAAI,IAAI,EAAE;QACf,OAAO,IAAI,CAAC;KACb;IAED,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;QACtB,OAAO,gCAAgC,CAAC,GAAG,CAAC,CAAC;KAC9C;IAED,OAAO,kCAAkC,CAAC,OAAO,GAAG,CAAC,CAAC;AACxD,CAAC;AAED,SAAS,gCAAgC,CAAC,GAAc;IACtD,IAAI,IAAwB,CAAC;IAE7B,KAAK,MAAM,OAAO,IAAI,GAAG,EAAE;QACzB,sCAAsC;QACtC,IAAI,OAAO,IAAI,IAAI;YAAE,SAAS;QAC9B,MAAM,WAAW,GAAG,OAAO,OAAO,CAAC;QAEnC,IAAI,WAAW,KAAK,IAAI,EAAE;YACxB,SAAS;SACV;QAED,IAAI,CAAC,IAAI,EAAE;YACT,IAAI,kCAAkC,CAAC,WAAW,CAAC,EAAE;gBACnD,IAAI,GAAG,WAAW,CAAC;gBACnB,SAAS;aACV;YACD,mCAAmC;YACnC,OAAO,KAAK,CAAC;SACd;QAED,OAAO,KAAK,CAAC;KACd;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAED,SAAS,kCAAkC,CAAC,OAAe;IACzD,QAAQ,OAAO,EAAE;QACf,KAAK,QAAQ,CAAC;QACd,KAAK,SAAS,CAAC;QACf,KAAK,QAAQ;YACX,OAAO,IAAI,CAAC;KACf;IAED,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { AttributeValue, Attributes } from '@opentelemetry/api';\nimport { diag } from '@opentelemetry/api';\n\nexport function sanitizeAttributes(attributes: unknown): Attributes {\n const out: Attributes = {};\n\n if (typeof attributes !== 'object' || attributes == null) {\n return out;\n }\n\n for (const key in attributes) {\n if (!Object.prototype.hasOwnProperty.call(attributes, key)) {\n continue;\n }\n if (!isAttributeKey(key)) {\n diag.warn(`Invalid attribute key: ${key}`);\n continue;\n }\n const val = (attributes as Record<string, unknown>)[key];\n if (!isAttributeValue(val)) {\n diag.warn(`Invalid attribute value set for key: ${key}`);\n continue;\n }\n if (Array.isArray(val)) {\n out[key] = val.slice();\n } else {\n out[key] = val;\n }\n }\n\n return out;\n}\n\nexport function isAttributeKey(key: unknown): key is string {\n return typeof key === 'string' && key !== '';\n}\n\nexport function isAttributeValue(val: unknown): val is AttributeValue {\n if (val == null) {\n return true;\n }\n\n if (Array.isArray(val)) {\n return isHomogeneousAttributeValueArray(val);\n }\n\n return isValidPrimitiveAttributeValueType(typeof val);\n}\n\nfunction isHomogeneousAttributeValueArray(arr: unknown[]): boolean {\n let type: string | undefined;\n\n for (const element of arr) {\n // null/undefined elements are allowed\n if (element == null) continue;\n const elementType = typeof element;\n\n if (elementType === type) {\n continue;\n }\n\n if (!type) {\n if (isValidPrimitiveAttributeValueType(elementType)) {\n type = elementType;\n continue;\n }\n // encountered an invalid primitive\n return false;\n }\n\n return false;\n }\n\n return true;\n}\n\nfunction isValidPrimitiveAttributeValueType(valType: string): boolean {\n switch (valType) {\n case 'number':\n case 'boolean':\n case 'string':\n return true;\n }\n\n return false;\n}\n"]}

View File

@@ -0,0 +1,13 @@
import type { Exception } from '@opentelemetry/api';
import type { ErrorHandler } from './types';
/**
* Set the global error handler
* @param {ErrorHandler} handler
*/
export declare function setGlobalErrorHandler(handler: ErrorHandler): void;
/**
* Return the global error handler
* @param {Exception} ex
*/
export declare function globalErrorHandler(ex: Exception): void;
//# sourceMappingURL=global-error-handler.d.ts.map

View File

@@ -0,0 +1,25 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
import { loggingErrorHandler } from './logging-error-handler';
/** The global error handler delegate */
let delegateHandler = loggingErrorHandler();
/**
* Set the global error handler
* @param {ErrorHandler} handler
*/
export function setGlobalErrorHandler(handler) {
delegateHandler = handler;
}
/**
* Return the global error handler
* @param {Exception} ex
*/
export function globalErrorHandler(ex) {
try {
delegateHandler(ex);
}
catch { } // eslint-disable-line no-empty
}
//# sourceMappingURL=global-error-handler.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"global-error-handler.js","sourceRoot":"","sources":["../../../src/common/global-error-handler.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAG9D,wCAAwC;AACxC,IAAI,eAAe,GAAG,mBAAmB,EAAE,CAAC;AAE5C;;;GAGG;AACH,MAAM,UAAU,qBAAqB,CAAC,OAAqB;IACzD,eAAe,GAAG,OAAO,CAAC;AAC5B,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CAAC,EAAa;IAC9C,IAAI;QACF,eAAe,CAAC,EAAE,CAAC,CAAC;KACrB;IAAC,MAAM,GAAE,CAAC,+BAA+B;AAC5C,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { Exception } from '@opentelemetry/api';\nimport { loggingErrorHandler } from './logging-error-handler';\nimport type { ErrorHandler } from './types';\n\n/** The global error handler delegate */\nlet delegateHandler = loggingErrorHandler();\n\n/**\n * Set the global error handler\n * @param {ErrorHandler} handler\n */\nexport function setGlobalErrorHandler(handler: ErrorHandler): void {\n delegateHandler = handler;\n}\n\n/**\n * Return the global error handler\n * @param {Exception} ex\n */\nexport function globalErrorHandler(ex: Exception): void {\n try {\n delegateHandler(ex);\n } catch {} // eslint-disable-line no-empty\n}\n"]}

View File

@@ -0,0 +1,5 @@
/**
* @deprecated Use globalThis directly instead.
*/
export declare const _globalThis: typeof globalThis;
//# sourceMappingURL=globalThis.d.ts.map

View File

@@ -0,0 +1,9 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @deprecated Use globalThis directly instead.
*/
export const _globalThis = globalThis;
//# sourceMappingURL=globalThis.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"globalThis.js","sourceRoot":"","sources":["../../../src/common/globalThis.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,UAAU,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\n/**\n * @deprecated Use globalThis directly instead.\n */\nexport const _globalThis = globalThis;\n"]}

View File

@@ -0,0 +1,7 @@
import type { ErrorHandler } from './types';
/**
* Returns a function that logs an error using the provided logger, or a
* console logger if one was not provided.
*/
export declare function loggingErrorHandler(): ErrorHandler;
//# sourceMappingURL=logging-error-handler.d.ts.map

View File

@@ -0,0 +1,48 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
import { diag } from '@opentelemetry/api';
/**
* Returns a function that logs an error using the provided logger, or a
* console logger if one was not provided.
*/
export function loggingErrorHandler() {
return (ex) => {
diag.error(stringifyException(ex));
};
}
/**
* Converts an exception into a string representation
* @param {Exception} ex
*/
function stringifyException(ex) {
if (typeof ex === 'string') {
return ex;
}
else {
return JSON.stringify(flattenException(ex));
}
}
/**
* Flattens an exception into key-value pairs by traversing the prototype chain
* and coercing values to strings. Duplicate properties will not be overwritten;
* the first insert wins.
*/
function flattenException(ex) {
const result = {};
let current = ex;
while (current !== null) {
Object.getOwnPropertyNames(current).forEach(propertyName => {
if (result[propertyName])
return;
const value = current[propertyName];
if (value) {
result[propertyName] = String(value);
}
});
current = Object.getPrototypeOf(current);
}
return result;
}
//# sourceMappingURL=logging-error-handler.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"logging-error-handler.js","sourceRoot":"","sources":["../../../src/common/logging-error-handler.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAG1C;;;GAGG;AACH,MAAM,UAAU,mBAAmB;IACjC,OAAO,CAAC,EAAa,EAAE,EAAE;QACvB,IAAI,CAAC,KAAK,CAAC,kBAAkB,CAAC,EAAE,CAAC,CAAC,CAAC;IACrC,CAAC,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,SAAS,kBAAkB,CAAC,EAAsB;IAChD,IAAI,OAAO,EAAE,KAAK,QAAQ,EAAE;QAC1B,OAAO,EAAE,CAAC;KACX;SAAM;QACL,OAAO,IAAI,CAAC,SAAS,CAAC,gBAAgB,CAAC,EAAE,CAAC,CAAC,CAAC;KAC7C;AACH,CAAC;AAED;;;;GAIG;AACH,SAAS,gBAAgB,CAAC,EAAa;IACrC,MAAM,MAAM,GAAG,EAA4B,CAAC;IAC5C,IAAI,OAAO,GAAG,EAAE,CAAC;IAEjB,OAAO,OAAO,KAAK,IAAI,EAAE;QACvB,MAAM,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE;YACzD,IAAI,MAAM,CAAC,YAAY,CAAC;gBAAE,OAAO;YACjC,MAAM,KAAK,GAAG,OAAO,CAAC,YAAoC,CAAC,CAAC;YAC5D,IAAI,KAAK,EAAE;gBACT,MAAM,CAAC,YAAY,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;aACtC;QACH,CAAC,CAAC,CAAC;QACH,OAAO,GAAG,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;KAC1C;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { Exception } from '@opentelemetry/api';\nimport { diag } from '@opentelemetry/api';\nimport type { ErrorHandler } from './types';\n\n/**\n * Returns a function that logs an error using the provided logger, or a\n * console logger if one was not provided.\n */\nexport function loggingErrorHandler(): ErrorHandler {\n return (ex: Exception) => {\n diag.error(stringifyException(ex));\n };\n}\n\n/**\n * Converts an exception into a string representation\n * @param {Exception} ex\n */\nfunction stringifyException(ex: Exception | string): string {\n if (typeof ex === 'string') {\n return ex;\n } else {\n return JSON.stringify(flattenException(ex));\n }\n}\n\n/**\n * Flattens an exception into key-value pairs by traversing the prototype chain\n * and coercing values to strings. Duplicate properties will not be overwritten;\n * the first insert wins.\n */\nfunction flattenException(ex: Exception): Record<string, string> {\n const result = {} as Record<string, string>;\n let current = ex;\n\n while (current !== null) {\n Object.getOwnPropertyNames(current).forEach(propertyName => {\n if (result[propertyName]) return;\n const value = current[propertyName as keyof typeof current];\n if (value) {\n result[propertyName] = String(value);\n }\n });\n current = Object.getPrototypeOf(current);\n }\n\n return result;\n}\n"]}

View File

@@ -0,0 +1,62 @@
import type * as api from '@opentelemetry/api';
/**
* Converts a number of milliseconds from epoch to HrTime([seconds, remainder in nanoseconds]).
* @param epochMillis
*/
export declare function millisToHrTime(epochMillis: number): api.HrTime;
/**
* @deprecated Use `performance.timeOrigin` directly.
*/
export declare function getTimeOrigin(): number;
/**
* Returns an hrtime calculated via performance component.
* @param performanceNow
*/
export declare function hrTime(performanceNow?: number): api.HrTime;
/**
*
* Converts a TimeInput to an HrTime, defaults to _hrtime().
* @param time
*/
export declare function timeInputToHrTime(time: api.TimeInput): api.HrTime;
/**
* Returns a duration of two hrTime.
* @param startTime
* @param endTime
*/
export declare function hrTimeDuration(startTime: api.HrTime, endTime: api.HrTime): api.HrTime;
/**
* Convert hrTime to timestamp, for example "2019-05-14T17:00:00.000123456Z"
* @param time
*/
export declare function hrTimeToTimeStamp(time: api.HrTime): string;
/**
* Convert hrTime to nanoseconds.
* @param time
*/
export declare function hrTimeToNanoseconds(time: api.HrTime): number;
/**
* Convert hrTime to milliseconds.
* @param time
*/
export declare function hrTimeToMilliseconds(time: api.HrTime): number;
/**
* Convert hrTime to microseconds.
* @param time
*/
export declare function hrTimeToMicroseconds(time: api.HrTime): number;
/**
* check if time is HrTime
* @param value
*/
export declare function isTimeInputHrTime(value: unknown): value is api.HrTime;
/**
* check if input value is a correct types.TimeInput
* @param value
*/
export declare function isTimeInput(value: unknown): value is api.HrTime | number | Date;
/**
* Given 2 HrTime formatted times, return their sum as an HrTime.
*/
export declare function addHrTimes(time1: api.HrTime, time2: api.HrTime): api.HrTime;
//# sourceMappingURL=time.d.ts.map

View File

@@ -0,0 +1,143 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
import { otperformance as performance } from '../platform';
const NANOSECOND_DIGITS = 9;
const NANOSECOND_DIGITS_IN_MILLIS = 6;
const MILLISECONDS_TO_NANOSECONDS = Math.pow(10, NANOSECOND_DIGITS_IN_MILLIS);
const SECOND_TO_NANOSECONDS = Math.pow(10, NANOSECOND_DIGITS);
/**
* Converts a number of milliseconds from epoch to HrTime([seconds, remainder in nanoseconds]).
* @param epochMillis
*/
export function millisToHrTime(epochMillis) {
const epochSeconds = epochMillis / 1000;
// Decimals only.
const seconds = Math.trunc(epochSeconds);
// Round sub-nanosecond accuracy to nanosecond.
const nanos = Math.round((epochMillis % 1000) * MILLISECONDS_TO_NANOSECONDS);
return [seconds, nanos];
}
/**
* @deprecated Use `performance.timeOrigin` directly.
*/
export function getTimeOrigin() {
return performance.timeOrigin;
}
/**
* Returns an hrtime calculated via performance component.
* @param performanceNow
*/
export function hrTime(performanceNow) {
const timeOrigin = millisToHrTime(performance.timeOrigin);
const now = millisToHrTime(typeof performanceNow === 'number' ? performanceNow : performance.now());
return addHrTimes(timeOrigin, now);
}
/**
*
* Converts a TimeInput to an HrTime, defaults to _hrtime().
* @param time
*/
export function timeInputToHrTime(time) {
// process.hrtime
if (isTimeInputHrTime(time)) {
return time;
}
else if (typeof time === 'number') {
// Must be a performance.now() if it's smaller than process start time.
if (time < performance.timeOrigin) {
return hrTime(time);
}
else {
// epoch milliseconds or performance.timeOrigin
return millisToHrTime(time);
}
}
else if (time instanceof Date) {
return millisToHrTime(time.getTime());
}
else {
throw TypeError('Invalid input type');
}
}
/**
* Returns a duration of two hrTime.
* @param startTime
* @param endTime
*/
export function hrTimeDuration(startTime, endTime) {
let seconds = endTime[0] - startTime[0];
let nanos = endTime[1] - startTime[1];
// overflow
if (nanos < 0) {
seconds -= 1;
// negate
nanos += SECOND_TO_NANOSECONDS;
}
return [seconds, nanos];
}
/**
* Convert hrTime to timestamp, for example "2019-05-14T17:00:00.000123456Z"
* @param time
*/
export function hrTimeToTimeStamp(time) {
const precision = NANOSECOND_DIGITS;
const tmp = `${'0'.repeat(precision)}${time[1]}Z`;
const nanoString = tmp.substring(tmp.length - precision - 1);
const date = new Date(time[0] * 1000).toISOString();
return date.replace('000Z', nanoString);
}
/**
* Convert hrTime to nanoseconds.
* @param time
*/
export function hrTimeToNanoseconds(time) {
return time[0] * SECOND_TO_NANOSECONDS + time[1];
}
/**
* Convert hrTime to milliseconds.
* @param time
*/
export function hrTimeToMilliseconds(time) {
return time[0] * 1e3 + time[1] / 1e6;
}
/**
* Convert hrTime to microseconds.
* @param time
*/
export function hrTimeToMicroseconds(time) {
return time[0] * 1e6 + time[1] / 1e3;
}
/**
* check if time is HrTime
* @param value
*/
export function isTimeInputHrTime(value) {
return (Array.isArray(value) &&
value.length === 2 &&
typeof value[0] === 'number' &&
typeof value[1] === 'number');
}
/**
* check if input value is a correct types.TimeInput
* @param value
*/
export function isTimeInput(value) {
return (isTimeInputHrTime(value) ||
typeof value === 'number' ||
value instanceof Date);
}
/**
* Given 2 HrTime formatted times, return their sum as an HrTime.
*/
export function addHrTimes(time1, time2) {
const out = [time1[0] + time2[0], time1[1] + time2[1]];
// Nanoseconds
if (out[1] >= SECOND_TO_NANOSECONDS) {
out[1] -= SECOND_TO_NANOSECONDS;
out[0] += 1;
}
return out;
}
//# sourceMappingURL=time.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,8 @@
/**
* @deprecated please copy this code to your implementation instead, this function will be removed in the next major version of this package.
* @param timer
*/
export declare function unrefTimer(timer: {
unref(): unknown;
} | number): void;
//# sourceMappingURL=timer-util.d.ts.map

View File

@@ -0,0 +1,14 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @deprecated please copy this code to your implementation instead, this function will be removed in the next major version of this package.
* @param timer
*/
export function unrefTimer(timer) {
if (typeof timer !== 'number') {
timer.unref();
}
}
//# sourceMappingURL=timer-util.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"timer-util.js","sourceRoot":"","sources":["../../../src/common/timer-util.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;GAGG;AACH,MAAM,UAAU,UAAU,CAAC,KAAoC;IAC7D,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;QAC7B,KAAK,CAAC,KAAK,EAAE,CAAC;KACf;AACH,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\n/**\n * @deprecated please copy this code to your implementation instead, this function will be removed in the next major version of this package.\n * @param timer\n */\nexport function unrefTimer(timer: { unref(): unknown } | number): void {\n if (typeof timer !== 'number') {\n timer.unref();\n }\n}\n"]}

View File

@@ -0,0 +1,23 @@
import type { Exception } from '@opentelemetry/api';
/**
* This interface defines the params that are be added to the wrapped function
* using the "shimmer.wrap"
*/
export interface ShimWrapped extends Function {
__wrapped: boolean;
__unwrap: Function;
__original: Function;
}
/**
* An instrumentation scope consists of the name and optional version
* used to obtain a tracer or meter from a provider. This metadata is made
* available on ReadableSpan and MetricRecord for use by the export pipeline.
*/
export interface InstrumentationScope {
readonly name: string;
readonly version?: string;
readonly schemaUrl?: string;
}
/** Defines an error handler function */
export type ErrorHandler = (ex: Exception) => void;
//# sourceMappingURL=types.d.ts.map

View File

@@ -0,0 +1,6 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
export {};
//# sourceMappingURL=types.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/common/types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { Exception } from '@opentelemetry/api';\n\n/**\n * This interface defines the params that are be added to the wrapped function\n * using the \"shimmer.wrap\"\n */\nexport interface ShimWrapped extends Function {\n __wrapped: boolean;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\n __unwrap: Function;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\n __original: Function;\n}\n\n/**\n * An instrumentation scope consists of the name and optional version\n * used to obtain a tracer or meter from a provider. This metadata is made\n * available on ReadableSpan and MetricRecord for use by the export pipeline.\n */\nexport interface InstrumentationScope {\n readonly name: string;\n readonly version?: string;\n readonly schemaUrl?: string;\n}\n\n/** Defines an error handler function */\nexport type ErrorHandler = (ex: Exception) => void;\n"]}

View File

@@ -0,0 +1,30 @@
export { W3CBaggagePropagator } from './baggage/propagation/W3CBaggagePropagator';
export { AnchoredClock } from './common/anchored-clock';
export type { Clock } from './common/anchored-clock';
export { isAttributeValue, sanitizeAttributes } from './common/attributes';
export { globalErrorHandler, setGlobalErrorHandler, } from './common/global-error-handler';
export { loggingErrorHandler } from './common/logging-error-handler';
export { addHrTimes, getTimeOrigin, hrTime, hrTimeDuration, hrTimeToMicroseconds, hrTimeToMilliseconds, hrTimeToNanoseconds, hrTimeToTimeStamp, isTimeInput, isTimeInputHrTime, millisToHrTime, timeInputToHrTime, } from './common/time';
export { unrefTimer } from './common/timer-util';
export type { ErrorHandler, InstrumentationScope } from './common/types';
export { ExportResultCode } from './ExportResult';
export type { ExportResult } from './ExportResult';
export { parseKeyPairsIntoRecord } from './baggage/utils';
export { SDK_INFO, _globalThis, getStringFromEnv, getBooleanFromEnv, getNumberFromEnv, getStringListFromEnv, otperformance, } from './platform';
export { CompositePropagator } from './propagation/composite';
export type { CompositePropagatorConfig } from './propagation/composite';
export { TRACE_PARENT_HEADER, TRACE_STATE_HEADER, W3CTraceContextPropagator, parseTraceParent, } from './trace/W3CTraceContextPropagator';
export { RPCType, deleteRPCMetadata, getRPCMetadata, setRPCMetadata, } from './trace/rpc-metadata';
export type { RPCMetadata } from './trace/rpc-metadata';
export { isTracingSuppressed, suppressTracing, unsuppressTracing, } from './trace/suppress-tracing';
export { TraceState } from './trace/TraceState';
export { merge } from './utils/merge';
export { TimeoutError, callWithTimeout } from './utils/timeout';
export { isUrlIgnored, urlMatches } from './utils/url';
export { BindOnceFuture } from './utils/callback';
export { diagLogLevelFromString } from './utils/configuration';
import { _export } from './internal/exporter';
export declare const internal: {
_export: typeof _export;
};
//# sourceMappingURL=index.d.ts.map

View File

@@ -0,0 +1,29 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
export { W3CBaggagePropagator } from './baggage/propagation/W3CBaggagePropagator';
export { AnchoredClock } from './common/anchored-clock';
export { isAttributeValue, sanitizeAttributes } from './common/attributes';
export { globalErrorHandler, setGlobalErrorHandler, } from './common/global-error-handler';
export { loggingErrorHandler } from './common/logging-error-handler';
export { addHrTimes, getTimeOrigin, hrTime, hrTimeDuration, hrTimeToMicroseconds, hrTimeToMilliseconds, hrTimeToNanoseconds, hrTimeToTimeStamp, isTimeInput, isTimeInputHrTime, millisToHrTime, timeInputToHrTime, } from './common/time';
export { unrefTimer } from './common/timer-util';
export { ExportResultCode } from './ExportResult';
export { parseKeyPairsIntoRecord } from './baggage/utils';
export { SDK_INFO, _globalThis, getStringFromEnv, getBooleanFromEnv, getNumberFromEnv, getStringListFromEnv, otperformance, } from './platform';
export { CompositePropagator } from './propagation/composite';
export { TRACE_PARENT_HEADER, TRACE_STATE_HEADER, W3CTraceContextPropagator, parseTraceParent, } from './trace/W3CTraceContextPropagator';
export { RPCType, deleteRPCMetadata, getRPCMetadata, setRPCMetadata, } from './trace/rpc-metadata';
export { isTracingSuppressed, suppressTracing, unsuppressTracing, } from './trace/suppress-tracing';
export { TraceState } from './trace/TraceState';
export { merge } from './utils/merge';
export { TimeoutError, callWithTimeout } from './utils/timeout';
export { isUrlIgnored, urlMatches } from './utils/url';
export { BindOnceFuture } from './utils/callback';
export { diagLogLevelFromString } from './utils/configuration';
import { _export } from './internal/exporter';
export const internal = {
_export,
};
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,4CAA4C,CAAC;AAClF,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAExD,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAC3E,OAAO,EACL,kBAAkB,EAClB,qBAAqB,GACtB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,EACL,UAAU,EACV,aAAa,EACb,MAAM,EACN,cAAc,EACd,oBAAoB,EACpB,oBAAoB,EACpB,mBAAmB,EACnB,iBAAiB,EACjB,WAAW,EACX,iBAAiB,EACjB,cAAc,EACd,iBAAiB,GAClB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAElD,OAAO,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAC1D,OAAO,EACL,QAAQ,EACR,WAAW,EACX,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,oBAAoB,EACpB,aAAa,GACd,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAE9D,OAAO,EACL,mBAAmB,EACnB,kBAAkB,EAClB,yBAAyB,EACzB,gBAAgB,GACjB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EACL,OAAO,EACP,iBAAiB,EACjB,cAAc,EACd,cAAc,GACf,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EACL,mBAAmB,EACnB,eAAe,EACf,iBAAiB,GAClB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,OAAO;CACR,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nexport { W3CBaggagePropagator } from './baggage/propagation/W3CBaggagePropagator';\nexport { AnchoredClock } from './common/anchored-clock';\nexport type { Clock } from './common/anchored-clock';\nexport { isAttributeValue, sanitizeAttributes } from './common/attributes';\nexport {\n globalErrorHandler,\n setGlobalErrorHandler,\n} from './common/global-error-handler';\nexport { loggingErrorHandler } from './common/logging-error-handler';\nexport {\n addHrTimes,\n getTimeOrigin,\n hrTime,\n hrTimeDuration,\n hrTimeToMicroseconds,\n hrTimeToMilliseconds,\n hrTimeToNanoseconds,\n hrTimeToTimeStamp,\n isTimeInput,\n isTimeInputHrTime,\n millisToHrTime,\n timeInputToHrTime,\n} from './common/time';\nexport { unrefTimer } from './common/timer-util';\nexport type { ErrorHandler, InstrumentationScope } from './common/types';\nexport { ExportResultCode } from './ExportResult';\nexport type { ExportResult } from './ExportResult';\nexport { parseKeyPairsIntoRecord } from './baggage/utils';\nexport {\n SDK_INFO,\n _globalThis,\n getStringFromEnv,\n getBooleanFromEnv,\n getNumberFromEnv,\n getStringListFromEnv,\n otperformance,\n} from './platform';\nexport { CompositePropagator } from './propagation/composite';\nexport type { CompositePropagatorConfig } from './propagation/composite';\nexport {\n TRACE_PARENT_HEADER,\n TRACE_STATE_HEADER,\n W3CTraceContextPropagator,\n parseTraceParent,\n} from './trace/W3CTraceContextPropagator';\nexport {\n RPCType,\n deleteRPCMetadata,\n getRPCMetadata,\n setRPCMetadata,\n} from './trace/rpc-metadata';\nexport type { RPCMetadata } from './trace/rpc-metadata';\nexport {\n isTracingSuppressed,\n suppressTracing,\n unsuppressTracing,\n} from './trace/suppress-tracing';\nexport { TraceState } from './trace/TraceState';\nexport { merge } from './utils/merge';\nexport { TimeoutError, callWithTimeout } from './utils/timeout';\nexport { isUrlIgnored, urlMatches } from './utils/url';\nexport { BindOnceFuture } from './utils/callback';\nexport { diagLogLevelFromString } from './utils/configuration';\nimport { _export } from './internal/exporter';\nexport const internal = {\n _export,\n};\n"]}

View File

@@ -0,0 +1,10 @@
import type { ExportResult } from '../ExportResult';
export interface Exporter<T> {
export(arg: T, resultCallback: (result: ExportResult) => void): void;
}
/**
* @internal
* Shared functionality used by Exporters while exporting data, including suppression of Traces.
*/
export declare function _export<T>(exporter: Exporter<T>, arg: T): Promise<ExportResult>;
//# sourceMappingURL=exporter.d.ts.map

View File

@@ -0,0 +1,19 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
import { context } from '@opentelemetry/api';
import { suppressTracing } from '../trace/suppress-tracing';
/**
* @internal
* Shared functionality used by Exporters while exporting data, including suppression of Traces.
*/
export function _export(exporter, arg) {
return new Promise(resolve => {
// prevent downstream exporter calls from generating spans
context.with(suppressTracing(context.active()), () => {
exporter.export(arg, resolve);
});
});
}
//# sourceMappingURL=exporter.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"exporter.js","sourceRoot":"","sources":["../../../src/internal/exporter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAE7C,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAM5D;;;GAGG;AACH,MAAM,UAAU,OAAO,CACrB,QAAqB,EACrB,GAAM;IAEN,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE;QAC3B,0DAA0D;QAC1D,OAAO,CAAC,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,GAAG,EAAE;YACnD,QAAQ,CAAC,MAAM,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;QAChC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { context } from '@opentelemetry/api';\nimport type { ExportResult } from '../ExportResult';\nimport { suppressTracing } from '../trace/suppress-tracing';\n\nexport interface Exporter<T> {\n export(arg: T, resultCallback: (result: ExportResult) => void): void;\n}\n\n/**\n * @internal\n * Shared functionality used by Exporters while exporting data, including suppression of Traces.\n */\nexport function _export<T>(\n exporter: Exporter<T>,\n arg: T\n): Promise<ExportResult> {\n return new Promise(resolve => {\n // prevent downstream exporter calls from generating spans\n context.with(suppressTracing(context.active()), () => {\n exporter.export(arg, resolve);\n });\n });\n}\n"]}

View File

@@ -0,0 +1,15 @@
/**
* Key is opaque string up to 256 characters printable. It MUST begin with a
* lowercase letter, and can only contain lowercase letters a-z, digits 0-9,
* underscores _, dashes -, asterisks *, and forward slashes /.
* For multi-tenant vendor scenarios, an at sign (@) can be used to prefix the
* vendor name. Vendors SHOULD set the tenant ID at the beginning of the key.
* see https://www.w3.org/TR/trace-context/#key
*/
export declare function validateKey(key: string): boolean;
/**
* Value is opaque string up to 256 characters printable ASCII RFC0020
* characters (i.e., the range 0x20 to 0x7E) except comma , and =.
*/
export declare function validateValue(value: string): boolean;
//# sourceMappingURL=validators.d.ts.map

View File

@@ -0,0 +1,30 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
const VALID_KEY_CHAR_RANGE = '[_0-9a-z-*/]';
const VALID_KEY = `[a-z]${VALID_KEY_CHAR_RANGE}{0,255}`;
const VALID_VENDOR_KEY = `[a-z0-9]${VALID_KEY_CHAR_RANGE}{0,240}@[a-z]${VALID_KEY_CHAR_RANGE}{0,13}`;
const VALID_KEY_REGEX = new RegExp(`^(?:${VALID_KEY}|${VALID_VENDOR_KEY})$`);
const VALID_VALUE_BASE_REGEX = /^[ -~]{0,255}[!-~]$/;
const INVALID_VALUE_COMMA_EQUAL_REGEX = /,|=/;
/**
* Key is opaque string up to 256 characters printable. It MUST begin with a
* lowercase letter, and can only contain lowercase letters a-z, digits 0-9,
* underscores _, dashes -, asterisks *, and forward slashes /.
* For multi-tenant vendor scenarios, an at sign (@) can be used to prefix the
* vendor name. Vendors SHOULD set the tenant ID at the beginning of the key.
* see https://www.w3.org/TR/trace-context/#key
*/
export function validateKey(key) {
return VALID_KEY_REGEX.test(key);
}
/**
* Value is opaque string up to 256 characters printable ASCII RFC0020
* characters (i.e., the range 0x20 to 0x7E) except comma , and =.
*/
export function validateValue(value) {
return (VALID_VALUE_BASE_REGEX.test(value) &&
!INVALID_VALUE_COMMA_EQUAL_REGEX.test(value));
}
//# sourceMappingURL=validators.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"validators.js","sourceRoot":"","sources":["../../../src/internal/validators.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,oBAAoB,GAAG,cAAc,CAAC;AAC5C,MAAM,SAAS,GAAG,QAAQ,oBAAoB,SAAS,CAAC;AACxD,MAAM,gBAAgB,GAAG,WAAW,oBAAoB,gBAAgB,oBAAoB,QAAQ,CAAC;AACrG,MAAM,eAAe,GAAG,IAAI,MAAM,CAAC,OAAO,SAAS,IAAI,gBAAgB,IAAI,CAAC,CAAC;AAC7E,MAAM,sBAAsB,GAAG,qBAAqB,CAAC;AACrD,MAAM,+BAA+B,GAAG,KAAK,CAAC;AAE9C;;;;;;;GAOG;AACH,MAAM,UAAU,WAAW,CAAC,GAAW;IACrC,OAAO,eAAe,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACnC,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,KAAa;IACzC,OAAO,CACL,sBAAsB,CAAC,IAAI,CAAC,KAAK,CAAC;QAClC,CAAC,+BAA+B,CAAC,IAAI,CAAC,KAAK,CAAC,CAC7C,CAAC;AACJ,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nconst VALID_KEY_CHAR_RANGE = '[_0-9a-z-*/]';\nconst VALID_KEY = `[a-z]${VALID_KEY_CHAR_RANGE}{0,255}`;\nconst VALID_VENDOR_KEY = `[a-z0-9]${VALID_KEY_CHAR_RANGE}{0,240}@[a-z]${VALID_KEY_CHAR_RANGE}{0,13}`;\nconst VALID_KEY_REGEX = new RegExp(`^(?:${VALID_KEY}|${VALID_VENDOR_KEY})$`);\nconst VALID_VALUE_BASE_REGEX = /^[ -~]{0,255}[!-~]$/;\nconst INVALID_VALUE_COMMA_EQUAL_REGEX = /,|=/;\n\n/**\n * Key is opaque string up to 256 characters printable. It MUST begin with a\n * lowercase letter, and can only contain lowercase letters a-z, digits 0-9,\n * underscores _, dashes -, asterisks *, and forward slashes /.\n * For multi-tenant vendor scenarios, an at sign (@) can be used to prefix the\n * vendor name. Vendors SHOULD set the tenant ID at the beginning of the key.\n * see https://www.w3.org/TR/trace-context/#key\n */\nexport function validateKey(key: string): boolean {\n return VALID_KEY_REGEX.test(key);\n}\n\n/**\n * Value is opaque string up to 256 characters printable ASCII RFC0020\n * characters (i.e., the range 0x20 to 0x7E) except comma , and =.\n */\nexport function validateValue(value: string): boolean {\n return (\n VALID_VALUE_BASE_REGEX.test(value) &&\n !INVALID_VALUE_COMMA_EQUAL_REGEX.test(value)\n );\n}\n"]}

View File

@@ -0,0 +1,5 @@
export declare function getStringFromEnv(_: string): string | undefined;
export declare function getBooleanFromEnv(_: string): boolean | undefined;
export declare function getNumberFromEnv(_: string): number | undefined;
export declare function getStringListFromEnv(_: string): string[] | undefined;
//# sourceMappingURL=environment.d.ts.map

View File

@@ -0,0 +1,17 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
export function getStringFromEnv(_) {
return undefined;
}
export function getBooleanFromEnv(_) {
return undefined;
}
export function getNumberFromEnv(_) {
return undefined;
}
export function getStringListFromEnv(_) {
return undefined;
}
//# sourceMappingURL=environment.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"environment.js","sourceRoot":"","sources":["../../../../src/platform/browser/environment.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,UAAU,gBAAgB,CAAC,CAAS;IACxC,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,CAAS;IACzC,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,CAAS;IACxC,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,CAAS;IAC5C,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nexport function getStringFromEnv(_: string): string | undefined {\n return undefined;\n}\n\nexport function getBooleanFromEnv(_: string): boolean | undefined {\n return undefined;\n}\n\nexport function getNumberFromEnv(_: string): number | undefined {\n return undefined;\n}\n\nexport function getStringListFromEnv(_: string): string[] | undefined {\n return undefined;\n}\n"]}

View File

@@ -0,0 +1,8 @@
export { getStringFromEnv, getBooleanFromEnv, getNumberFromEnv, getStringListFromEnv, } from './environment';
export { _globalThis } from '../../common/globalThis';
export { SDK_INFO } from './sdk-info';
/**
* @deprecated Use performance directly.
*/
export declare const otperformance: Performance;
//# sourceMappingURL=index.d.ts.map

View File

@@ -0,0 +1,12 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
export { getStringFromEnv, getBooleanFromEnv, getNumberFromEnv, getStringListFromEnv, } from './environment';
export { _globalThis } from '../../common/globalThis';
export { SDK_INFO } from './sdk-info';
/**
* @deprecated Use performance directly.
*/
export const otperformance = performance;
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/platform/browser/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,oBAAoB,GACrB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC;;GAEG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,WAAW,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nexport {\n getStringFromEnv,\n getBooleanFromEnv,\n getNumberFromEnv,\n getStringListFromEnv,\n} from './environment';\nexport { _globalThis } from '../../common/globalThis';\nexport { SDK_INFO } from './sdk-info';\n\n/**\n * @deprecated Use performance directly.\n */\nexport const otperformance = performance;\n"]}

View File

@@ -0,0 +1,8 @@
/** Constants describing the SDK in use */
export declare const SDK_INFO: {
"telemetry.sdk.name": string;
"process.runtime.name": string;
"telemetry.sdk.language": "webjs";
"telemetry.sdk.version": string;
};
//# sourceMappingURL=sdk-info.d.ts.map

View File

@@ -0,0 +1,15 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
import { VERSION } from '../../version';
import { ATTR_TELEMETRY_SDK_NAME, ATTR_TELEMETRY_SDK_LANGUAGE, TELEMETRY_SDK_LANGUAGE_VALUE_WEBJS, ATTR_TELEMETRY_SDK_VERSION, } from '@opentelemetry/semantic-conventions';
import { ATTR_PROCESS_RUNTIME_NAME } from '../../semconv';
/** Constants describing the SDK in use */
export const SDK_INFO = {
[ATTR_TELEMETRY_SDK_NAME]: 'opentelemetry',
[ATTR_PROCESS_RUNTIME_NAME]: 'browser',
[ATTR_TELEMETRY_SDK_LANGUAGE]: TELEMETRY_SDK_LANGUAGE_VALUE_WEBJS,
[ATTR_TELEMETRY_SDK_VERSION]: VERSION,
};
//# sourceMappingURL=sdk-info.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"sdk-info.js","sourceRoot":"","sources":["../../../../src/platform/browser/sdk-info.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EACL,uBAAuB,EACvB,2BAA2B,EAC3B,kCAAkC,EAClC,0BAA0B,GAC3B,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC;AAE1D,0CAA0C;AAC1C,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,CAAC,uBAAuB,CAAC,EAAE,eAAe;IAC1C,CAAC,yBAAyB,CAAC,EAAE,SAAS;IACtC,CAAC,2BAA2B,CAAC,EAAE,kCAAkC;IACjE,CAAC,0BAA0B,CAAC,EAAE,OAAO;CACtC,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { VERSION } from '../../version';\nimport {\n ATTR_TELEMETRY_SDK_NAME,\n ATTR_TELEMETRY_SDK_LANGUAGE,\n TELEMETRY_SDK_LANGUAGE_VALUE_WEBJS,\n ATTR_TELEMETRY_SDK_VERSION,\n} from '@opentelemetry/semantic-conventions';\nimport { ATTR_PROCESS_RUNTIME_NAME } from '../../semconv';\n\n/** Constants describing the SDK in use */\nexport const SDK_INFO = {\n [ATTR_TELEMETRY_SDK_NAME]: 'opentelemetry',\n [ATTR_PROCESS_RUNTIME_NAME]: 'browser',\n [ATTR_TELEMETRY_SDK_LANGUAGE]: TELEMETRY_SDK_LANGUAGE_VALUE_WEBJS,\n [ATTR_TELEMETRY_SDK_VERSION]: VERSION,\n};\n"]}

View File

@@ -0,0 +1,2 @@
export { SDK_INFO, _globalThis, otperformance, getBooleanFromEnv, getStringFromEnv, getNumberFromEnv, getStringListFromEnv, } from './node';
//# sourceMappingURL=index.d.ts.map

View File

@@ -0,0 +1,6 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
export { SDK_INFO, _globalThis, otperformance, getBooleanFromEnv, getStringFromEnv, getNumberFromEnv, getStringListFromEnv, } from './node';
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/platform/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EACL,QAAQ,EACR,WAAW,EACX,aAAa,EACb,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,EAChB,oBAAoB,GACrB,MAAM,QAAQ,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\nexport {\n SDK_INFO,\n _globalThis,\n otperformance,\n getBooleanFromEnv,\n getStringFromEnv,\n getNumberFromEnv,\n getStringListFromEnv,\n} from './node';\n"]}

View File

@@ -0,0 +1,40 @@
/**
* Retrieves a number from an environment variable.
* - Returns `undefined` if the environment variable is empty, unset, contains only whitespace, or is not a number.
* - Returns a number in all other cases.
*
* @param {string} key - The name of the environment variable to retrieve.
* @returns {number | undefined} - The number value or `undefined`.
*/
export declare function getNumberFromEnv(key: string): number | undefined;
/**
* Retrieves a string from an environment variable.
* - Returns `undefined` if the environment variable is empty, unset, or contains only whitespace.
*
* @param {string} key - The name of the environment variable to retrieve.
* @returns {string | undefined} - The string value or `undefined`.
*/
export declare function getStringFromEnv(key: string): string | undefined;
/**
* Retrieves a boolean value from an environment variable.
* - Trims leading and trailing whitespace and ignores casing.
* - Returns `false` if the environment variable is empty, unset, or contains only whitespace.
* - Returns `false` for strings that cannot be mapped to a boolean.
*
* @param {string} key - The name of the environment variable to retrieve.
* @returns {boolean} - The boolean value or `false` if the environment variable is unset empty, unset, or contains only whitespace.
*/
export declare function getBooleanFromEnv(key: string): boolean;
/**
* Retrieves a list of strings from an environment variable.
* - Uses ',' as the delimiter.
* - Trims leading and trailing whitespace from each entry.
* - Excludes empty entries.
* - Returns `undefined` if the environment variable is empty or contains only whitespace.
* - Returns an empty array if all entries are empty or whitespace.
*
* @param {string} key - The name of the environment variable to retrieve.
* @returns {string[] | undefined} - The list of strings or `undefined`.
*/
export declare function getStringListFromEnv(key: string): string[] | undefined;
//# sourceMappingURL=environment.d.ts.map

View File

@@ -0,0 +1,86 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
import { diag } from '@opentelemetry/api';
import { inspect } from 'util';
/**
* Retrieves a number from an environment variable.
* - Returns `undefined` if the environment variable is empty, unset, contains only whitespace, or is not a number.
* - Returns a number in all other cases.
*
* @param {string} key - The name of the environment variable to retrieve.
* @returns {number | undefined} - The number value or `undefined`.
*/
export function getNumberFromEnv(key) {
const raw = process.env[key];
if (raw == null || raw.trim() === '') {
return undefined;
}
const value = Number(raw);
if (isNaN(value)) {
diag.warn(`Unknown value ${inspect(raw)} for ${key}, expected a number, using defaults`);
return undefined;
}
return value;
}
/**
* Retrieves a string from an environment variable.
* - Returns `undefined` if the environment variable is empty, unset, or contains only whitespace.
*
* @param {string} key - The name of the environment variable to retrieve.
* @returns {string | undefined} - The string value or `undefined`.
*/
export function getStringFromEnv(key) {
const raw = process.env[key];
if (raw == null || raw.trim() === '') {
return undefined;
}
return raw;
}
/**
* Retrieves a boolean value from an environment variable.
* - Trims leading and trailing whitespace and ignores casing.
* - Returns `false` if the environment variable is empty, unset, or contains only whitespace.
* - Returns `false` for strings that cannot be mapped to a boolean.
*
* @param {string} key - The name of the environment variable to retrieve.
* @returns {boolean} - The boolean value or `false` if the environment variable is unset empty, unset, or contains only whitespace.
*/
export function getBooleanFromEnv(key) {
const raw = process.env[key]?.trim().toLowerCase();
if (raw == null || raw === '') {
// NOTE: falling back to `false` instead of `undefined` as required by the specification.
// If you have a use-case that requires `undefined`, consider using `getStringFromEnv()` and applying the necessary
// normalizations in the consuming code.
return false;
}
if (raw === 'true') {
return true;
}
else if (raw === 'false') {
return false;
}
else {
diag.warn(`Unknown value ${inspect(raw)} for ${key}, expected 'true' or 'false', falling back to 'false' (default)`);
return false;
}
}
/**
* Retrieves a list of strings from an environment variable.
* - Uses ',' as the delimiter.
* - Trims leading and trailing whitespace from each entry.
* - Excludes empty entries.
* - Returns `undefined` if the environment variable is empty or contains only whitespace.
* - Returns an empty array if all entries are empty or whitespace.
*
* @param {string} key - The name of the environment variable to retrieve.
* @returns {string[] | undefined} - The list of strings or `undefined`.
*/
export function getStringListFromEnv(key) {
return getStringFromEnv(key)
?.split(',')
.map(v => v.trim())
.filter(s => s !== '');
}
//# sourceMappingURL=environment.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"environment.js","sourceRoot":"","sources":["../../../../src/platform/node/environment.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAE/B;;;;;;;GAOG;AACH,MAAM,UAAU,gBAAgB,CAAC,GAAW;IAC1C,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC7B,IAAI,GAAG,IAAI,IAAI,IAAI,GAAG,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;QACpC,OAAO,SAAS,CAAC;KAClB;IAED,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;IAC1B,IAAI,KAAK,CAAC,KAAK,CAAC,EAAE;QAChB,IAAI,CAAC,IAAI,CACP,iBAAiB,OAAO,CAAC,GAAG,CAAC,QAAQ,GAAG,qCAAqC,CAC9E,CAAC;QACF,OAAO,SAAS,CAAC;KAClB;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAAC,GAAW;IAC1C,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC7B,IAAI,GAAG,IAAI,IAAI,IAAI,GAAG,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;QACpC,OAAO,SAAS,CAAC;KAClB;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,iBAAiB,CAAC,GAAW;IAC3C,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IACnD,IAAI,GAAG,IAAI,IAAI,IAAI,GAAG,KAAK,EAAE,EAAE;QAC7B,yFAAyF;QACzF,mHAAmH;QACnH,wCAAwC;QACxC,OAAO,KAAK,CAAC;KACd;IACD,IAAI,GAAG,KAAK,MAAM,EAAE;QAClB,OAAO,IAAI,CAAC;KACb;SAAM,IAAI,GAAG,KAAK,OAAO,EAAE;QAC1B,OAAO,KAAK,CAAC;KACd;SAAM;QACL,IAAI,CAAC,IAAI,CACP,iBAAiB,OAAO,CAAC,GAAG,CAAC,QAAQ,GAAG,iEAAiE,CAC1G,CAAC;QACF,OAAO,KAAK,CAAC;KACd;AACH,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,oBAAoB,CAAC,GAAW;IAC9C,OAAO,gBAAgB,CAAC,GAAG,CAAC;QAC1B,EAAE,KAAK,CAAC,GAAG,CAAC;SACX,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;SAClB,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC;AAC3B,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { diag } from '@opentelemetry/api';\nimport { inspect } from 'util';\n\n/**\n * Retrieves a number from an environment variable.\n * - Returns `undefined` if the environment variable is empty, unset, contains only whitespace, or is not a number.\n * - Returns a number in all other cases.\n *\n * @param {string} key - The name of the environment variable to retrieve.\n * @returns {number | undefined} - The number value or `undefined`.\n */\nexport function getNumberFromEnv(key: string): number | undefined {\n const raw = process.env[key];\n if (raw == null || raw.trim() === '') {\n return undefined;\n }\n\n const value = Number(raw);\n if (isNaN(value)) {\n diag.warn(\n `Unknown value ${inspect(raw)} for ${key}, expected a number, using defaults`\n );\n return undefined;\n }\n\n return value;\n}\n\n/**\n * Retrieves a string from an environment variable.\n * - Returns `undefined` if the environment variable is empty, unset, or contains only whitespace.\n *\n * @param {string} key - The name of the environment variable to retrieve.\n * @returns {string | undefined} - The string value or `undefined`.\n */\nexport function getStringFromEnv(key: string): string | undefined {\n const raw = process.env[key];\n if (raw == null || raw.trim() === '') {\n return undefined;\n }\n return raw;\n}\n\n/**\n * Retrieves a boolean value from an environment variable.\n * - Trims leading and trailing whitespace and ignores casing.\n * - Returns `false` if the environment variable is empty, unset, or contains only whitespace.\n * - Returns `false` for strings that cannot be mapped to a boolean.\n *\n * @param {string} key - The name of the environment variable to retrieve.\n * @returns {boolean} - The boolean value or `false` if the environment variable is unset empty, unset, or contains only whitespace.\n */\nexport function getBooleanFromEnv(key: string): boolean {\n const raw = process.env[key]?.trim().toLowerCase();\n if (raw == null || raw === '') {\n // NOTE: falling back to `false` instead of `undefined` as required by the specification.\n // If you have a use-case that requires `undefined`, consider using `getStringFromEnv()` and applying the necessary\n // normalizations in the consuming code.\n return false;\n }\n if (raw === 'true') {\n return true;\n } else if (raw === 'false') {\n return false;\n } else {\n diag.warn(\n `Unknown value ${inspect(raw)} for ${key}, expected 'true' or 'false', falling back to 'false' (default)`\n );\n return false;\n }\n}\n\n/**\n * Retrieves a list of strings from an environment variable.\n * - Uses ',' as the delimiter.\n * - Trims leading and trailing whitespace from each entry.\n * - Excludes empty entries.\n * - Returns `undefined` if the environment variable is empty or contains only whitespace.\n * - Returns an empty array if all entries are empty or whitespace.\n *\n * @param {string} key - The name of the environment variable to retrieve.\n * @returns {string[] | undefined} - The list of strings or `undefined`.\n */\nexport function getStringListFromEnv(key: string): string[] | undefined {\n return getStringFromEnv(key)\n ?.split(',')\n .map(v => v.trim())\n .filter(s => s !== '');\n}\n"]}

View File

@@ -0,0 +1,11 @@
export { getStringFromEnv, getBooleanFromEnv, getNumberFromEnv, getStringListFromEnv, } from './environment';
export { _globalThis } from '../../common/globalThis';
export { SDK_INFO } from './sdk-info';
/**
* @deprecated Use performance directly.
*/
export declare const otperformance: {
now(): number;
readonly timeOrigin: number;
};
//# sourceMappingURL=index.d.ts.map

View File

@@ -0,0 +1,12 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
export { getStringFromEnv, getBooleanFromEnv, getNumberFromEnv, getStringListFromEnv, } from './environment';
export { _globalThis } from '../../common/globalThis';
export { SDK_INFO } from './sdk-info';
/**
* @deprecated Use performance directly.
*/
export const otperformance = performance;
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/platform/node/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,oBAAoB,GACrB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC;;GAEG;AACH,MAAM,CAAC,MAAM,aAAa,GACxB,WAAW,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nexport {\n getStringFromEnv,\n getBooleanFromEnv,\n getNumberFromEnv,\n getStringListFromEnv,\n} from './environment';\nexport { _globalThis } from '../../common/globalThis';\nexport { SDK_INFO } from './sdk-info';\n\n/**\n * @deprecated Use performance directly.\n */\nexport const otperformance: { now(): number; readonly timeOrigin: number } =\n performance;\n"]}

View File

@@ -0,0 +1,8 @@
/** Constants describing the SDK in use */
export declare const SDK_INFO: {
"telemetry.sdk.name": string;
"process.runtime.name": string;
"telemetry.sdk.language": "nodejs";
"telemetry.sdk.version": string;
};
//# sourceMappingURL=sdk-info.d.ts.map

View File

@@ -0,0 +1,15 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
import { VERSION } from '../../version';
import { ATTR_TELEMETRY_SDK_NAME, ATTR_TELEMETRY_SDK_LANGUAGE, TELEMETRY_SDK_LANGUAGE_VALUE_NODEJS, ATTR_TELEMETRY_SDK_VERSION, } from '@opentelemetry/semantic-conventions';
import { ATTR_PROCESS_RUNTIME_NAME } from '../../semconv';
/** Constants describing the SDK in use */
export const SDK_INFO = {
[ATTR_TELEMETRY_SDK_NAME]: 'opentelemetry',
[ATTR_PROCESS_RUNTIME_NAME]: 'node',
[ATTR_TELEMETRY_SDK_LANGUAGE]: TELEMETRY_SDK_LANGUAGE_VALUE_NODEJS,
[ATTR_TELEMETRY_SDK_VERSION]: VERSION,
};
//# sourceMappingURL=sdk-info.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"sdk-info.js","sourceRoot":"","sources":["../../../../src/platform/node/sdk-info.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EACL,uBAAuB,EACvB,2BAA2B,EAC3B,mCAAmC,EACnC,0BAA0B,GAC3B,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC;AAE1D,0CAA0C;AAC1C,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,CAAC,uBAAuB,CAAC,EAAE,eAAe;IAC1C,CAAC,yBAAyB,CAAC,EAAE,MAAM;IACnC,CAAC,2BAA2B,CAAC,EAAE,mCAAmC;IAClE,CAAC,0BAA0B,CAAC,EAAE,OAAO;CACtC,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { VERSION } from '../../version';\nimport {\n ATTR_TELEMETRY_SDK_NAME,\n ATTR_TELEMETRY_SDK_LANGUAGE,\n TELEMETRY_SDK_LANGUAGE_VALUE_NODEJS,\n ATTR_TELEMETRY_SDK_VERSION,\n} from '@opentelemetry/semantic-conventions';\nimport { ATTR_PROCESS_RUNTIME_NAME } from '../../semconv';\n\n/** Constants describing the SDK in use */\nexport const SDK_INFO = {\n [ATTR_TELEMETRY_SDK_NAME]: 'opentelemetry',\n [ATTR_PROCESS_RUNTIME_NAME]: 'node',\n [ATTR_TELEMETRY_SDK_LANGUAGE]: TELEMETRY_SDK_LANGUAGE_VALUE_NODEJS,\n [ATTR_TELEMETRY_SDK_VERSION]: VERSION,\n};\n"]}

View File

@@ -0,0 +1,43 @@
import type { Context, TextMapGetter, TextMapPropagator, TextMapSetter } from '@opentelemetry/api';
/** Configuration object for composite propagator */
export interface CompositePropagatorConfig {
/**
* List of propagators to run. Propagators run in the
* list order. If a propagator later in the list writes the same context
* key as a propagator earlier in the list, the later on will "win".
*/
propagators?: TextMapPropagator[];
}
/** Combines multiple propagators into a single propagator. */
export declare class CompositePropagator implements TextMapPropagator {
private readonly _propagators;
private readonly _fields;
/**
* Construct a composite propagator from a list of propagators.
*
* @param [config] Configuration object for composite propagator
*/
constructor(config?: CompositePropagatorConfig);
/**
* Run each of the configured propagators with the given context and carrier.
* Propagators are run in the order they are configured, so if multiple
* propagators write the same carrier key, the propagator later in the list
* will "win".
*
* @param context Context to inject
* @param carrier Carrier into which context will be injected
*/
inject(context: Context, carrier: unknown, setter: TextMapSetter): void;
/**
* Run each of the configured propagators with the given context and carrier.
* Propagators are run in the order they are configured, so if multiple
* propagators write the same context key, the propagator later in the list
* will "win".
*
* @param context Context to add values to
* @param carrier Carrier from which to extract context
*/
extract(context: Context, carrier: unknown, getter: TextMapGetter): Context;
fields(): string[];
}
//# sourceMappingURL=composite.d.ts.map

View File

@@ -0,0 +1,66 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
import { diag } from '@opentelemetry/api';
/** Combines multiple propagators into a single propagator. */
export class CompositePropagator {
_propagators;
_fields;
/**
* Construct a composite propagator from a list of propagators.
*
* @param [config] Configuration object for composite propagator
*/
constructor(config = {}) {
this._propagators = config.propagators ?? [];
this._fields = Array.from(new Set(this._propagators
// older propagators may not have fields function, null check to be sure
.map(p => (typeof p.fields === 'function' ? p.fields() : []))
.reduce((x, y) => x.concat(y), [])));
}
/**
* Run each of the configured propagators with the given context and carrier.
* Propagators are run in the order they are configured, so if multiple
* propagators write the same carrier key, the propagator later in the list
* will "win".
*
* @param context Context to inject
* @param carrier Carrier into which context will be injected
*/
inject(context, carrier, setter) {
for (const propagator of this._propagators) {
try {
propagator.inject(context, carrier, setter);
}
catch (err) {
diag.warn(`Failed to inject with ${propagator.constructor.name}. Err: ${err.message}`);
}
}
}
/**
* Run each of the configured propagators with the given context and carrier.
* Propagators are run in the order they are configured, so if multiple
* propagators write the same context key, the propagator later in the list
* will "win".
*
* @param context Context to add values to
* @param carrier Carrier from which to extract context
*/
extract(context, carrier, getter) {
return this._propagators.reduce((ctx, propagator) => {
try {
return propagator.extract(ctx, carrier, getter);
}
catch (err) {
diag.warn(`Failed to extract with ${propagator.constructor.name}. Err: ${err.message}`);
}
return ctx;
}, context);
}
fields() {
// return a new array so our fields cannot be modified
return this._fields.slice();
}
}
//# sourceMappingURL=composite.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"composite.js","sourceRoot":"","sources":["../../../src/propagation/composite.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAQH,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAY1C,8DAA8D;AAC9D,MAAM,OAAO,mBAAmB;IACb,YAAY,CAAsB;IAClC,OAAO,CAAW;IAEnC;;;;OAIG;IACH,YAAY,SAAoC,EAAE;QAChD,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC,WAAW,IAAI,EAAE,CAAC;QAE7C,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC,IAAI,CACvB,IAAI,GAAG,CACL,IAAI,CAAC,YAAY;YACf,wEAAwE;aACvE,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,MAAM,KAAK,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;aAC5D,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CACrC,CACF,CAAC;IACJ,CAAC;IAED;;;;;;;;OAQG;IACH,MAAM,CAAC,OAAgB,EAAE,OAAgB,EAAE,MAAqB;QAC9D,KAAK,MAAM,UAAU,IAAI,IAAI,CAAC,YAAY,EAAE;YAC1C,IAAI;gBACF,UAAU,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;aAC7C;YAAC,OAAO,GAAG,EAAE;gBACZ,IAAI,CAAC,IAAI,CACP,yBAAyB,UAAU,CAAC,WAAW,CAAC,IAAI,UAAU,GAAG,CAAC,OAAO,EAAE,CAC5E,CAAC;aACH;SACF;IACH,CAAC;IAED;;;;;;;;OAQG;IACH,OAAO,CAAC,OAAgB,EAAE,OAAgB,EAAE,MAAqB;QAC/D,OAAO,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,UAAU,EAAE,EAAE;YAClD,IAAI;gBACF,OAAO,UAAU,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;aACjD;YAAC,OAAO,GAAG,EAAE;gBACZ,IAAI,CAAC,IAAI,CACP,0BAA0B,UAAU,CAAC,WAAW,CAAC,IAAI,UAAU,GAAG,CAAC,OAAO,EAAE,CAC7E,CAAC;aACH;YACD,OAAO,GAAG,CAAC;QACb,CAAC,EAAE,OAAO,CAAC,CAAC;IACd,CAAC;IAED,MAAM;QACJ,sDAAsD;QACtD,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;IAC9B,CAAC;CACF","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type {\n Context,\n TextMapGetter,\n TextMapPropagator,\n TextMapSetter,\n} from '@opentelemetry/api';\nimport { diag } from '@opentelemetry/api';\n\n/** Configuration object for composite propagator */\nexport interface CompositePropagatorConfig {\n /**\n * List of propagators to run. Propagators run in the\n * list order. If a propagator later in the list writes the same context\n * key as a propagator earlier in the list, the later on will \"win\".\n */\n propagators?: TextMapPropagator[];\n}\n\n/** Combines multiple propagators into a single propagator. */\nexport class CompositePropagator implements TextMapPropagator {\n private readonly _propagators: TextMapPropagator[];\n private readonly _fields: string[];\n\n /**\n * Construct a composite propagator from a list of propagators.\n *\n * @param [config] Configuration object for composite propagator\n */\n constructor(config: CompositePropagatorConfig = {}) {\n this._propagators = config.propagators ?? [];\n\n this._fields = Array.from(\n new Set(\n this._propagators\n // older propagators may not have fields function, null check to be sure\n .map(p => (typeof p.fields === 'function' ? p.fields() : []))\n .reduce((x, y) => x.concat(y), [])\n )\n );\n }\n\n /**\n * Run each of the configured propagators with the given context and carrier.\n * Propagators are run in the order they are configured, so if multiple\n * propagators write the same carrier key, the propagator later in the list\n * will \"win\".\n *\n * @param context Context to inject\n * @param carrier Carrier into which context will be injected\n */\n inject(context: Context, carrier: unknown, setter: TextMapSetter): void {\n for (const propagator of this._propagators) {\n try {\n propagator.inject(context, carrier, setter);\n } catch (err) {\n diag.warn(\n `Failed to inject with ${propagator.constructor.name}. Err: ${err.message}`\n );\n }\n }\n }\n\n /**\n * Run each of the configured propagators with the given context and carrier.\n * Propagators are run in the order they are configured, so if multiple\n * propagators write the same context key, the propagator later in the list\n * will \"win\".\n *\n * @param context Context to add values to\n * @param carrier Carrier from which to extract context\n */\n extract(context: Context, carrier: unknown, getter: TextMapGetter): Context {\n return this._propagators.reduce((ctx, propagator) => {\n try {\n return propagator.extract(ctx, carrier, getter);\n } catch (err) {\n diag.warn(\n `Failed to extract with ${propagator.constructor.name}. Err: ${err.message}`\n );\n }\n return ctx;\n }, context);\n }\n\n fields(): string[] {\n // return a new array so our fields cannot be modified\n return this._fields.slice();\n }\n}\n"]}

View File

@@ -0,0 +1,9 @@
/**
* The name of the runtime of this process.
*
* @example OpenJDK Runtime Environment
*
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
*/
export declare const ATTR_PROCESS_RUNTIME_NAME: "process.runtime.name";
//# sourceMappingURL=semconv.d.ts.map

View File

@@ -0,0 +1,18 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
/*
* This file contains a copy of unstable semantic convention definitions
* used by this package.
* @see https://github.com/open-telemetry/opentelemetry-js/tree/main/semantic-conventions#unstable-semconv
*/
/**
* The name of the runtime of this process.
*
* @example OpenJDK Runtime Environment
*
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
*/
export const ATTR_PROCESS_RUNTIME_NAME = 'process.runtime.name';
//# sourceMappingURL=semconv.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"semconv.js","sourceRoot":"","sources":["../../src/semconv.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;GAIG;AAEH;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,sBAA+B,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\n/*\n * This file contains a copy of unstable semantic convention definitions\n * used by this package.\n * @see https://github.com/open-telemetry/opentelemetry-js/tree/main/semantic-conventions#unstable-semconv\n */\n\n/**\n * The name of the runtime of this process.\n *\n * @example OpenJDK Runtime Environment\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n */\nexport const ATTR_PROCESS_RUNTIME_NAME = 'process.runtime.name' as const;\n"]}

View File

@@ -0,0 +1,22 @@
import type * as api from '@opentelemetry/api';
/**
* TraceState must be a class and not a simple object type because of the spec
* requirement (https://www.w3.org/TR/trace-context/#tracestate-field).
*
* Here is the list of allowed mutations:
* - New key-value pair should be added into the beginning of the list
* - The value of any key can be updated. Modified keys MUST be moved to the
* beginning of the list.
*/
export declare class TraceState implements api.TraceState {
private _internalState;
constructor(rawTraceState?: string);
set(key: string, value: string): TraceState;
unset(key: string): TraceState;
get(key: string): string | undefined;
serialize(): string;
private _parse;
private _keys;
private _clone;
}
//# sourceMappingURL=TraceState.d.ts.map

View File

@@ -0,0 +1,88 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
import { validateKey, validateValue } from '../internal/validators';
const MAX_TRACE_STATE_ITEMS = 32;
const MAX_TRACE_STATE_LEN = 512;
const LIST_MEMBERS_SEPARATOR = ',';
const LIST_MEMBER_KEY_VALUE_SPLITTER = '=';
/**
* TraceState must be a class and not a simple object type because of the spec
* requirement (https://www.w3.org/TR/trace-context/#tracestate-field).
*
* Here is the list of allowed mutations:
* - New key-value pair should be added into the beginning of the list
* - The value of any key can be updated. Modified keys MUST be moved to the
* beginning of the list.
*/
export class TraceState {
_internalState = new Map();
constructor(rawTraceState) {
if (rawTraceState)
this._parse(rawTraceState);
}
set(key, value) {
// TODO: Benchmark the different approaches(map vs list) and
// use the faster one.
const traceState = this._clone();
if (traceState._internalState.has(key)) {
traceState._internalState.delete(key);
}
traceState._internalState.set(key, value);
return traceState;
}
unset(key) {
const traceState = this._clone();
traceState._internalState.delete(key);
return traceState;
}
get(key) {
return this._internalState.get(key);
}
serialize() {
return this._keys()
.reduce((agg, key) => {
agg.push(key + LIST_MEMBER_KEY_VALUE_SPLITTER + this.get(key));
return agg;
}, [])
.join(LIST_MEMBERS_SEPARATOR);
}
_parse(rawTraceState) {
if (rawTraceState.length > MAX_TRACE_STATE_LEN)
return;
this._internalState = rawTraceState
.split(LIST_MEMBERS_SEPARATOR)
.reverse() // Store in reverse so new keys (.set(...)) will be placed at the beginning
.reduce((agg, part) => {
const listMember = part.trim(); // Optional Whitespace (OWS) handling
const i = listMember.indexOf(LIST_MEMBER_KEY_VALUE_SPLITTER);
if (i !== -1) {
const key = listMember.slice(0, i);
const value = listMember.slice(i + 1, part.length);
if (validateKey(key) && validateValue(value)) {
agg.set(key, value);
}
else {
// TODO: Consider to add warning log
}
}
return agg;
}, new Map());
// Because of the reverse() requirement, trunc must be done after map is created
if (this._internalState.size > MAX_TRACE_STATE_ITEMS) {
this._internalState = new Map(Array.from(this._internalState.entries())
.reverse() // Use reverse same as original tracestate parse chain
.slice(0, MAX_TRACE_STATE_ITEMS));
}
}
_keys() {
return Array.from(this._internalState.keys()).reverse();
}
_clone() {
const traceState = new TraceState();
traceState._internalState = new Map(this._internalState);
return traceState;
}
}
//# sourceMappingURL=TraceState.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,26 @@
import type { Context, SpanContext, TextMapGetter, TextMapPropagator, TextMapSetter } from '@opentelemetry/api';
export declare const TRACE_PARENT_HEADER = "traceparent";
export declare const TRACE_STATE_HEADER = "tracestate";
/**
* Parses information from the [traceparent] span tag and converts it into {@link SpanContext}
* @param traceParent - A meta property that comes from server.
* It should be dynamically generated server side to have the server's request trace Id,
* a parent span Id that was set on the server's request span,
* and the trace flags to indicate the server's sampling decision
* (01 = sampled, 00 = not sampled).
* for example: '{version}-{traceId}-{spanId}-{sampleDecision}'
* For more information see {@link https://www.w3.org/TR/trace-context/}
*/
export declare function parseTraceParent(traceParent: string): SpanContext | null;
/**
* Propagates {@link SpanContext} through Trace Context format propagation.
*
* Based on the Trace Context specification:
* https://www.w3.org/TR/trace-context/
*/
export declare class W3CTraceContextPropagator implements TextMapPropagator {
inject(context: Context, carrier: unknown, setter: TextMapSetter): void;
extract(context: Context, carrier: unknown, getter: TextMapGetter): Context;
fields(): string[];
}
//# sourceMappingURL=W3CTraceContextPropagator.d.ts.map

View File

@@ -0,0 +1,88 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
import { isSpanContextValid, trace, TraceFlags } from '@opentelemetry/api';
import { isTracingSuppressed } from './suppress-tracing';
import { TraceState } from './TraceState';
export const TRACE_PARENT_HEADER = 'traceparent';
export const TRACE_STATE_HEADER = 'tracestate';
const VERSION = '00';
const VERSION_PART = '(?!ff)[\\da-f]{2}';
const TRACE_ID_PART = '(?![0]{32})[\\da-f]{32}';
const PARENT_ID_PART = '(?![0]{16})[\\da-f]{16}';
const FLAGS_PART = '[\\da-f]{2}';
const TRACE_PARENT_REGEX = new RegExp(`^\\s?(${VERSION_PART})-(${TRACE_ID_PART})-(${PARENT_ID_PART})-(${FLAGS_PART})(-.*)?\\s?$`);
/**
* Parses information from the [traceparent] span tag and converts it into {@link SpanContext}
* @param traceParent - A meta property that comes from server.
* It should be dynamically generated server side to have the server's request trace Id,
* a parent span Id that was set on the server's request span,
* and the trace flags to indicate the server's sampling decision
* (01 = sampled, 00 = not sampled).
* for example: '{version}-{traceId}-{spanId}-{sampleDecision}'
* For more information see {@link https://www.w3.org/TR/trace-context/}
*/
export function parseTraceParent(traceParent) {
const match = TRACE_PARENT_REGEX.exec(traceParent);
if (!match)
return null;
// According to the specification the implementation should be compatible
// with future versions. If there are more parts, we only reject it if it's using version 00
// See https://www.w3.org/TR/trace-context/#versioning-of-traceparent
if (match[1] === '00' && match[5])
return null;
return {
traceId: match[2],
spanId: match[3],
traceFlags: parseInt(match[4], 16),
};
}
/**
* Propagates {@link SpanContext} through Trace Context format propagation.
*
* Based on the Trace Context specification:
* https://www.w3.org/TR/trace-context/
*/
export class W3CTraceContextPropagator {
inject(context, carrier, setter) {
const spanContext = trace.getSpanContext(context);
if (!spanContext ||
isTracingSuppressed(context) ||
!isSpanContextValid(spanContext))
return;
const traceParent = `${VERSION}-${spanContext.traceId}-${spanContext.spanId}-0${Number(spanContext.traceFlags || TraceFlags.NONE).toString(16)}`;
setter.set(carrier, TRACE_PARENT_HEADER, traceParent);
if (spanContext.traceState) {
setter.set(carrier, TRACE_STATE_HEADER, spanContext.traceState.serialize());
}
}
extract(context, carrier, getter) {
const traceParentHeader = getter.get(carrier, TRACE_PARENT_HEADER);
if (!traceParentHeader)
return context;
const traceParent = Array.isArray(traceParentHeader)
? traceParentHeader[0]
: traceParentHeader;
if (typeof traceParent !== 'string')
return context;
const spanContext = parseTraceParent(traceParent);
if (!spanContext)
return context;
spanContext.isRemote = true;
const traceStateHeader = getter.get(carrier, TRACE_STATE_HEADER);
if (traceStateHeader) {
// If more than one `tracestate` header is found, we merge them into a
// single header.
const state = Array.isArray(traceStateHeader)
? traceStateHeader.join(',')
: traceStateHeader;
spanContext.traceState = new TraceState(typeof state === 'string' ? state : undefined);
}
return trace.setSpanContext(context, spanContext);
}
fields() {
return [TRACE_PARENT_HEADER, TRACE_STATE_HEADER];
}
}
//# sourceMappingURL=W3CTraceContextPropagator.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,18 @@
import type { Context, Span } from '@opentelemetry/api';
export declare enum RPCType {
HTTP = "http"
}
type HTTPMetadata = {
type: RPCType.HTTP;
route?: string;
span: Span;
};
/**
* Allows for future rpc metadata to be used with this mechanism
*/
export type RPCMetadata = HTTPMetadata;
export declare function setRPCMetadata(context: Context, meta: RPCMetadata): Context;
export declare function deleteRPCMetadata(context: Context): Context;
export declare function getRPCMetadata(context: Context): RPCMetadata | undefined;
export {};
//# sourceMappingURL=rpc-metadata.d.ts.map

View File

@@ -0,0 +1,20 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
import { createContextKey } from '@opentelemetry/api';
const RPC_METADATA_KEY = createContextKey('OpenTelemetry SDK Context Key RPC_METADATA');
export var RPCType;
(function (RPCType) {
RPCType["HTTP"] = "http";
})(RPCType || (RPCType = {}));
export function setRPCMetadata(context, meta) {
return context.setValue(RPC_METADATA_KEY, meta);
}
export function deleteRPCMetadata(context) {
return context.deleteValue(RPC_METADATA_KEY);
}
export function getRPCMetadata(context) {
return context.getValue(RPC_METADATA_KEY);
}
//# sourceMappingURL=rpc-metadata.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"rpc-metadata.js","sourceRoot":"","sources":["../../../src/trace/rpc-metadata.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD,MAAM,gBAAgB,GAAG,gBAAgB,CACvC,4CAA4C,CAC7C,CAAC;AAEF,MAAM,CAAN,IAAY,OAEX;AAFD,WAAY,OAAO;IACjB,wBAAa,CAAA;AACf,CAAC,EAFW,OAAO,KAAP,OAAO,QAElB;AAaD,MAAM,UAAU,cAAc,CAAC,OAAgB,EAAE,IAAiB;IAChE,OAAO,OAAO,CAAC,QAAQ,CAAC,gBAAgB,EAAE,IAAI,CAAC,CAAC;AAClD,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,OAAgB;IAChD,OAAO,OAAO,CAAC,WAAW,CAAC,gBAAgB,CAAC,CAAC;AAC/C,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,OAAgB;IAC7C,OAAO,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAA4B,CAAC;AACvE,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { Context, Span } from '@opentelemetry/api';\nimport { createContextKey } from '@opentelemetry/api';\n\nconst RPC_METADATA_KEY = createContextKey(\n 'OpenTelemetry SDK Context Key RPC_METADATA'\n);\n\nexport enum RPCType {\n HTTP = 'http',\n}\n\ntype HTTPMetadata = {\n type: RPCType.HTTP;\n route?: string;\n span: Span;\n};\n\n/**\n * Allows for future rpc metadata to be used with this mechanism\n */\nexport type RPCMetadata = HTTPMetadata;\n\nexport function setRPCMetadata(context: Context, meta: RPCMetadata): Context {\n return context.setValue(RPC_METADATA_KEY, meta);\n}\n\nexport function deleteRPCMetadata(context: Context): Context {\n return context.deleteValue(RPC_METADATA_KEY);\n}\n\nexport function getRPCMetadata(context: Context): RPCMetadata | undefined {\n return context.getValue(RPC_METADATA_KEY) as RPCMetadata | undefined;\n}\n"]}

View File

@@ -0,0 +1,5 @@
import type { Context } from '@opentelemetry/api';
export declare function suppressTracing(context: Context): Context;
export declare function unsuppressTracing(context: Context): Context;
export declare function isTracingSuppressed(context: Context): boolean;
//# sourceMappingURL=suppress-tracing.d.ts.map

View File

@@ -0,0 +1,16 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
import { createContextKey } from '@opentelemetry/api';
const SUPPRESS_TRACING_KEY = createContextKey('OpenTelemetry SDK Context Key SUPPRESS_TRACING');
export function suppressTracing(context) {
return context.setValue(SUPPRESS_TRACING_KEY, true);
}
export function unsuppressTracing(context) {
return context.deleteValue(SUPPRESS_TRACING_KEY);
}
export function isTracingSuppressed(context) {
return context.getValue(SUPPRESS_TRACING_KEY) === true;
}
//# sourceMappingURL=suppress-tracing.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"suppress-tracing.js","sourceRoot":"","sources":["../../../src/trace/suppress-tracing.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD,MAAM,oBAAoB,GAAG,gBAAgB,CAC3C,gDAAgD,CACjD,CAAC;AAEF,MAAM,UAAU,eAAe,CAAC,OAAgB;IAC9C,OAAO,OAAO,CAAC,QAAQ,CAAC,oBAAoB,EAAE,IAAI,CAAC,CAAC;AACtD,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,OAAgB;IAChD,OAAO,OAAO,CAAC,WAAW,CAAC,oBAAoB,CAAC,CAAC;AACnD,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,OAAgB;IAClD,OAAO,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAAC,KAAK,IAAI,CAAC;AACzD,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { Context } from '@opentelemetry/api';\nimport { createContextKey } from '@opentelemetry/api';\n\nconst SUPPRESS_TRACING_KEY = createContextKey(\n 'OpenTelemetry SDK Context Key SUPPRESS_TRACING'\n);\n\nexport function suppressTracing(context: Context): Context {\n return context.setValue(SUPPRESS_TRACING_KEY, true);\n}\n\nexport function unsuppressTracing(context: Context): Context {\n return context.deleteValue(SUPPRESS_TRACING_KEY);\n}\n\nexport function isTracingSuppressed(context: Context): boolean {\n return context.getValue(SUPPRESS_TRACING_KEY) === true;\n}\n"]}

View File

@@ -0,0 +1,14 @@
/**
* Bind the callback and only invoke the callback once regardless how many times `BindOnceFuture.call` is invoked.
*/
export declare class BindOnceFuture<R, This = unknown, T extends (this: This, ...args: unknown[]) => R = () => R> {
private _isCalled;
private _deferred;
private _callback;
private _that;
constructor(callback: T, that: This);
get isCalled(): boolean;
get promise(): Promise<R>;
call(...args: Parameters<T>): Promise<R>;
}
//# sourceMappingURL=callback.d.ts.map

View File

@@ -0,0 +1,37 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
import { Deferred } from './promise';
/**
* Bind the callback and only invoke the callback once regardless how many times `BindOnceFuture.call` is invoked.
*/
export class BindOnceFuture {
_isCalled = false;
_deferred = new Deferred();
_callback;
_that;
constructor(callback, that) {
this._callback = callback;
this._that = that;
}
get isCalled() {
return this._isCalled;
}
get promise() {
return this._deferred.promise;
}
call(...args) {
if (!this._isCalled) {
this._isCalled = true;
try {
Promise.resolve(this._callback.call(this._that, ...args)).then(val => this._deferred.resolve(val), err => this._deferred.reject(err));
}
catch (err) {
this._deferred.reject(err);
}
}
return this._deferred.promise;
}
}
//# sourceMappingURL=callback.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"callback.js","sourceRoot":"","sources":["../../../src/utils/callback.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAErC;;GAEG;AACH,MAAM,OAAO,cAAc;IAKjB,SAAS,GAAG,KAAK,CAAC;IAClB,SAAS,GAAG,IAAI,QAAQ,EAAK,CAAC;IAC9B,SAAS,CAAI;IACb,KAAK,CAAO;IAEpB,YAAY,QAAW,EAAE,IAAU;QACjC,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;QAC1B,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACpB,CAAC;IAED,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC;IAChC,CAAC;IAED,IAAI,CAAC,GAAG,IAAmB;QACzB,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE;YACnB,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;YACtB,IAAI;gBACF,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,CAC5D,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,GAAG,CAAC,EAClC,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,CAClC,CAAC;aACH;YAAC,OAAO,GAAG,EAAE;gBACZ,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;aAC5B;SACF;QACD,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC;IAChC,CAAC;CACF","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { Deferred } from './promise';\n\n/**\n * Bind the callback and only invoke the callback once regardless how many times `BindOnceFuture.call` is invoked.\n */\nexport class BindOnceFuture<\n R,\n This = unknown,\n T extends (this: This, ...args: unknown[]) => R = () => R,\n> {\n private _isCalled = false;\n private _deferred = new Deferred<R>();\n private _callback: T;\n private _that: This;\n\n constructor(callback: T, that: This) {\n this._callback = callback;\n this._that = that;\n }\n\n get isCalled() {\n return this._isCalled;\n }\n\n get promise() {\n return this._deferred.promise;\n }\n\n call(...args: Parameters<T>): Promise<R> {\n if (!this._isCalled) {\n this._isCalled = true;\n try {\n Promise.resolve(this._callback.call(this._that, ...args)).then(\n val => this._deferred.resolve(val),\n err => this._deferred.reject(err)\n );\n } catch (err) {\n this._deferred.reject(err);\n }\n }\n return this._deferred.promise;\n }\n}\n"]}

View File

@@ -0,0 +1,7 @@
import { DiagLogLevel } from '@opentelemetry/api';
/**
* Convert a string to a {@link DiagLogLevel}, defaults to {@link DiagLogLevel} if the log level does not exist or undefined if the input is undefined.
* @param value
*/
export declare function diagLogLevelFromString(value: string | undefined): DiagLogLevel | undefined;
//# sourceMappingURL=configuration.d.ts.map

View File

@@ -0,0 +1,31 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
import { diag, DiagLogLevel } from '@opentelemetry/api';
const logLevelMap = {
ALL: DiagLogLevel.ALL,
VERBOSE: DiagLogLevel.VERBOSE,
DEBUG: DiagLogLevel.DEBUG,
INFO: DiagLogLevel.INFO,
WARN: DiagLogLevel.WARN,
ERROR: DiagLogLevel.ERROR,
NONE: DiagLogLevel.NONE,
};
/**
* Convert a string to a {@link DiagLogLevel}, defaults to {@link DiagLogLevel} if the log level does not exist or undefined if the input is undefined.
* @param value
*/
export function diagLogLevelFromString(value) {
if (value == null) {
// don't fall back to default - no value set has different semantics for ús than an incorrect value (do not set vs. fall back to default)
return undefined;
}
const resolvedLogLevel = logLevelMap[value.toUpperCase()];
if (resolvedLogLevel == null) {
diag.warn(`Unknown log level "${value}", expected one of ${Object.keys(logLevelMap)}, using default`);
return DiagLogLevel.INFO;
}
return resolvedLogLevel;
}
//# sourceMappingURL=configuration.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"configuration.js","sourceRoot":"","sources":["../../../src/utils/configuration.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAExD,MAAM,WAAW,GAAoC;IACnD,GAAG,EAAE,YAAY,CAAC,GAAG;IACrB,OAAO,EAAE,YAAY,CAAC,OAAO;IAC7B,KAAK,EAAE,YAAY,CAAC,KAAK;IACzB,IAAI,EAAE,YAAY,CAAC,IAAI;IACvB,IAAI,EAAE,YAAY,CAAC,IAAI;IACvB,KAAK,EAAE,YAAY,CAAC,KAAK;IACzB,IAAI,EAAE,YAAY,CAAC,IAAI;CACxB,CAAC;AAEF;;;GAGG;AACH,MAAM,UAAU,sBAAsB,CACpC,KAAyB;IAEzB,IAAI,KAAK,IAAI,IAAI,EAAE;QACjB,yIAAyI;QACzI,OAAO,SAAS,CAAC;KAClB;IAED,MAAM,gBAAgB,GAAG,WAAW,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,CAAC;IAE1D,IAAI,gBAAgB,IAAI,IAAI,EAAE;QAC5B,IAAI,CAAC,IAAI,CACP,sBAAsB,KAAK,sBAAsB,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,iBAAiB,CAC3F,CAAC;QACF,OAAO,YAAY,CAAC,IAAI,CAAC;KAC1B;IAED,OAAO,gBAAgB,CAAC;AAC1B,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\nimport { diag, DiagLogLevel } from '@opentelemetry/api';\n\nconst logLevelMap: { [key: string]: DiagLogLevel } = {\n ALL: DiagLogLevel.ALL,\n VERBOSE: DiagLogLevel.VERBOSE,\n DEBUG: DiagLogLevel.DEBUG,\n INFO: DiagLogLevel.INFO,\n WARN: DiagLogLevel.WARN,\n ERROR: DiagLogLevel.ERROR,\n NONE: DiagLogLevel.NONE,\n};\n\n/**\n * Convert a string to a {@link DiagLogLevel}, defaults to {@link DiagLogLevel} if the log level does not exist or undefined if the input is undefined.\n * @param value\n */\nexport function diagLogLevelFromString(\n value: string | undefined\n): DiagLogLevel | undefined {\n if (value == null) {\n // don't fall back to default - no value set has different semantics for ús than an incorrect value (do not set vs. fall back to default)\n return undefined;\n }\n\n const resolvedLogLevel = logLevelMap[value.toUpperCase()];\n\n if (resolvedLogLevel == null) {\n diag.warn(\n `Unknown log level \"${value}\", expected one of ${Object.keys(logLevelMap)}, using default`\n );\n return DiagLogLevel.INFO;\n }\n\n return resolvedLogLevel;\n}\n"]}

View File

@@ -0,0 +1,30 @@
/**
* Checks if `value` is a plain object, that is, an object created by the
* `Object` constructor or one with a `[[Prototype]]` of `null`.
*
* @static
* @memberOf _
* @since 0.8.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
* @example
*
* function Foo() {
* this.a = 1;
* }
*
* _.isPlainObject(new Foo);
* // => false
*
* _.isPlainObject([1, 2, 3]);
* // => false
*
* _.isPlainObject({ 'x': 0, 'y': 0 });
* // => true
*
* _.isPlainObject(Object.create(null));
* // => true
*/
export declare function isPlainObject(value: any): boolean;
//# sourceMappingURL=lodash.merge.d.ts.map

View File

@@ -0,0 +1,142 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
/* eslint-disable @typescript-eslint/no-explicit-any */
/**
* based on lodash in order to support esm builds without esModuleInterop.
* lodash is using MIT License.
**/
const objectTag = '[object Object]';
const nullTag = '[object Null]';
const undefinedTag = '[object Undefined]';
const funcProto = Function.prototype;
const funcToString = funcProto.toString;
const objectCtorString = funcToString.call(Object);
const getPrototypeOf = Object.getPrototypeOf;
const objectProto = Object.prototype;
const hasOwnProperty = objectProto.hasOwnProperty;
const symToStringTag = Symbol ? Symbol.toStringTag : undefined;
const nativeObjectToString = objectProto.toString;
/**
* Checks if `value` is a plain object, that is, an object created by the
* `Object` constructor or one with a `[[Prototype]]` of `null`.
*
* @static
* @memberOf _
* @since 0.8.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
* @example
*
* function Foo() {
* this.a = 1;
* }
*
* _.isPlainObject(new Foo);
* // => false
*
* _.isPlainObject([1, 2, 3]);
* // => false
*
* _.isPlainObject({ 'x': 0, 'y': 0 });
* // => true
*
* _.isPlainObject(Object.create(null));
* // => true
*/
export function isPlainObject(value) {
if (!isObjectLike(value) || baseGetTag(value) !== objectTag) {
return false;
}
const proto = getPrototypeOf(value);
if (proto === null) {
return true;
}
const Ctor = hasOwnProperty.call(proto, 'constructor') && proto.constructor;
return (typeof Ctor == 'function' &&
Ctor instanceof Ctor &&
funcToString.call(Ctor) === objectCtorString);
}
/**
* Checks if `value` is object-like. A value is object-like if it's not `null`
* and has a `typeof` result of "object".
*
* @static
* @memberOf _
* @since 4.0.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is object-like, else `false`.
* @example
*
* _.isObjectLike({});
* // => true
*
* _.isObjectLike([1, 2, 3]);
* // => true
*
* _.isObjectLike(_.noop);
* // => false
*
* _.isObjectLike(null);
* // => false
*/
function isObjectLike(value) {
return value != null && typeof value == 'object';
}
/**
* The base implementation of `getTag` without fallbacks for buggy environments.
*
* @private
* @param {*} value The value to query.
* @returns {string} Returns the `toStringTag`.
*/
function baseGetTag(value) {
if (value == null) {
return value === undefined ? undefinedTag : nullTag;
}
return symToStringTag && symToStringTag in Object(value)
? getRawTag(value)
: objectToString(value);
}
/**
* A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values.
*
* @private
* @param {*} value The value to query.
* @returns {string} Returns the raw `toStringTag`.
*/
function getRawTag(value) {
const isOwn = hasOwnProperty.call(value, symToStringTag), tag = value[symToStringTag];
let unmasked = false;
try {
value[symToStringTag] = undefined;
unmasked = true;
}
catch {
// silence
}
const result = nativeObjectToString.call(value);
if (unmasked) {
if (isOwn) {
value[symToStringTag] = tag;
}
else {
delete value[symToStringTag];
}
}
return result;
}
/**
* Converts `value` to a string using `Object.prototype.toString`.
*
* @private
* @param {*} value The value to convert.
* @returns {string} Returns the converted string.
*/
function objectToString(value) {
return nativeObjectToString.call(value);
}
//# sourceMappingURL=lodash.merge.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,6 @@
/**
* Merges objects together
* @param args - objects / values to be merged
*/
export declare function merge(...args: any[]): any;
//# sourceMappingURL=merge.d.ts.map

View File

@@ -0,0 +1,147 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
/* eslint-disable @typescript-eslint/no-explicit-any */
import { isPlainObject } from './lodash.merge';
const MAX_LEVEL = 20;
/**
* Merges objects together
* @param args - objects / values to be merged
*/
export function merge(...args) {
let result = args.shift();
const objects = new WeakMap();
while (args.length > 0) {
result = mergeTwoObjects(result, args.shift(), 0, objects);
}
return result;
}
function takeValue(value) {
if (isArray(value)) {
return value.slice();
}
return value;
}
/**
* Merges two objects
* @param one - first object
* @param two - second object
* @param level - current deep level
* @param objects - objects holder that has been already referenced - to prevent
* cyclic dependency
*/
function mergeTwoObjects(one, two, level = 0, objects) {
let result;
if (level > MAX_LEVEL) {
return undefined;
}
level++;
if (isPrimitive(one) || isPrimitive(two) || isFunction(two)) {
result = takeValue(two);
}
else if (isArray(one)) {
result = one.slice();
if (isArray(two)) {
for (let i = 0, j = two.length; i < j; i++) {
result.push(takeValue(two[i]));
}
}
else if (isObject(two)) {
const keys = Object.keys(two);
for (let i = 0, j = keys.length; i < j; i++) {
const key = keys[i];
result[key] = takeValue(two[key]);
}
}
}
else if (isObject(one)) {
if (isObject(two)) {
if (!shouldMerge(one, two)) {
return two;
}
result = Object.assign({}, one);
const keys = Object.keys(two);
for (let i = 0, j = keys.length; i < j; i++) {
const key = keys[i];
const twoValue = two[key];
if (isPrimitive(twoValue)) {
if (typeof twoValue === 'undefined') {
delete result[key];
}
else {
// result[key] = takeValue(twoValue);
result[key] = twoValue;
}
}
else {
const obj1 = result[key];
const obj2 = twoValue;
if (wasObjectReferenced(one, key, objects) ||
wasObjectReferenced(two, key, objects)) {
delete result[key];
}
else {
if (isObject(obj1) && isObject(obj2)) {
const arr1 = objects.get(obj1) || [];
const arr2 = objects.get(obj2) || [];
arr1.push({ obj: one, key });
arr2.push({ obj: two, key });
objects.set(obj1, arr1);
objects.set(obj2, arr2);
}
result[key] = mergeTwoObjects(result[key], twoValue, level, objects);
}
}
}
}
else {
result = two;
}
}
return result;
}
/**
* Function to check if object has been already reference
* @param obj
* @param key
* @param objects
*/
function wasObjectReferenced(obj, key, objects) {
const arr = objects.get(obj[key]) || [];
for (let i = 0, j = arr.length; i < j; i++) {
const info = arr[i];
if (info.key === key && info.obj === obj) {
return true;
}
}
return false;
}
function isArray(value) {
return Array.isArray(value);
}
function isFunction(value) {
return typeof value === 'function';
}
function isObject(value) {
return (!isPrimitive(value) &&
!isArray(value) &&
!isFunction(value) &&
typeof value === 'object');
}
function isPrimitive(value) {
return (typeof value === 'string' ||
typeof value === 'number' ||
typeof value === 'boolean' ||
typeof value === 'undefined' ||
value instanceof Date ||
value instanceof RegExp ||
value === null);
}
function shouldMerge(one, two) {
if (!isPlainObject(one) || !isPlainObject(two)) {
return false;
}
return true;
}
//# sourceMappingURL=merge.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,10 @@
export declare class Deferred<T> {
private _promise;
private _resolve;
private _reject;
constructor();
get promise(): Promise<T>;
resolve(val: T): void;
reject(err: unknown): void;
}
//# sourceMappingURL=promise.d.ts.map

View File

@@ -0,0 +1,25 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
export class Deferred {
_promise;
_resolve;
_reject;
constructor() {
this._promise = new Promise((resolve, reject) => {
this._resolve = resolve;
this._reject = reject;
});
}
get promise() {
return this._promise;
}
resolve(val) {
this._resolve(val);
}
reject(err) {
this._reject(err);
}
}
//# sourceMappingURL=promise.js.map

Some files were not shown because too many files have changed in this diff Show More