mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-26 06:34:20 +08:00
Carry runtime-decided dns.lookup answers dynamically, dial Node-typed net lookups, and keep tsc enum exports undefined until assigned
- dns.lookup with options known only at run time (a checked-dynamic
value, or one cast to an overload's option type) may answer a string or,
with `all: true`, an address list, whatever the overload the checker
picked says: an inline callback now binds its parameters as
checked-dynamic values. Array.isArray tests a checker-narrowed dyn read's
dyn value instead of folding on the extracted type, so it never answers
false for an address list the declared type omits.
- net.connect({ lookup }) accepts a lookup of Node's own type
(net.LookupFunction: options plus a callback taking an address string
or list), called as Node's autoSelectFamily dial does ({ hints, all:
true }); the fallback declarations spell net.LookupFunction that way.
dns.lookup accepts Node's hints flags (ADDRCONFIG, V4MAPPED, ALL) and
passes them to getaddrinfo.
- A CommonJS export typed as the empty object literal (tsc's enum output
`exports.E || (exports.E = {})` after `exports.E = void 0`) rides
checked-dynamic storage, so the preamble's undefined no longer traps at
module load: @opentelemetry/api loads and its no-op metrics and trace
APIs run.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
c91bfea743
commit
f669c46f0d
+7
-5
@@ -4852,15 +4852,17 @@ declare module "net" {
|
||||
host?: string,
|
||||
connectListener?: () => void,
|
||||
): Socket;
|
||||
/* The caller-resolver dial (@types/node's net.LookupFunction, narrowed
|
||||
* to the lowered shape): the runtime invokes it as Node does and dials
|
||||
* the answered addresses in order under autoSelectFamily: true. */
|
||||
/* The caller-resolver dial (@types/node's net.LookupFunction): the
|
||||
* runtime invokes it as Node's autoSelectFamily dial does (options
|
||||
* { hints, all: true }, so the callback answers an address list) and
|
||||
* dials the answered addresses in order. */
|
||||
export type LookupFunction = (
|
||||
hostname: string,
|
||||
options: unknown,
|
||||
options: import("node:dns").LookupOptions,
|
||||
callback: (
|
||||
err: NodeJS.ErrnoException | null,
|
||||
addresses: { address: string; family: number }[],
|
||||
address: string | import("node:dns").LookupAddress[],
|
||||
family?: number,
|
||||
) => void,
|
||||
) => void;
|
||||
export function connect(
|
||||
|
||||
@@ -459,6 +459,7 @@ export const LIB_FN_SYMS: Record<string, string> = {
|
||||
"fs.existsChk": "scr_fs_exists_async",
|
||||
"fs.mkdtempSyncChk": "scr_fs_mkdtemp_sync_chk",
|
||||
"net.connectAttempt": "scr_net_connect_attempt",
|
||||
"net.connectLookupDyn": "scr_net_connect_lookup_dyn",
|
||||
"fs.lchmodSyncChk": "scr_fs_lchmod_sync_chk",
|
||||
"fsp.lchmodChk": "scr_fsp_lchmod_chk",
|
||||
"fs.readFileSyncBuf": "scr_fs_read_file_bytes",
|
||||
@@ -1639,6 +1640,7 @@ export const USES_TIMERS_LIB_FNS = new Set<string>([
|
||||
"net.connect",
|
||||
"net.connectCb",
|
||||
"net.connectLookup",
|
||||
"net.connectLookupDyn",
|
||||
"net.connectAttempt",
|
||||
"fs.existsChk",
|
||||
"fs.callbackValue",
|
||||
|
||||
@@ -854,6 +854,17 @@ export function lambdaSignature(
|
||||
return { shapes, funcType: funcTypeFromParamShapes(shapes, DYN) };
|
||||
}
|
||||
}
|
||||
// A callback whose arguments arrive as the runtime produced them, wider
|
||||
// than its contextual overload says (dns.lookup's callback when the
|
||||
// options are only known at run time: the address is a string or an
|
||||
// address list): every parameter binds as a checked-dynamic value.
|
||||
if (lowerer.dynParamLambdas.has(node)) {
|
||||
const shapes: ParamShape[] = node.parameters.nodes.map(() => ({
|
||||
type: DYN,
|
||||
mode: "required",
|
||||
}));
|
||||
return { shapes, funcType: funcTypeFromParamShapes(shapes, VOID) };
|
||||
}
|
||||
if (node.typeParameters?.nodes && !lowerer.erasingLambdas.has(node)) {
|
||||
// Generic function-like forms monomorphize only where a static home
|
||||
// exists: top-level generic function declarations, generic methods
|
||||
|
||||
@@ -4252,8 +4252,13 @@ function lowerArrayIsArrayCall(
|
||||
if (lowerer.stdlibGlobalMember(access, "Array") !== "isArray") return null;
|
||||
if (call.arguments.nodes.length !== 1) return null; // the stdlib chokepoint fences
|
||||
const argNode = call.arguments.nodes[0]!;
|
||||
const arg = lowerer.lowerExpr(argNode);
|
||||
let arg = lowerer.lowerExpr(argNode);
|
||||
const loc = locOf(call);
|
||||
// A checker-narrowed dyn read arrives as a validated extraction (the
|
||||
// dynCheck bridge). The runtime value may be wider than the flow type
|
||||
// claims (an overload narrower than what arrives), so test the dyn value
|
||||
// itself instead of folding on the extracted type (typeof's rule).
|
||||
if (arg.kind === "dynCheck" && arg.value.type.kind === "dyn") arg = arg.value;
|
||||
if (arg.type.kind === "dyn") {
|
||||
return { kind: "dynTest", test: "array", value: arg, type: BOOL, loc };
|
||||
}
|
||||
|
||||
@@ -321,8 +321,31 @@ function lowerDnsModuleCall(
|
||||
const hostname = dyn(args[0]!);
|
||||
const options = args.length === 3 ? dyn(args[1]!) : dynUndefinedExpr(loc);
|
||||
const last = args[args.length - 1]!;
|
||||
const typed = typedResult(last);
|
||||
const cb = lowerDnsCallback(lowerer, last, "lookup callbacks");
|
||||
// Options known only at run time (a checked-dynamic value, or one cast
|
||||
// to an overload's option type) decide between Node's two callback
|
||||
// shapes there: the address is a string, or an address list with
|
||||
// `all: true`. An inline callback then binds its parameters as
|
||||
// checked-dynamic values, whatever the overload the checker picked
|
||||
// says, and its body tests what actually arrived.
|
||||
let runtimeOptions = false;
|
||||
if (args.length === 3) {
|
||||
let inner: ts.Expression = args[1]!;
|
||||
while (ts.isParenthesizedExpression(inner) || ts.isAsExpression(inner))
|
||||
inner = inner.expression;
|
||||
runtimeOptions = lowerer.mapTypeOf(lowerer.typeOf(inner))?.kind === "dyn";
|
||||
}
|
||||
let callbackNode: ts.Expression = last;
|
||||
while (ts.isParenthesizedExpression(callbackNode)) callbackNode = callbackNode.expression;
|
||||
const dynCallback =
|
||||
runtimeOptions && (ts.isArrowFunction(callbackNode) || ts.isFunctionExpression(callbackNode));
|
||||
const typed = dynCallback ? boolLit(false, loc) : typedResult(last);
|
||||
if (dynCallback) lowerer.dynParamLambdas.add(callbackNode);
|
||||
let cb: IrExpr;
|
||||
try {
|
||||
cb = lowerDnsCallback(lowerer, last, "lookup callbacks");
|
||||
} finally {
|
||||
if (dynCallback) lowerer.dynParamLambdas.delete(callbackNode);
|
||||
}
|
||||
return {
|
||||
kind: "libCall",
|
||||
fn: "dns.lookupDyn",
|
||||
|
||||
@@ -1357,8 +1357,17 @@ export function collectGlobals(
|
||||
// common/tls's `exports.check = function (certs) {...}` —
|
||||
// keep func-ness with dyn pieces; everything else is dyn).
|
||||
const strict = lowerer.checker.getTypeOfSymbol(symbol);
|
||||
const t = lowerer.mapTypeOf(strict) ?? dynFallbackType(lowerer, nameNode, strict);
|
||||
let t = lowerer.mapTypeOf(strict) ?? dynFallbackType(lowerer, nameNode, strict);
|
||||
if (!t || t.kind === "void") lowerer.badType(typeNode, strict);
|
||||
// An export typed as the empty object literal (tsc's enum output
|
||||
// `exports.E || (exports.E = {})` after its `exports.E = void 0`
|
||||
// preamble): TS's `{}` admits any later non-nullish value and the
|
||||
// export is undefined until then, so it rides checked-dynamic
|
||||
// storage like the same-shaped var binding (varBindingType).
|
||||
if (t.kind === "record" && isJsSourceFile(sf)) {
|
||||
const shape = lowerer.shapes.get(t.shapeId);
|
||||
if (shape && shape.fields.length === 0 && !shape.indexValue && !shape.tuple) t = DYN;
|
||||
}
|
||||
// An immutable export source shares its live storage and native
|
||||
// callable ABI. Mutable sources need a separate snapshot slot:
|
||||
// later writes to the binding do not change the exported value.
|
||||
|
||||
@@ -930,6 +930,7 @@ function lowerNetConnectOptions(
|
||||
let port: IrExpr | null = null;
|
||||
let host: IrExpr | null = null;
|
||||
let lookup: IrExpr | null = null;
|
||||
let dynLookup: IrExpr | null = null;
|
||||
let autoSelect = false;
|
||||
let attempt: IrExpr | null = null;
|
||||
let optionThrow: IrExpr | null = null;
|
||||
@@ -1037,7 +1038,23 @@ function lowerNetConnectOptions(
|
||||
);
|
||||
}
|
||||
lookup = lowerer.lowerExpr(initializer);
|
||||
if (!lookupFnShapeOk(lowerer, lookup.type)) {
|
||||
// A lookup of Node's own type (net.LookupFunction: options and a
|
||||
// callback taking an address string or list) crosses as a checked-
|
||||
// dynamic function the runtime calls the way Node's dial does.
|
||||
if (
|
||||
!lookupFnShapeOk(lowerer, lookup.type) &&
|
||||
lookup.type.kind === "func" &&
|
||||
lookup.type.params.length === 3 &&
|
||||
canBoxFuncIntoDyn(
|
||||
lookup.type,
|
||||
(id) => lowerer.shapes.get(id),
|
||||
(id) => lowerer.unions.get(id),
|
||||
)
|
||||
) {
|
||||
dynLookup = { kind: "dynFrom", value: lookup, type: DYN, loc: locOf(initializer) };
|
||||
} else if (lookup.type.kind === "dyn") {
|
||||
dynLookup = lookup;
|
||||
} else if (!lookupFnShapeOk(lowerer, lookup.type)) {
|
||||
lowerer.noLowering(
|
||||
`a ${member} 'lookup' option of '${lowerer.fmt(lookup.type)}' values`,
|
||||
prop,
|
||||
@@ -1080,6 +1097,22 @@ function lowerNetConnectOptions(
|
||||
loc,
|
||||
};
|
||||
}
|
||||
if (dynLookup !== null) {
|
||||
if (args.length !== 1) {
|
||||
lowerer.noLowering(
|
||||
`${member} with a lookup and a connect listener`,
|
||||
expr,
|
||||
"register the listener separately: socket.once('connect', ...)",
|
||||
);
|
||||
}
|
||||
return {
|
||||
kind: "libCall",
|
||||
fn: "net.connectLookupDyn",
|
||||
args: [port, host, dynLookup],
|
||||
type: NETSOCKET_T,
|
||||
loc,
|
||||
};
|
||||
}
|
||||
if (lookup !== null) {
|
||||
if (!autoSelect) {
|
||||
lowerer.noLowering(
|
||||
|
||||
@@ -1950,6 +1950,9 @@ export class Lowerer {
|
||||
* setEncoding call whose receiver is a socket or an untyped value.
|
||||
* Computed once on first use (null until then). */
|
||||
socketEncodingReachable: boolean | null = null;
|
||||
/** Lambdas lowered with checked-dynamic parameters (lambdaSignature):
|
||||
* callbacks whose arguments are wider than their contextual overload. */
|
||||
readonly dynParamLambdas = new Set<ts.Node>();
|
||||
/** IMPLICIT-ANY instances lowered EAGERLY at first demand (their return
|
||||
* types are inferred from the body — the call site needs them settled),
|
||||
* collected here for run()'s function list (the liftedFns discipline). */
|
||||
|
||||
@@ -423,6 +423,7 @@ export const MAY_THROW_LIB_FNS: ReadonlySet<IrLibFn> = new Set([
|
||||
// The caller's lookup runs synchronously inside the connect call — a
|
||||
// throw there propagates like Node's.
|
||||
"net.connectLookup",
|
||||
"net.connectLookupDyn",
|
||||
"cp.execSync",
|
||||
"cp.execCapture",
|
||||
// The client request constructors validate the method token
|
||||
|
||||
@@ -1368,6 +1368,11 @@ export const LIB_FN_SIGS = defineLibFnSignatures({
|
||||
* 'error'. A synchronous throw INSIDE the lookup propagates out of the
|
||||
* connect call (may-throw seed). */
|
||||
"net.connectLookup": { argTypes: [F64, STRING, null], result: NETSOCKET_T },
|
||||
/** connect({ host, port, lookup }) with a lookup of Node's own type, as
|
||||
* a checked-dynamic function: the runtime calls it with { hints, all:
|
||||
* true } and a callback taking an address string or list, then dials
|
||||
* the answers in order. MAY THROW (host validation, a lookup throw). */
|
||||
"net.connectLookupDyn": { argTypes: [F64, STRING, DYN], result: NETSOCKET_T },
|
||||
"net.sockWrite": { argTypes: [NETSOCKET_T, STRING], result: VOID },
|
||||
"net.sockWriteBytes": { argTypes: [NETSOCKET_T, BYTES_U8], result: VOID },
|
||||
"net.sockEnd": { argTypes: [NETSOCKET_T], result: VOID },
|
||||
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"order": [
|
||||
"<repo>/tests/corpus/6452-dns-lookup-runtime-options.ts"
|
||||
],
|
||||
"diags": []
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"order": [
|
||||
"<repo>/tests/fixtures/npm/cases/opentelemetry-api/main.ts"
|
||||
],
|
||||
"diags": []
|
||||
}
|
||||
@@ -1394,6 +1394,7 @@ static void scr_dns_lookup_plain(const ScrDyn *hostname, const ScrDyn *options,
|
||||
double family = 0;
|
||||
bool all = false;
|
||||
int order = scr_dns_default_order;
|
||||
int ai_flags = 0;
|
||||
if (options->kind == SCR_DYN_NUM) {
|
||||
double f = options->v.num;
|
||||
if (f != 0 && f != 4 && f != 6) {
|
||||
@@ -1412,10 +1413,15 @@ static void scr_dns_lookup_plain(const ScrDyn *hostname, const ScrDyn *options,
|
||||
scr_dyn_prop_type_fail("options.hints", "of type number", v);
|
||||
return;
|
||||
}
|
||||
if (v->v.num != 0) {
|
||||
scr_throw_error_msg_code(SCR_ERR_ERROR, "dns.lookup hints are not supported yet", 38, "SC2020");
|
||||
/* Node's validateHints: only dns.ADDRCONFIG, dns.V4MAPPED and
|
||||
* dns.ALL (getaddrinfo's own flags), which then reach getaddrinfo */
|
||||
double h = v->v.num;
|
||||
int allowed = AI_ADDRCONFIG | AI_V4MAPPED | AI_ALL;
|
||||
if (!(h == h && trunc(h) == h && h >= 0 && h <= 0x7fffffff) || ((int)h & ~allowed) != 0) {
|
||||
scr_dyn_arg_value_fail("hints", "is invalid", v);
|
||||
return;
|
||||
}
|
||||
ai_flags = (int)h;
|
||||
}
|
||||
v = scr_dyn_obj_get(options, "family", 6);
|
||||
if (v != NULL && v->kind != SCR_DYN_UNDEF && v->kind != SCR_DYN_NULL) {
|
||||
@@ -1519,6 +1525,7 @@ static void scr_dns_lookup_plain(const ScrDyn *hostname, const ScrDyn *options,
|
||||
memset(&hints, 0, sizeof hints);
|
||||
hints.ai_family = family == 4 ? AF_INET : family == 6 ? AF_INET6 : AF_UNSPEC;
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
hints.ai_flags = ai_flags;
|
||||
struct addrinfo *res = NULL;
|
||||
int rc = getaddrinfo(host->data, NULL, &hints, &res);
|
||||
if (rc != 0 || res == NULL) {
|
||||
|
||||
@@ -2669,6 +2669,81 @@ ScrNetSocket *scr_net_connect_lookup(double port, ScrStr *host /*borrowed*/,
|
||||
return s;
|
||||
}
|
||||
|
||||
/* The callback a checked-dynamic lookup function receives (Node's own
|
||||
* shape, `(err, address, family)`): with `all: true` the address is a list
|
||||
* of { address, family } records, otherwise one address string. caps[0]
|
||||
* boxes the socket, as for the typed answer closure. */
|
||||
static ScrDyn *scr_net_lookup_dyn_thunk(ScrClosure *clo, ScrDyn *const *args, size_t argc) {
|
||||
const ScrDyn *err = argc > 0 ? args[0] : scr_dyn_undefined();
|
||||
const ScrDyn *addr = argc > 1 ? args[1] : scr_dyn_undefined();
|
||||
ScrStr *msg = NULL;
|
||||
ScrArr *ips = NULL;
|
||||
bool failed = scr_dyn_truthy(err);
|
||||
if (failed) {
|
||||
const ScrDyn *m = err->kind == SCR_DYN_OBJ ? scr_dyn_obj_get(err, "message", 7) : NULL;
|
||||
msg = m != NULL && m->kind == SCR_DYN_STR ? scr_str_retain(m->v.str) : scr_dyn_string_coerce_js(err);
|
||||
} else {
|
||||
ScrDyn *view = addr->kind == SCR_DYN_TYPED_REF ? scr_dyn_typed_ref_materialize(addr) : NULL;
|
||||
const ScrDyn *list = view != NULL ? view : addr;
|
||||
ips = scr_arr_new(SCR_ELEM_STR, 0);
|
||||
if (list->kind == SCR_DYN_STR) {
|
||||
scr_arr_push_ref(ips, scr_str_retain(list->v.str));
|
||||
} else if (list->kind == SCR_DYN_ARR) {
|
||||
for (size_t i = 0; i < list->v.arr.len; i++) {
|
||||
const ScrDyn *entry = list->v.arr.items[i];
|
||||
ScrDyn *ev = entry->kind == SCR_DYN_TYPED_REF ? scr_dyn_typed_ref_materialize(entry) : NULL;
|
||||
const ScrDyn *rec = ev != NULL ? ev : entry;
|
||||
const ScrDyn *a = rec->kind == SCR_DYN_OBJ ? scr_dyn_obj_get(rec, "address", 7) : NULL;
|
||||
if (a != NULL && a->kind == SCR_DYN_STR) scr_arr_push_ref(ips, scr_str_retain(a->v.str));
|
||||
scr_dyn_release(ev);
|
||||
}
|
||||
}
|
||||
scr_dyn_release(view);
|
||||
}
|
||||
scr_net_lookup_answer(clo, failed, msg, ips);
|
||||
scr_str_release(msg);
|
||||
if (ips != NULL) scr_arr_release(ips);
|
||||
return scr_dyn_retain(scr_dyn_undefined());
|
||||
}
|
||||
|
||||
/* net.connect({ host, port, lookup }) with a lookup of Node's own type
|
||||
* (`(hostname, options, callback)` whose callback takes a string or an
|
||||
* address list), held as a checked-dynamic function: the runtime calls it
|
||||
* as Node's autoSelectFamily dial does, with { hints, all: true }, and dials
|
||||
* the answered addresses in order. NULL with the exception pending. */
|
||||
ScrNetSocket *scr_net_connect_lookup_dyn(double port, ScrStr *host /*borrowed*/,
|
||||
const ScrDyn *lookup /*borrowed*/) {
|
||||
if (!scr_net_host_chk(host)) return NULL;
|
||||
ScrNetSocket *s = scr_net_sock_new();
|
||||
s->peer_port = (int)port;
|
||||
snprintf(s->peer_ip, sizeof s->peer_ip, "%.*s",
|
||||
(int)(host->len < 63 ? host->len : 63), host->data);
|
||||
if (!scr_net_poller_init()) {
|
||||
fputs("scriptc: event poller init failed\n", stderr);
|
||||
abort();
|
||||
}
|
||||
s->connecting = true;
|
||||
s->lookup_wait = true;
|
||||
scr_net_sock_register(s);
|
||||
ScrClosure *ans = scr_closure_new((void *)&scr_net_lookup_dyn_thunk, 1);
|
||||
ScrBox *box = scr_box_new_obj(&scr_net_sock_retain_v, &scr_net_sock_release_v, NULL);
|
||||
scr_box_set_ref(box, scr_net_sock_retain(s));
|
||||
ans->caps[0] = box;
|
||||
ScrDyn *callback = scr_dyn_new_func(ans, &scr_net_lookup_dyn_thunk, 3, "(err, address, family)", "callback");
|
||||
ScrDyn *options = scr_dyn_new_obj();
|
||||
#ifndef _WIN32
|
||||
scr_dyn_obj_set(options, "hints", 5, scr_dyn_new_num((double)AI_ADDRCONFIG));
|
||||
#endif
|
||||
scr_dyn_obj_set(options, "all", 3, scr_dyn_new_bool(true));
|
||||
ScrDyn *name = scr_dyn_new_str(host);
|
||||
ScrDyn *args[3] = { name, options, callback };
|
||||
scr_dyn_release(scr_dyn_call(lookup, args, 3, "lookup"));
|
||||
scr_dyn_release(name);
|
||||
scr_dyn_release(options);
|
||||
scr_dyn_release(callback);
|
||||
return s;
|
||||
}
|
||||
|
||||
/* The answer closure's runtime half (its fn is the emitted per-shape
|
||||
* thunk; caps[0] boxes the socket). msg/ips are borrowed (nullable). */
|
||||
void scr_net_lookup_answer(ScrClosure *self, bool has_err, ScrStr *msg /*borrowed, nullable*/,
|
||||
|
||||
@@ -237,6 +237,7 @@ bool scr_net_sock_readable(ScrNetSocket *s);
|
||||
/* The deferred dial (the http agent's maxSockets queue): the socket
|
||||
* registers "connecting" and buffers writes; dial_start runs the dial. */
|
||||
ScrNetSocket *scr_net_connect_deferred(double port, ScrStr *host /*borrowed, nullable*/); /* +1 */
|
||||
ScrNetSocket *scr_net_connect_lookup_dyn(double port, ScrStr *host /*borrowed*/, const ScrDyn *lookup /*borrowed*/); /* +1, NULL on throw */
|
||||
void scr_net_sock_dial_start(ScrNetSocket *s);
|
||||
void scr_net_sock_set_timeout(ScrNetSocket *s, double ms);
|
||||
void scr_net_sock_on_timeout(ScrNetSocket *s, ScrClosure *cb /*moves*/, bool once);
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
// A custom lookup function over Node's lookup-option union passes its
|
||||
// options to dns.lookup through a cast, so the callback's address is a
|
||||
// string or, with `all: true`, an address list, whatever the overload the
|
||||
// checker picked says. Array.isArray tests what arrived. The same function
|
||||
// serves as net.connect's lookup, which Node calls with `all: true`.
|
||||
import * as dns from "node:dns";
|
||||
import * as net from "node:net";
|
||||
|
||||
type LookupCallback = (
|
||||
err: NodeJS.ErrnoException | null,
|
||||
address: string | dns.LookupAddress[],
|
||||
family?: number,
|
||||
) => void;
|
||||
|
||||
function createSafeLookup(): (
|
||||
hostname: string,
|
||||
opts: dns.LookupOneOptions | dns.LookupAllOptions | number | undefined,
|
||||
callback: LookupCallback,
|
||||
) => void {
|
||||
return function safeLookup(hostname, opts, callback) {
|
||||
dns.lookup(hostname, opts as dns.LookupOneOptions, (err, address, family) => {
|
||||
if (err) {
|
||||
callback(err, address as string, family);
|
||||
return;
|
||||
}
|
||||
if (Array.isArray(address)) {
|
||||
const v4: dns.LookupAddress[] = [];
|
||||
for (const entry of address) {
|
||||
if (entry.address === "10.0.0.1") {
|
||||
callback(new Error("blocked"), "", 0);
|
||||
return;
|
||||
}
|
||||
if (entry.family === 4) v4.push(entry);
|
||||
}
|
||||
callback(null, v4);
|
||||
return;
|
||||
}
|
||||
callback(null, address as string, family);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
const lookup = createSafeLookup();
|
||||
const show = (address: string | dns.LookupAddress[]): string =>
|
||||
typeof address === "string" ? address : JSON.stringify(address);
|
||||
|
||||
lookup("localhost", { family: 4 }, (err, address, family) => {
|
||||
console.log("one", err, show(address), family);
|
||||
lookup("localhost", { family: 4, all: false }, (err2, address2, family2) => {
|
||||
console.log("all false", err2, show(address2), family2);
|
||||
lookup("localhost", { all: true }, (err3, addresses) => {
|
||||
console.log("all true", err3, show(addresses));
|
||||
lookup("127.0.0.1", 4, (err4, address4, family4) => {
|
||||
console.log("family", err4, show(address4), family4);
|
||||
const server = net.createServer((socket) => socket.end("hello"));
|
||||
server.listen(0, "127.0.0.1", () => {
|
||||
const port = (server.address() as net.AddressInfo).port;
|
||||
const socket = net.connect({ host: "localhost", port, lookup: createSafeLookup() });
|
||||
socket.on("data", (chunk: Buffer) => console.log("net", chunk.toString()));
|
||||
socket.on("close", () => server.close());
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
+23
-5
@@ -18,8 +18,23 @@ function createLookup(): (
|
||||
) => void {
|
||||
return function lookup(hostname, opts, callback) {
|
||||
dns.lookup(hostname, opts as dns.LookupOneOptions, (err, address, family) => {
|
||||
if (err) return callback(err, "", 0);
|
||||
callback(null, address, family);
|
||||
if (err) {
|
||||
callback(err, address as string, family);
|
||||
return;
|
||||
}
|
||||
// With `all: true` Node answers an address list whatever the
|
||||
// overload the cast selected says.
|
||||
if (Array.isArray(address)) {
|
||||
const v4: dns.LookupAddress[] = [];
|
||||
for (const entry of address) if (entry.family === 4) v4.push(entry);
|
||||
// The same list read through casts to the declared element type.
|
||||
const viaCast = (address as dns.LookupAddress[]).map((entry) => entry.address);
|
||||
const viaShape = address.map((entry) => (entry as { address: string }).address);
|
||||
console.log("casts", viaCast.join(","), viaShape.join(","));
|
||||
callback(null, v4);
|
||||
return;
|
||||
}
|
||||
callback(null, address as string, family);
|
||||
});
|
||||
};
|
||||
}
|
||||
@@ -40,8 +55,11 @@ function flatten(input: HeadersLike | undefined): string[] {
|
||||
const lookup = createLookup();
|
||||
lookup("localhost", { family: 4 }, (err, address, family) => {
|
||||
console.log("one", err, address, family);
|
||||
lookup("127.0.0.1", 4, (err3, address3, family3) => {
|
||||
console.log("family", err3, address3, family3);
|
||||
console.log(flatten({ accept: "text/plain", "x-list": ["a", "b"], "x-skip": undefined }).join(","));
|
||||
lookup("localhost", { all: true }, (err2, addresses) => {
|
||||
console.log("all", err2, JSON.stringify(addresses));
|
||||
lookup("127.0.0.1", 4, (err3, address3, family3) => {
|
||||
console.log("family", err3, address3, family3);
|
||||
console.log(flatten({ accept: "text/plain", "x-list": ["a", "b"], "x-skip": undefined }).join(","));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
// The real @opentelemetry/api (1.9.0, its CommonJS build) with no SDK
|
||||
// registered: the metrics and trace entry points answer their no-op
|
||||
// implementations. The package's tsc output opens each module with an
|
||||
// `exports.X = void 0` preamble and builds its enums through
|
||||
// `exports.E || (exports.E = {})`, and its index adds a default-export
|
||||
// object next to the named re-exports.
|
||||
import { metrics, trace, DiagLogLevel, SpanKind, type Counter } from "@opentelemetry/api";
|
||||
|
||||
let counter: Counter | undefined;
|
||||
function getCounter(): Counter {
|
||||
if (!counter) {
|
||||
counter = metrics.getMeter("example-meter").createCounter("example.count", {
|
||||
description: "counts examples",
|
||||
});
|
||||
}
|
||||
return counter;
|
||||
}
|
||||
|
||||
getCounter().add(1, { reason: "first" });
|
||||
getCounter().add(2);
|
||||
console.log("meter provider", typeof metrics.getMeterProvider().getMeter);
|
||||
console.log("levels", DiagLogLevel.ERROR, DiagLogLevel.DEBUG, DiagLogLevel[DiagLogLevel.WARN]);
|
||||
console.log("span kinds", SpanKind.SERVER, SpanKind[SpanKind.CLIENT]);
|
||||
const span = trace.getTracer("example-tracer").startSpan("work");
|
||||
console.log("span recording", span.isRecording());
|
||||
span.end();
|
||||
+201
@@ -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.
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
import { Context, ContextManager } from '../context/types';
|
||||
/**
|
||||
* Singleton object which represents the entry point to the OpenTelemetry Context API
|
||||
*/
|
||||
export declare class ContextAPI {
|
||||
private static _instance?;
|
||||
/** Empty private constructor prevents end users from constructing a new instance of the API */
|
||||
private constructor();
|
||||
/** Get the singleton instance of the Context API */
|
||||
static getInstance(): ContextAPI;
|
||||
/**
|
||||
* Set the current context manager.
|
||||
*
|
||||
* @returns true if the context manager was successfully registered, else false
|
||||
*/
|
||||
setGlobalContextManager(contextManager: ContextManager): boolean;
|
||||
/**
|
||||
* Get the currently active context
|
||||
*/
|
||||
active(): Context;
|
||||
/**
|
||||
* Execute a function with an active context
|
||||
*
|
||||
* @param context context to be active during function execution
|
||||
* @param fn function to execute in a context
|
||||
* @param thisArg optional receiver to be used for calling fn
|
||||
* @param args optional arguments forwarded to fn
|
||||
*/
|
||||
with<A extends unknown[], F extends (...args: A) => ReturnType<F>>(context: Context, fn: F, thisArg?: ThisParameterType<F>, ...args: A): ReturnType<F>;
|
||||
/**
|
||||
* Bind a context to a target function or event emitter
|
||||
*
|
||||
* @param context context to bind to the event emitter or function. Defaults to the currently active context
|
||||
* @param target function or event emitter to bind
|
||||
*/
|
||||
bind<T>(context: Context, target: T): T;
|
||||
private _getContextManager;
|
||||
/** Disable and remove the global context manager */
|
||||
disable(): void;
|
||||
}
|
||||
//# sourceMappingURL=context.d.ts.map
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
"use strict";
|
||||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ContextAPI = void 0;
|
||||
const NoopContextManager_1 = require("../context/NoopContextManager");
|
||||
const global_utils_1 = require("../internal/global-utils");
|
||||
const diag_1 = require("./diag");
|
||||
const API_NAME = 'context';
|
||||
const NOOP_CONTEXT_MANAGER = new NoopContextManager_1.NoopContextManager();
|
||||
/**
|
||||
* Singleton object which represents the entry point to the OpenTelemetry Context API
|
||||
*/
|
||||
class ContextAPI {
|
||||
/** Empty private constructor prevents end users from constructing a new instance of the API */
|
||||
constructor() { }
|
||||
/** Get the singleton instance of the Context API */
|
||||
static getInstance() {
|
||||
if (!this._instance) {
|
||||
this._instance = new ContextAPI();
|
||||
}
|
||||
return this._instance;
|
||||
}
|
||||
/**
|
||||
* Set the current context manager.
|
||||
*
|
||||
* @returns true if the context manager was successfully registered, else false
|
||||
*/
|
||||
setGlobalContextManager(contextManager) {
|
||||
return (0, global_utils_1.registerGlobal)(API_NAME, contextManager, diag_1.DiagAPI.instance());
|
||||
}
|
||||
/**
|
||||
* Get the currently active context
|
||||
*/
|
||||
active() {
|
||||
return this._getContextManager().active();
|
||||
}
|
||||
/**
|
||||
* Execute a function with an active context
|
||||
*
|
||||
* @param context context to be active during function execution
|
||||
* @param fn function to execute in a context
|
||||
* @param thisArg optional receiver to be used for calling fn
|
||||
* @param args optional arguments forwarded to fn
|
||||
*/
|
||||
with(context, fn, thisArg, ...args) {
|
||||
return this._getContextManager().with(context, fn, thisArg, ...args);
|
||||
}
|
||||
/**
|
||||
* Bind a context to a target function or event emitter
|
||||
*
|
||||
* @param context context to bind to the event emitter or function. Defaults to the currently active context
|
||||
* @param target function or event emitter to bind
|
||||
*/
|
||||
bind(context, target) {
|
||||
return this._getContextManager().bind(context, target);
|
||||
}
|
||||
_getContextManager() {
|
||||
return (0, global_utils_1.getGlobal)(API_NAME) || NOOP_CONTEXT_MANAGER;
|
||||
}
|
||||
/** Disable and remove the global context manager */
|
||||
disable() {
|
||||
this._getContextManager().disable();
|
||||
(0, global_utils_1.unregisterGlobal)(API_NAME, diag_1.DiagAPI.instance());
|
||||
}
|
||||
}
|
||||
exports.ContextAPI = ContextAPI;
|
||||
//# sourceMappingURL=context.js.map
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
import { ComponentLoggerOptions, DiagLogFunction, DiagLogger, DiagLoggerApi } from '../diag/types';
|
||||
/**
|
||||
* Singleton object which represents the entry point to the OpenTelemetry internal
|
||||
* diagnostic API
|
||||
*/
|
||||
export declare class DiagAPI implements DiagLogger, DiagLoggerApi {
|
||||
private static _instance?;
|
||||
/** Get the singleton instance of the DiagAPI API */
|
||||
static instance(): DiagAPI;
|
||||
/**
|
||||
* Private internal constructor
|
||||
* @private
|
||||
*/
|
||||
private constructor();
|
||||
setLogger: DiagLoggerApi['setLogger'];
|
||||
/**
|
||||
*
|
||||
*/
|
||||
createComponentLogger: (options: ComponentLoggerOptions) => DiagLogger;
|
||||
verbose: DiagLogFunction;
|
||||
debug: DiagLogFunction;
|
||||
info: DiagLogFunction;
|
||||
warn: DiagLogFunction;
|
||||
error: DiagLogFunction;
|
||||
/**
|
||||
* Unregister the global logger and return to Noop
|
||||
*/
|
||||
disable: () => void;
|
||||
}
|
||||
//# sourceMappingURL=diag.d.ts.map
|
||||
+93
@@ -0,0 +1,93 @@
|
||||
"use strict";
|
||||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.DiagAPI = void 0;
|
||||
const ComponentLogger_1 = require("../diag/ComponentLogger");
|
||||
const logLevelLogger_1 = require("../diag/internal/logLevelLogger");
|
||||
const types_1 = require("../diag/types");
|
||||
const global_utils_1 = require("../internal/global-utils");
|
||||
const API_NAME = 'diag';
|
||||
/**
|
||||
* Singleton object which represents the entry point to the OpenTelemetry internal
|
||||
* diagnostic API
|
||||
*/
|
||||
class DiagAPI {
|
||||
/**
|
||||
* Private internal constructor
|
||||
* @private
|
||||
*/
|
||||
constructor() {
|
||||
function _logProxy(funcName) {
|
||||
return function (...args) {
|
||||
const logger = (0, global_utils_1.getGlobal)('diag');
|
||||
// shortcut if logger not set
|
||||
if (!logger)
|
||||
return;
|
||||
return logger[funcName](...args);
|
||||
};
|
||||
}
|
||||
// Using self local variable for minification purposes as 'this' cannot be minified
|
||||
const self = this;
|
||||
// DiagAPI specific functions
|
||||
const setLogger = (logger, optionsOrLogLevel = { logLevel: types_1.DiagLogLevel.INFO }) => {
|
||||
var _a, _b, _c;
|
||||
if (logger === self) {
|
||||
// There isn't much we can do here.
|
||||
// Logging to the console might break the user application.
|
||||
// Try to log to self. If a logger was previously registered it will receive the log.
|
||||
const err = new Error('Cannot use diag as the logger for itself. Please use a DiagLogger implementation like ConsoleDiagLogger or a custom implementation');
|
||||
self.error((_a = err.stack) !== null && _a !== void 0 ? _a : err.message);
|
||||
return false;
|
||||
}
|
||||
if (typeof optionsOrLogLevel === 'number') {
|
||||
optionsOrLogLevel = {
|
||||
logLevel: optionsOrLogLevel,
|
||||
};
|
||||
}
|
||||
const oldLogger = (0, global_utils_1.getGlobal)('diag');
|
||||
const newLogger = (0, logLevelLogger_1.createLogLevelDiagLogger)((_b = optionsOrLogLevel.logLevel) !== null && _b !== void 0 ? _b : types_1.DiagLogLevel.INFO, logger);
|
||||
// There already is an logger registered. We'll let it know before overwriting it.
|
||||
if (oldLogger && !optionsOrLogLevel.suppressOverrideMessage) {
|
||||
const stack = (_c = new Error().stack) !== null && _c !== void 0 ? _c : '<failed to generate stacktrace>';
|
||||
oldLogger.warn(`Current logger will be overwritten from ${stack}`);
|
||||
newLogger.warn(`Current logger will overwrite one already registered from ${stack}`);
|
||||
}
|
||||
return (0, global_utils_1.registerGlobal)('diag', newLogger, self, true);
|
||||
};
|
||||
self.setLogger = setLogger;
|
||||
self.disable = () => {
|
||||
(0, global_utils_1.unregisterGlobal)(API_NAME, self);
|
||||
};
|
||||
self.createComponentLogger = (options) => {
|
||||
return new ComponentLogger_1.DiagComponentLogger(options);
|
||||
};
|
||||
self.verbose = _logProxy('verbose');
|
||||
self.debug = _logProxy('debug');
|
||||
self.info = _logProxy('info');
|
||||
self.warn = _logProxy('warn');
|
||||
self.error = _logProxy('error');
|
||||
}
|
||||
/** Get the singleton instance of the DiagAPI API */
|
||||
static instance() {
|
||||
if (!this._instance) {
|
||||
this._instance = new DiagAPI();
|
||||
}
|
||||
return this._instance;
|
||||
}
|
||||
}
|
||||
exports.DiagAPI = DiagAPI;
|
||||
//# sourceMappingURL=diag.js.map
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
import { Meter, MeterOptions } from '../metrics/Meter';
|
||||
import { MeterProvider } from '../metrics/MeterProvider';
|
||||
/**
|
||||
* Singleton object which represents the entry point to the OpenTelemetry Metrics API
|
||||
*/
|
||||
export declare class MetricsAPI {
|
||||
private static _instance?;
|
||||
/** Empty private constructor prevents end users from constructing a new instance of the API */
|
||||
private constructor();
|
||||
/** Get the singleton instance of the Metrics API */
|
||||
static getInstance(): MetricsAPI;
|
||||
/**
|
||||
* Set the current global meter provider.
|
||||
* Returns true if the meter provider was successfully registered, else false.
|
||||
*/
|
||||
setGlobalMeterProvider(provider: MeterProvider): boolean;
|
||||
/**
|
||||
* Returns the global meter provider.
|
||||
*/
|
||||
getMeterProvider(): MeterProvider;
|
||||
/**
|
||||
* Returns a meter from the global meter provider.
|
||||
*/
|
||||
getMeter(name: string, version?: string, options?: MeterOptions): Meter;
|
||||
/** Remove the global meter provider */
|
||||
disable(): void;
|
||||
}
|
||||
//# sourceMappingURL=metrics.d.ts.map
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
"use strict";
|
||||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.MetricsAPI = void 0;
|
||||
const NoopMeterProvider_1 = require("../metrics/NoopMeterProvider");
|
||||
const global_utils_1 = require("../internal/global-utils");
|
||||
const diag_1 = require("./diag");
|
||||
const API_NAME = 'metrics';
|
||||
/**
|
||||
* Singleton object which represents the entry point to the OpenTelemetry Metrics API
|
||||
*/
|
||||
class MetricsAPI {
|
||||
/** Empty private constructor prevents end users from constructing a new instance of the API */
|
||||
constructor() { }
|
||||
/** Get the singleton instance of the Metrics API */
|
||||
static getInstance() {
|
||||
if (!this._instance) {
|
||||
this._instance = new MetricsAPI();
|
||||
}
|
||||
return this._instance;
|
||||
}
|
||||
/**
|
||||
* Set the current global meter provider.
|
||||
* Returns true if the meter provider was successfully registered, else false.
|
||||
*/
|
||||
setGlobalMeterProvider(provider) {
|
||||
return (0, global_utils_1.registerGlobal)(API_NAME, provider, diag_1.DiagAPI.instance());
|
||||
}
|
||||
/**
|
||||
* Returns the global meter provider.
|
||||
*/
|
||||
getMeterProvider() {
|
||||
return (0, global_utils_1.getGlobal)(API_NAME) || NoopMeterProvider_1.NOOP_METER_PROVIDER;
|
||||
}
|
||||
/**
|
||||
* Returns a meter from the global meter provider.
|
||||
*/
|
||||
getMeter(name, version, options) {
|
||||
return this.getMeterProvider().getMeter(name, version, options);
|
||||
}
|
||||
/** Remove the global meter provider */
|
||||
disable() {
|
||||
(0, global_utils_1.unregisterGlobal)(API_NAME, diag_1.DiagAPI.instance());
|
||||
}
|
||||
}
|
||||
exports.MetricsAPI = MetricsAPI;
|
||||
//# sourceMappingURL=metrics.js.map
|
||||
Generated
Vendored
+49
@@ -0,0 +1,49 @@
|
||||
import { Context } from '../context/types';
|
||||
import { TextMapGetter, TextMapPropagator, TextMapSetter } from '../propagation/TextMapPropagator';
|
||||
import { getBaggage, getActiveBaggage, setBaggage, deleteBaggage } from '../baggage/context-helpers';
|
||||
import { createBaggage } from '../baggage/utils';
|
||||
/**
|
||||
* Singleton object which represents the entry point to the OpenTelemetry Propagation API
|
||||
*/
|
||||
export declare class PropagationAPI {
|
||||
private static _instance?;
|
||||
/** Empty private constructor prevents end users from constructing a new instance of the API */
|
||||
private constructor();
|
||||
/** Get the singleton instance of the Propagator API */
|
||||
static getInstance(): PropagationAPI;
|
||||
/**
|
||||
* Set the current propagator.
|
||||
*
|
||||
* @returns true if the propagator was successfully registered, else false
|
||||
*/
|
||||
setGlobalPropagator(propagator: TextMapPropagator): boolean;
|
||||
/**
|
||||
* Inject context into a carrier to be propagated inter-process
|
||||
*
|
||||
* @param context Context carrying tracing data to inject
|
||||
* @param carrier carrier to inject context into
|
||||
* @param setter Function used to set values on the carrier
|
||||
*/
|
||||
inject<Carrier>(context: Context, carrier: Carrier, setter?: TextMapSetter<Carrier>): void;
|
||||
/**
|
||||
* Extract context from a carrier
|
||||
*
|
||||
* @param context Context which the newly created context will inherit from
|
||||
* @param carrier Carrier to extract context from
|
||||
* @param getter Function used to extract keys from a carrier
|
||||
*/
|
||||
extract<Carrier>(context: Context, carrier: Carrier, getter?: TextMapGetter<Carrier>): Context;
|
||||
/**
|
||||
* Return a list of all fields which may be used by the propagator.
|
||||
*/
|
||||
fields(): string[];
|
||||
/** Remove the global propagator */
|
||||
disable(): void;
|
||||
createBaggage: typeof createBaggage;
|
||||
getBaggage: typeof getBaggage;
|
||||
getActiveBaggage: typeof getActiveBaggage;
|
||||
setBaggage: typeof setBaggage;
|
||||
deleteBaggage: typeof deleteBaggage;
|
||||
private _getGlobalPropagator;
|
||||
}
|
||||
//# sourceMappingURL=propagation.d.ts.map
|
||||
+89
@@ -0,0 +1,89 @@
|
||||
"use strict";
|
||||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.PropagationAPI = void 0;
|
||||
const global_utils_1 = require("../internal/global-utils");
|
||||
const NoopTextMapPropagator_1 = require("../propagation/NoopTextMapPropagator");
|
||||
const TextMapPropagator_1 = require("../propagation/TextMapPropagator");
|
||||
const context_helpers_1 = require("../baggage/context-helpers");
|
||||
const utils_1 = require("../baggage/utils");
|
||||
const diag_1 = require("./diag");
|
||||
const API_NAME = 'propagation';
|
||||
const NOOP_TEXT_MAP_PROPAGATOR = new NoopTextMapPropagator_1.NoopTextMapPropagator();
|
||||
/**
|
||||
* Singleton object which represents the entry point to the OpenTelemetry Propagation API
|
||||
*/
|
||||
class PropagationAPI {
|
||||
/** Empty private constructor prevents end users from constructing a new instance of the API */
|
||||
constructor() {
|
||||
this.createBaggage = utils_1.createBaggage;
|
||||
this.getBaggage = context_helpers_1.getBaggage;
|
||||
this.getActiveBaggage = context_helpers_1.getActiveBaggage;
|
||||
this.setBaggage = context_helpers_1.setBaggage;
|
||||
this.deleteBaggage = context_helpers_1.deleteBaggage;
|
||||
}
|
||||
/** Get the singleton instance of the Propagator API */
|
||||
static getInstance() {
|
||||
if (!this._instance) {
|
||||
this._instance = new PropagationAPI();
|
||||
}
|
||||
return this._instance;
|
||||
}
|
||||
/**
|
||||
* Set the current propagator.
|
||||
*
|
||||
* @returns true if the propagator was successfully registered, else false
|
||||
*/
|
||||
setGlobalPropagator(propagator) {
|
||||
return (0, global_utils_1.registerGlobal)(API_NAME, propagator, diag_1.DiagAPI.instance());
|
||||
}
|
||||
/**
|
||||
* Inject context into a carrier to be propagated inter-process
|
||||
*
|
||||
* @param context Context carrying tracing data to inject
|
||||
* @param carrier carrier to inject context into
|
||||
* @param setter Function used to set values on the carrier
|
||||
*/
|
||||
inject(context, carrier, setter = TextMapPropagator_1.defaultTextMapSetter) {
|
||||
return this._getGlobalPropagator().inject(context, carrier, setter);
|
||||
}
|
||||
/**
|
||||
* Extract context from a carrier
|
||||
*
|
||||
* @param context Context which the newly created context will inherit from
|
||||
* @param carrier Carrier to extract context from
|
||||
* @param getter Function used to extract keys from a carrier
|
||||
*/
|
||||
extract(context, carrier, getter = TextMapPropagator_1.defaultTextMapGetter) {
|
||||
return this._getGlobalPropagator().extract(context, carrier, getter);
|
||||
}
|
||||
/**
|
||||
* Return a list of all fields which may be used by the propagator.
|
||||
*/
|
||||
fields() {
|
||||
return this._getGlobalPropagator().fields();
|
||||
}
|
||||
/** Remove the global propagator */
|
||||
disable() {
|
||||
(0, global_utils_1.unregisterGlobal)(API_NAME, diag_1.DiagAPI.instance());
|
||||
}
|
||||
_getGlobalPropagator() {
|
||||
return (0, global_utils_1.getGlobal)(API_NAME) || NOOP_TEXT_MAP_PROPAGATOR;
|
||||
}
|
||||
}
|
||||
exports.PropagationAPI = PropagationAPI;
|
||||
//# sourceMappingURL=propagation.js.map
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
import { isSpanContextValid, wrapSpanContext } from '../trace/spancontext-utils';
|
||||
import { Tracer } from '../trace/tracer';
|
||||
import { TracerProvider } from '../trace/tracer_provider';
|
||||
import { deleteSpan, getActiveSpan, getSpan, getSpanContext, setSpan, setSpanContext } from '../trace/context-utils';
|
||||
/**
|
||||
* Singleton object which represents the entry point to the OpenTelemetry Tracing API
|
||||
*/
|
||||
export declare class TraceAPI {
|
||||
private static _instance?;
|
||||
private _proxyTracerProvider;
|
||||
/** Empty private constructor prevents end users from constructing a new instance of the API */
|
||||
private constructor();
|
||||
/** Get the singleton instance of the Trace API */
|
||||
static getInstance(): TraceAPI;
|
||||
/**
|
||||
* Set the current global tracer.
|
||||
*
|
||||
* @returns true if the tracer provider was successfully registered, else false
|
||||
*/
|
||||
setGlobalTracerProvider(provider: TracerProvider): boolean;
|
||||
/**
|
||||
* Returns the global tracer provider.
|
||||
*/
|
||||
getTracerProvider(): TracerProvider;
|
||||
/**
|
||||
* Returns a tracer from the global tracer provider.
|
||||
*/
|
||||
getTracer(name: string, version?: string): Tracer;
|
||||
/** Remove the global tracer provider */
|
||||
disable(): void;
|
||||
wrapSpanContext: typeof wrapSpanContext;
|
||||
isSpanContextValid: typeof isSpanContextValid;
|
||||
deleteSpan: typeof deleteSpan;
|
||||
getSpan: typeof getSpan;
|
||||
getActiveSpan: typeof getActiveSpan;
|
||||
getSpanContext: typeof getSpanContext;
|
||||
setSpan: typeof setSpan;
|
||||
setSpanContext: typeof setSpanContext;
|
||||
}
|
||||
//# sourceMappingURL=trace.d.ts.map
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
"use strict";
|
||||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.TraceAPI = void 0;
|
||||
const global_utils_1 = require("../internal/global-utils");
|
||||
const ProxyTracerProvider_1 = require("../trace/ProxyTracerProvider");
|
||||
const spancontext_utils_1 = require("../trace/spancontext-utils");
|
||||
const context_utils_1 = require("../trace/context-utils");
|
||||
const diag_1 = require("./diag");
|
||||
const API_NAME = 'trace';
|
||||
/**
|
||||
* Singleton object which represents the entry point to the OpenTelemetry Tracing API
|
||||
*/
|
||||
class TraceAPI {
|
||||
/** Empty private constructor prevents end users from constructing a new instance of the API */
|
||||
constructor() {
|
||||
this._proxyTracerProvider = new ProxyTracerProvider_1.ProxyTracerProvider();
|
||||
this.wrapSpanContext = spancontext_utils_1.wrapSpanContext;
|
||||
this.isSpanContextValid = spancontext_utils_1.isSpanContextValid;
|
||||
this.deleteSpan = context_utils_1.deleteSpan;
|
||||
this.getSpan = context_utils_1.getSpan;
|
||||
this.getActiveSpan = context_utils_1.getActiveSpan;
|
||||
this.getSpanContext = context_utils_1.getSpanContext;
|
||||
this.setSpan = context_utils_1.setSpan;
|
||||
this.setSpanContext = context_utils_1.setSpanContext;
|
||||
}
|
||||
/** Get the singleton instance of the Trace API */
|
||||
static getInstance() {
|
||||
if (!this._instance) {
|
||||
this._instance = new TraceAPI();
|
||||
}
|
||||
return this._instance;
|
||||
}
|
||||
/**
|
||||
* Set the current global tracer.
|
||||
*
|
||||
* @returns true if the tracer provider was successfully registered, else false
|
||||
*/
|
||||
setGlobalTracerProvider(provider) {
|
||||
const success = (0, global_utils_1.registerGlobal)(API_NAME, this._proxyTracerProvider, diag_1.DiagAPI.instance());
|
||||
if (success) {
|
||||
this._proxyTracerProvider.setDelegate(provider);
|
||||
}
|
||||
return success;
|
||||
}
|
||||
/**
|
||||
* Returns the global tracer provider.
|
||||
*/
|
||||
getTracerProvider() {
|
||||
return (0, global_utils_1.getGlobal)(API_NAME) || this._proxyTracerProvider;
|
||||
}
|
||||
/**
|
||||
* Returns a tracer from the global tracer provider.
|
||||
*/
|
||||
getTracer(name, version) {
|
||||
return this.getTracerProvider().getTracer(name, version);
|
||||
}
|
||||
/** Remove the global tracer provider */
|
||||
disable() {
|
||||
(0, global_utils_1.unregisterGlobal)(API_NAME, diag_1.DiagAPI.instance());
|
||||
this._proxyTracerProvider = new ProxyTracerProvider_1.ProxyTracerProvider();
|
||||
}
|
||||
}
|
||||
exports.TraceAPI = TraceAPI;
|
||||
//# sourceMappingURL=trace.js.map
|
||||
Generated
Vendored
+29
@@ -0,0 +1,29 @@
|
||||
import { Context } from '../context/types';
|
||||
import { Baggage } from './types';
|
||||
/**
|
||||
* Retrieve the current baggage from the given context
|
||||
*
|
||||
* @param {Context} Context that manage all context values
|
||||
* @returns {Baggage} Extracted baggage from the context
|
||||
*/
|
||||
export declare function getBaggage(context: Context): Baggage | undefined;
|
||||
/**
|
||||
* Retrieve the current baggage from the active/current context
|
||||
*
|
||||
* @returns {Baggage} Extracted baggage from the context
|
||||
*/
|
||||
export declare function getActiveBaggage(): Baggage | undefined;
|
||||
/**
|
||||
* Store a baggage in the given context
|
||||
*
|
||||
* @param {Context} Context that manage all context values
|
||||
* @param {Baggage} baggage that will be set in the actual context
|
||||
*/
|
||||
export declare function setBaggage(context: Context, baggage: Baggage): Context;
|
||||
/**
|
||||
* Delete the baggage stored in the given context
|
||||
*
|
||||
* @param {Context} Context that manage all context values
|
||||
*/
|
||||
export declare function deleteBaggage(context: Context): Context;
|
||||
//# sourceMappingURL=context-helpers.d.ts.map
|
||||
Generated
Vendored
+63
@@ -0,0 +1,63 @@
|
||||
"use strict";
|
||||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.deleteBaggage = exports.setBaggage = exports.getActiveBaggage = exports.getBaggage = void 0;
|
||||
const context_1 = require("../api/context");
|
||||
const context_2 = require("../context/context");
|
||||
/**
|
||||
* Baggage key
|
||||
*/
|
||||
const BAGGAGE_KEY = (0, context_2.createContextKey)('OpenTelemetry Baggage Key');
|
||||
/**
|
||||
* Retrieve the current baggage from the given context
|
||||
*
|
||||
* @param {Context} Context that manage all context values
|
||||
* @returns {Baggage} Extracted baggage from the context
|
||||
*/
|
||||
function getBaggage(context) {
|
||||
return context.getValue(BAGGAGE_KEY) || undefined;
|
||||
}
|
||||
exports.getBaggage = getBaggage;
|
||||
/**
|
||||
* Retrieve the current baggage from the active/current context
|
||||
*
|
||||
* @returns {Baggage} Extracted baggage from the context
|
||||
*/
|
||||
function getActiveBaggage() {
|
||||
return getBaggage(context_1.ContextAPI.getInstance().active());
|
||||
}
|
||||
exports.getActiveBaggage = getActiveBaggage;
|
||||
/**
|
||||
* Store a baggage in the given context
|
||||
*
|
||||
* @param {Context} Context that manage all context values
|
||||
* @param {Baggage} baggage that will be set in the actual context
|
||||
*/
|
||||
function setBaggage(context, baggage) {
|
||||
return context.setValue(BAGGAGE_KEY, baggage);
|
||||
}
|
||||
exports.setBaggage = setBaggage;
|
||||
/**
|
||||
* Delete the baggage stored in the given context
|
||||
*
|
||||
* @param {Context} Context that manage all context values
|
||||
*/
|
||||
function deleteBaggage(context) {
|
||||
return context.deleteValue(BAGGAGE_KEY);
|
||||
}
|
||||
exports.deleteBaggage = deleteBaggage;
|
||||
//# sourceMappingURL=context-helpers.js.map
|
||||
Generated
Vendored
+12
@@ -0,0 +1,12 @@
|
||||
import type { Baggage, BaggageEntry } from '../types';
|
||||
export declare class BaggageImpl implements Baggage {
|
||||
private _entries;
|
||||
constructor(entries?: Map<string, BaggageEntry>);
|
||||
getEntry(key: string): BaggageEntry | undefined;
|
||||
getAllEntries(): [string, BaggageEntry][];
|
||||
setEntry(key: string, entry: BaggageEntry): BaggageImpl;
|
||||
removeEntry(key: string): BaggageImpl;
|
||||
removeEntries(...keys: string[]): BaggageImpl;
|
||||
clear(): BaggageImpl;
|
||||
}
|
||||
//# sourceMappingURL=baggage-impl.d.ts.map
|
||||
Generated
Vendored
+55
@@ -0,0 +1,55 @@
|
||||
"use strict";
|
||||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.BaggageImpl = void 0;
|
||||
class BaggageImpl {
|
||||
constructor(entries) {
|
||||
this._entries = entries ? new Map(entries) : new Map();
|
||||
}
|
||||
getEntry(key) {
|
||||
const entry = this._entries.get(key);
|
||||
if (!entry) {
|
||||
return undefined;
|
||||
}
|
||||
return Object.assign({}, entry);
|
||||
}
|
||||
getAllEntries() {
|
||||
return Array.from(this._entries.entries()).map(([k, v]) => [k, v]);
|
||||
}
|
||||
setEntry(key, entry) {
|
||||
const newBaggage = new BaggageImpl(this._entries);
|
||||
newBaggage._entries.set(key, entry);
|
||||
return newBaggage;
|
||||
}
|
||||
removeEntry(key) {
|
||||
const newBaggage = new BaggageImpl(this._entries);
|
||||
newBaggage._entries.delete(key);
|
||||
return newBaggage;
|
||||
}
|
||||
removeEntries(...keys) {
|
||||
const newBaggage = new BaggageImpl(this._entries);
|
||||
for (const key of keys) {
|
||||
newBaggage._entries.delete(key);
|
||||
}
|
||||
return newBaggage;
|
||||
}
|
||||
clear() {
|
||||
return new BaggageImpl();
|
||||
}
|
||||
}
|
||||
exports.BaggageImpl = BaggageImpl;
|
||||
//# sourceMappingURL=baggage-impl.js.map
|
||||
Generated
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
/**
|
||||
* Symbol used to make BaggageEntryMetadata an opaque type
|
||||
*/
|
||||
export declare const baggageEntryMetadataSymbol: unique symbol;
|
||||
//# sourceMappingURL=symbol.d.ts.map
|
||||
Generated
Vendored
+23
@@ -0,0 +1,23 @@
|
||||
"use strict";
|
||||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.baggageEntryMetadataSymbol = void 0;
|
||||
/**
|
||||
* Symbol used to make BaggageEntryMetadata an opaque type
|
||||
*/
|
||||
exports.baggageEntryMetadataSymbol = Symbol('BaggageEntryMetadata');
|
||||
//# sourceMappingURL=symbol.js.map
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
import { baggageEntryMetadataSymbol } from './internal/symbol';
|
||||
export interface BaggageEntry {
|
||||
/** `String` value of the `BaggageEntry`. */
|
||||
value: string;
|
||||
/**
|
||||
* Metadata is an optional string property defined by the W3C baggage specification.
|
||||
* It currently has no special meaning defined by the specification.
|
||||
*/
|
||||
metadata?: BaggageEntryMetadata;
|
||||
}
|
||||
/**
|
||||
* Serializable Metadata defined by the W3C baggage specification.
|
||||
* It currently has no special meaning defined by the OpenTelemetry or W3C.
|
||||
*/
|
||||
export declare type BaggageEntryMetadata = {
|
||||
toString(): string;
|
||||
} & {
|
||||
__TYPE__: typeof baggageEntryMetadataSymbol;
|
||||
};
|
||||
/**
|
||||
* Baggage represents collection of key-value pairs with optional metadata.
|
||||
* Each key of Baggage is associated with exactly one value.
|
||||
* Baggage may be used to annotate and enrich telemetry data.
|
||||
*/
|
||||
export interface Baggage {
|
||||
/**
|
||||
* Get an entry from Baggage if it exists
|
||||
*
|
||||
* @param key The key which identifies the BaggageEntry
|
||||
*/
|
||||
getEntry(key: string): BaggageEntry | undefined;
|
||||
/**
|
||||
* Get a list of all entries in the Baggage
|
||||
*/
|
||||
getAllEntries(): [string, BaggageEntry][];
|
||||
/**
|
||||
* Returns a new baggage with the entries from the current bag and the specified entry
|
||||
*
|
||||
* @param key string which identifies the baggage entry
|
||||
* @param entry BaggageEntry for the given key
|
||||
*/
|
||||
setEntry(key: string, entry: BaggageEntry): Baggage;
|
||||
/**
|
||||
* Returns a new baggage with the entries from the current bag except the removed entry
|
||||
*
|
||||
* @param key key identifying the entry to be removed
|
||||
*/
|
||||
removeEntry(key: string): Baggage;
|
||||
/**
|
||||
* Returns a new baggage with the entries from the current bag except the removed entries
|
||||
*
|
||||
* @param key keys identifying the entries to be removed
|
||||
*/
|
||||
removeEntries(...key: string[]): Baggage;
|
||||
/**
|
||||
* Returns a new baggage with no entries
|
||||
*/
|
||||
clear(): Baggage;
|
||||
}
|
||||
//# sourceMappingURL=types.d.ts.map
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
"use strict";
|
||||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
//# sourceMappingURL=types.js.map
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
import { Baggage, BaggageEntry, BaggageEntryMetadata } from './types';
|
||||
/**
|
||||
* Create a new Baggage with optional entries
|
||||
*
|
||||
* @param entries An array of baggage entries the new baggage should contain
|
||||
*/
|
||||
export declare function createBaggage(entries?: Record<string, BaggageEntry>): Baggage;
|
||||
/**
|
||||
* Create a serializable BaggageEntryMetadata object from a string.
|
||||
*
|
||||
* @param str string metadata. Format is currently not defined by the spec and has no special meaning.
|
||||
*
|
||||
*/
|
||||
export declare function baggageEntryMetadataFromString(str: string): BaggageEntryMetadata;
|
||||
//# sourceMappingURL=utils.d.ts.map
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
"use strict";
|
||||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.baggageEntryMetadataFromString = exports.createBaggage = void 0;
|
||||
const diag_1 = require("../api/diag");
|
||||
const baggage_impl_1 = require("./internal/baggage-impl");
|
||||
const symbol_1 = require("./internal/symbol");
|
||||
const diag = diag_1.DiagAPI.instance();
|
||||
/**
|
||||
* Create a new Baggage with optional entries
|
||||
*
|
||||
* @param entries An array of baggage entries the new baggage should contain
|
||||
*/
|
||||
function createBaggage(entries = {}) {
|
||||
return new baggage_impl_1.BaggageImpl(new Map(Object.entries(entries)));
|
||||
}
|
||||
exports.createBaggage = createBaggage;
|
||||
/**
|
||||
* Create a serializable BaggageEntryMetadata object from a string.
|
||||
*
|
||||
* @param str string metadata. Format is currently not defined by the spec and has no special meaning.
|
||||
*
|
||||
*/
|
||||
function baggageEntryMetadataFromString(str) {
|
||||
if (typeof str !== 'string') {
|
||||
diag.error(`Cannot create baggage metadata from unknown type: ${typeof str}`);
|
||||
str = '';
|
||||
}
|
||||
return {
|
||||
__TYPE__: symbol_1.baggageEntryMetadataSymbol,
|
||||
toString() {
|
||||
return str;
|
||||
},
|
||||
};
|
||||
}
|
||||
exports.baggageEntryMetadataFromString = baggageEntryMetadataFromString;
|
||||
//# sourceMappingURL=utils.js.map
|
||||
Generated
Vendored
+15
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* Attributes is a map from string to attribute values.
|
||||
*
|
||||
* Note: only the own enumerable keys are counted as valid attribute keys.
|
||||
*/
|
||||
export interface Attributes {
|
||||
[attributeKey: string]: AttributeValue | undefined;
|
||||
}
|
||||
/**
|
||||
* Attribute values may be any non-nullish primitive value except an object.
|
||||
*
|
||||
* null or undefined attribute values are invalid and will result in undefined behavior.
|
||||
*/
|
||||
export declare type AttributeValue = string | number | boolean | Array<null | undefined | string> | Array<null | undefined | number> | Array<null | undefined | boolean>;
|
||||
//# sourceMappingURL=Attributes.d.ts.map
|
||||
Generated
Vendored
+18
@@ -0,0 +1,18 @@
|
||||
"use strict";
|
||||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
//# sourceMappingURL=Attributes.js.map
|
||||
Generated
Vendored
+26
@@ -0,0 +1,26 @@
|
||||
interface ExceptionWithCode {
|
||||
code: string | number;
|
||||
name?: string;
|
||||
message?: string;
|
||||
stack?: string;
|
||||
}
|
||||
interface ExceptionWithMessage {
|
||||
code?: string | number;
|
||||
message: string;
|
||||
name?: string;
|
||||
stack?: string;
|
||||
}
|
||||
interface ExceptionWithName {
|
||||
code?: string | number;
|
||||
message?: string;
|
||||
name: string;
|
||||
stack?: string;
|
||||
}
|
||||
/**
|
||||
* Defines Exception.
|
||||
*
|
||||
* string or an object with one of (message or name or code) and optional stack
|
||||
*/
|
||||
export declare type Exception = ExceptionWithCode | ExceptionWithMessage | ExceptionWithName | string;
|
||||
export {};
|
||||
//# sourceMappingURL=Exception.d.ts.map
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
"use strict";
|
||||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
//# sourceMappingURL=Exception.js.map
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* Defines High-Resolution Time.
|
||||
*
|
||||
* The first number, HrTime[0], is UNIX Epoch time in seconds since 00:00:00 UTC on 1 January 1970.
|
||||
* The second number, HrTime[1], represents the partial second elapsed since Unix Epoch time represented by first number in nanoseconds.
|
||||
* For example, 2021-01-01T12:30:10.150Z in UNIX Epoch time in milliseconds is represented as 1609504210150.
|
||||
* The first number is calculated by converting and truncating the Epoch time in milliseconds to seconds:
|
||||
* HrTime[0] = Math.trunc(1609504210150 / 1000) = 1609504210.
|
||||
* The second number is calculated by converting the digits after the decimal point of the subtraction, (1609504210150 / 1000) - HrTime[0], to nanoseconds:
|
||||
* HrTime[1] = Number((1609504210.150 - HrTime[0]).toFixed(9)) * 1e9 = 150000000.
|
||||
* This is represented in HrTime format as [1609504210, 150000000].
|
||||
*/
|
||||
export declare type HrTime = [number, number];
|
||||
/**
|
||||
* Defines TimeInput.
|
||||
*
|
||||
* hrtime, epoch milliseconds, performance.now() or Date
|
||||
*/
|
||||
export declare type TimeInput = HrTime | number | Date;
|
||||
//# sourceMappingURL=Time.d.ts.map
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
//# sourceMappingURL=Time.js.map
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
import { ContextAPI } from './api/context';
|
||||
/** Entrypoint for context API */
|
||||
export declare const context: ContextAPI;
|
||||
//# sourceMappingURL=context-api.d.ts.map
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
"use strict";
|
||||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.context = void 0;
|
||||
// Split module-level variable definition into separate files to allow
|
||||
// tree-shaking on each api instance.
|
||||
const context_1 = require("./api/context");
|
||||
/** Entrypoint for context API */
|
||||
exports.context = context_1.ContextAPI.getInstance();
|
||||
//# sourceMappingURL=context-api.js.map
|
||||
Generated
Vendored
+9
@@ -0,0 +1,9 @@
|
||||
import * as types from './types';
|
||||
export declare class NoopContextManager implements types.ContextManager {
|
||||
active(): types.Context;
|
||||
with<A extends unknown[], F extends (...args: A) => ReturnType<F>>(_context: types.Context, fn: F, thisArg?: ThisParameterType<F>, ...args: A): ReturnType<F>;
|
||||
bind<T>(_context: types.Context, target: T): T;
|
||||
enable(): this;
|
||||
disable(): this;
|
||||
}
|
||||
//# sourceMappingURL=NoopContextManager.d.ts.map
|
||||
Generated
Vendored
+38
@@ -0,0 +1,38 @@
|
||||
"use strict";
|
||||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.NoopContextManager = void 0;
|
||||
const context_1 = require("./context");
|
||||
class NoopContextManager {
|
||||
active() {
|
||||
return context_1.ROOT_CONTEXT;
|
||||
}
|
||||
with(_context, fn, thisArg, ...args) {
|
||||
return fn.call(thisArg, ...args);
|
||||
}
|
||||
bind(_context, target) {
|
||||
return target;
|
||||
}
|
||||
enable() {
|
||||
return this;
|
||||
}
|
||||
disable() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
exports.NoopContextManager = NoopContextManager;
|
||||
//# sourceMappingURL=NoopContextManager.js.map
|
||||
Generated
Vendored
+6
@@ -0,0 +1,6 @@
|
||||
import { Context } from './types';
|
||||
/** Get a key to uniquely identify a context value */
|
||||
export declare function createContextKey(description: string): symbol;
|
||||
/** The root context is used as the default parent context when there is no active context */
|
||||
export declare const ROOT_CONTEXT: Context;
|
||||
//# sourceMappingURL=context.d.ts.map
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
"use strict";
|
||||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ROOT_CONTEXT = exports.createContextKey = void 0;
|
||||
/** Get a key to uniquely identify a context value */
|
||||
function createContextKey(description) {
|
||||
// The specification states that for the same input, multiple calls should
|
||||
// return different keys. Due to the nature of the JS dependency management
|
||||
// system, this creates problems where multiple versions of some package
|
||||
// could hold different keys for the same property.
|
||||
//
|
||||
// Therefore, we use Symbol.for which returns the same key for the same input.
|
||||
return Symbol.for(description);
|
||||
}
|
||||
exports.createContextKey = createContextKey;
|
||||
class BaseContext {
|
||||
/**
|
||||
* Construct a new context which inherits values from an optional parent context.
|
||||
*
|
||||
* @param parentContext a context from which to inherit values
|
||||
*/
|
||||
constructor(parentContext) {
|
||||
// for minification
|
||||
const self = this;
|
||||
self._currentContext = parentContext ? new Map(parentContext) : new Map();
|
||||
self.getValue = (key) => self._currentContext.get(key);
|
||||
self.setValue = (key, value) => {
|
||||
const context = new BaseContext(self._currentContext);
|
||||
context._currentContext.set(key, value);
|
||||
return context;
|
||||
};
|
||||
self.deleteValue = (key) => {
|
||||
const context = new BaseContext(self._currentContext);
|
||||
context._currentContext.delete(key);
|
||||
return context;
|
||||
};
|
||||
}
|
||||
}
|
||||
/** The root context is used as the default parent context when there is no active context */
|
||||
exports.ROOT_CONTEXT = new BaseContext();
|
||||
//# sourceMappingURL=context.js.map
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
export interface Context {
|
||||
/**
|
||||
* Get a value from the context.
|
||||
*
|
||||
* @param key key which identifies a context value
|
||||
*/
|
||||
getValue(key: symbol): unknown;
|
||||
/**
|
||||
* Create a new context which inherits from this context and has
|
||||
* the given key set to the given value.
|
||||
*
|
||||
* @param key context key for which to set the value
|
||||
* @param value value to set for the given key
|
||||
*/
|
||||
setValue(key: symbol, value: unknown): Context;
|
||||
/**
|
||||
* Return a new context which inherits from this context but does
|
||||
* not contain a value for the given key.
|
||||
*
|
||||
* @param key context key for which to clear a value
|
||||
*/
|
||||
deleteValue(key: symbol): Context;
|
||||
}
|
||||
export interface ContextManager {
|
||||
/**
|
||||
* Get the current active context
|
||||
*/
|
||||
active(): Context;
|
||||
/**
|
||||
* Run the fn callback with object set as the current active context
|
||||
* @param context Any object to set as the current active context
|
||||
* @param fn A callback to be immediately run within a specific context
|
||||
* @param thisArg optional receiver to be used for calling fn
|
||||
* @param args optional arguments forwarded to fn
|
||||
*/
|
||||
with<A extends unknown[], F extends (...args: A) => ReturnType<F>>(context: Context, fn: F, thisArg?: ThisParameterType<F>, ...args: A): ReturnType<F>;
|
||||
/**
|
||||
* Bind an object as the current context (or a specific one)
|
||||
* @param [context] Optionally specify the context which you want to assign
|
||||
* @param target Any object to which a context need to be set
|
||||
*/
|
||||
bind<T>(context: Context, target: T): T;
|
||||
/**
|
||||
* Enable context management
|
||||
*/
|
||||
enable(): this;
|
||||
/**
|
||||
* Disable context management
|
||||
*/
|
||||
disable(): this;
|
||||
}
|
||||
//# sourceMappingURL=types.d.ts.map
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
"use strict";
|
||||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
//# sourceMappingURL=types.js.map
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
import { DiagAPI } from './api/diag';
|
||||
/**
|
||||
* Entrypoint for Diag API.
|
||||
* Defines Diagnostic handler used for internal diagnostic logging operations.
|
||||
* The default provides a Noop DiagLogger implementation which may be changed via the
|
||||
* diag.setLogger(logger: DiagLogger) function.
|
||||
*/
|
||||
export declare const diag: DiagAPI;
|
||||
//# sourceMappingURL=diag-api.d.ts.map
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
"use strict";
|
||||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.diag = void 0;
|
||||
// Split module-level variable definition into separate files to allow
|
||||
// tree-shaking on each api instance.
|
||||
const diag_1 = require("./api/diag");
|
||||
/**
|
||||
* Entrypoint for Diag API.
|
||||
* Defines Diagnostic handler used for internal diagnostic logging operations.
|
||||
* The default provides a Noop DiagLogger implementation which may be changed via the
|
||||
* diag.setLogger(logger: DiagLogger) function.
|
||||
*/
|
||||
exports.diag = diag_1.DiagAPI.instance();
|
||||
//# sourceMappingURL=diag-api.js.map
|
||||
Generated
Vendored
+20
@@ -0,0 +1,20 @@
|
||||
import { ComponentLoggerOptions, DiagLogger } from './types';
|
||||
/**
|
||||
* Component Logger which is meant to be used as part of any component which
|
||||
* will add automatically additional namespace in front of the log message.
|
||||
* It will then forward all message to global diag logger
|
||||
* @example
|
||||
* const cLogger = diag.createComponentLogger({ namespace: '@opentelemetry/instrumentation-http' });
|
||||
* cLogger.debug('test');
|
||||
* // @opentelemetry/instrumentation-http test
|
||||
*/
|
||||
export declare class DiagComponentLogger implements DiagLogger {
|
||||
private _namespace;
|
||||
constructor(props: ComponentLoggerOptions);
|
||||
debug(...args: any[]): void;
|
||||
error(...args: any[]): void;
|
||||
info(...args: any[]): void;
|
||||
warn(...args: any[]): void;
|
||||
verbose(...args: any[]): void;
|
||||
}
|
||||
//# sourceMappingURL=ComponentLogger.d.ts.map
|
||||
Generated
Vendored
+59
@@ -0,0 +1,59 @@
|
||||
"use strict";
|
||||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.DiagComponentLogger = void 0;
|
||||
const global_utils_1 = require("../internal/global-utils");
|
||||
/**
|
||||
* Component Logger which is meant to be used as part of any component which
|
||||
* will add automatically additional namespace in front of the log message.
|
||||
* It will then forward all message to global diag logger
|
||||
* @example
|
||||
* const cLogger = diag.createComponentLogger({ namespace: '@opentelemetry/instrumentation-http' });
|
||||
* cLogger.debug('test');
|
||||
* // @opentelemetry/instrumentation-http test
|
||||
*/
|
||||
class DiagComponentLogger {
|
||||
constructor(props) {
|
||||
this._namespace = props.namespace || 'DiagComponentLogger';
|
||||
}
|
||||
debug(...args) {
|
||||
return logProxy('debug', this._namespace, args);
|
||||
}
|
||||
error(...args) {
|
||||
return logProxy('error', this._namespace, args);
|
||||
}
|
||||
info(...args) {
|
||||
return logProxy('info', this._namespace, args);
|
||||
}
|
||||
warn(...args) {
|
||||
return logProxy('warn', this._namespace, args);
|
||||
}
|
||||
verbose(...args) {
|
||||
return logProxy('verbose', this._namespace, args);
|
||||
}
|
||||
}
|
||||
exports.DiagComponentLogger = DiagComponentLogger;
|
||||
function logProxy(funcName, namespace, args) {
|
||||
const logger = (0, global_utils_1.getGlobal)('diag');
|
||||
// shortcut if logger not set
|
||||
if (!logger) {
|
||||
return;
|
||||
}
|
||||
args.unshift(namespace);
|
||||
return logger[funcName](...args);
|
||||
}
|
||||
//# sourceMappingURL=ComponentLogger.js.map
|
||||
Generated
Vendored
+38
@@ -0,0 +1,38 @@
|
||||
import { DiagLogger, DiagLogFunction } from './types';
|
||||
/**
|
||||
* A simple Immutable Console based diagnostic logger which will output any messages to the Console.
|
||||
* If you want to limit the amount of logging to a specific level or lower use the
|
||||
* {@link createLogLevelDiagLogger}
|
||||
*/
|
||||
export declare class DiagConsoleLogger implements DiagLogger {
|
||||
constructor();
|
||||
/** Log an error scenario that was not expected and caused the requested operation to fail. */
|
||||
error: DiagLogFunction;
|
||||
/**
|
||||
* Log a warning scenario to inform the developer of an issues that should be investigated.
|
||||
* The requested operation may or may not have succeeded or completed.
|
||||
*/
|
||||
warn: DiagLogFunction;
|
||||
/**
|
||||
* Log a general informational message, this should not affect functionality.
|
||||
* This is also the default logging level so this should NOT be used for logging
|
||||
* debugging level information.
|
||||
*/
|
||||
info: DiagLogFunction;
|
||||
/**
|
||||
* Log a general debug message that can be useful for identifying a failure.
|
||||
* Information logged at this level may include diagnostic details that would
|
||||
* help identify a failure scenario. Useful scenarios would be to log the execution
|
||||
* order of async operations
|
||||
*/
|
||||
debug: DiagLogFunction;
|
||||
/**
|
||||
* Log a detailed (verbose) trace level logging that can be used to identify failures
|
||||
* where debug level logging would be insufficient, this level of tracing can include
|
||||
* input and output parameters and as such may include PII information passing through
|
||||
* the API. As such it is recommended that this level of tracing should not be enabled
|
||||
* in a production environment.
|
||||
*/
|
||||
verbose: DiagLogFunction;
|
||||
}
|
||||
//# sourceMappingURL=consoleLogger.d.ts.map
|
||||
Generated
Vendored
+57
@@ -0,0 +1,57 @@
|
||||
"use strict";
|
||||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.DiagConsoleLogger = void 0;
|
||||
const consoleMap = [
|
||||
{ n: 'error', c: 'error' },
|
||||
{ n: 'warn', c: 'warn' },
|
||||
{ n: 'info', c: 'info' },
|
||||
{ n: 'debug', c: 'debug' },
|
||||
{ n: 'verbose', c: 'trace' },
|
||||
];
|
||||
/**
|
||||
* A simple Immutable Console based diagnostic logger which will output any messages to the Console.
|
||||
* If you want to limit the amount of logging to a specific level or lower use the
|
||||
* {@link createLogLevelDiagLogger}
|
||||
*/
|
||||
class DiagConsoleLogger {
|
||||
constructor() {
|
||||
function _consoleFunc(funcName) {
|
||||
return function (...args) {
|
||||
if (console) {
|
||||
// Some environments only expose the console when the F12 developer console is open
|
||||
// eslint-disable-next-line no-console
|
||||
let theFunc = console[funcName];
|
||||
if (typeof theFunc !== 'function') {
|
||||
// Not all environments support all functions
|
||||
// eslint-disable-next-line no-console
|
||||
theFunc = console.log;
|
||||
}
|
||||
// One last final check
|
||||
if (typeof theFunc === 'function') {
|
||||
return theFunc.apply(console, args);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
for (let i = 0; i < consoleMap.length; i++) {
|
||||
this[consoleMap[i].n] = _consoleFunc(consoleMap[i].c);
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.DiagConsoleLogger = DiagConsoleLogger;
|
||||
//# sourceMappingURL=consoleLogger.js.map
|
||||
Generated
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
import { DiagLogger, DiagLogLevel } from '../types';
|
||||
export declare function createLogLevelDiagLogger(maxLevel: DiagLogLevel, logger: DiagLogger): DiagLogger;
|
||||
//# sourceMappingURL=logLevelLogger.d.ts.map
|
||||
Generated
Vendored
+45
@@ -0,0 +1,45 @@
|
||||
"use strict";
|
||||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.createLogLevelDiagLogger = void 0;
|
||||
const types_1 = require("../types");
|
||||
function createLogLevelDiagLogger(maxLevel, logger) {
|
||||
if (maxLevel < types_1.DiagLogLevel.NONE) {
|
||||
maxLevel = types_1.DiagLogLevel.NONE;
|
||||
}
|
||||
else if (maxLevel > types_1.DiagLogLevel.ALL) {
|
||||
maxLevel = types_1.DiagLogLevel.ALL;
|
||||
}
|
||||
// In case the logger is null or undefined
|
||||
logger = logger || {};
|
||||
function _filterFunc(funcName, theLevel) {
|
||||
const theFunc = logger[funcName];
|
||||
if (typeof theFunc === 'function' && maxLevel >= theLevel) {
|
||||
return theFunc.bind(logger);
|
||||
}
|
||||
return function () { };
|
||||
}
|
||||
return {
|
||||
error: _filterFunc('error', types_1.DiagLogLevel.ERROR),
|
||||
warn: _filterFunc('warn', types_1.DiagLogLevel.WARN),
|
||||
info: _filterFunc('info', types_1.DiagLogLevel.INFO),
|
||||
debug: _filterFunc('debug', types_1.DiagLogLevel.DEBUG),
|
||||
verbose: _filterFunc('verbose', types_1.DiagLogLevel.VERBOSE),
|
||||
};
|
||||
}
|
||||
exports.createLogLevelDiagLogger = createLogLevelDiagLogger;
|
||||
//# sourceMappingURL=logLevelLogger.js.map
|
||||
Generated
Vendored
+8
@@ -0,0 +1,8 @@
|
||||
import { DiagLogger } from '../types';
|
||||
/**
|
||||
* Returns a No-Op Diagnostic logger where all messages do nothing.
|
||||
* @implements {@link DiagLogger}
|
||||
* @returns {DiagLogger}
|
||||
*/
|
||||
export declare function createNoopDiagLogger(): DiagLogger;
|
||||
//# sourceMappingURL=noopLogger.d.ts.map
|
||||
Generated
Vendored
+35
@@ -0,0 +1,35 @@
|
||||
"use strict";
|
||||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.createNoopDiagLogger = void 0;
|
||||
function noopLogFunction() { }
|
||||
/**
|
||||
* Returns a No-Op Diagnostic logger where all messages do nothing.
|
||||
* @implements {@link DiagLogger}
|
||||
* @returns {DiagLogger}
|
||||
*/
|
||||
function createNoopDiagLogger() {
|
||||
return {
|
||||
verbose: noopLogFunction,
|
||||
debug: noopLogFunction,
|
||||
info: noopLogFunction,
|
||||
warn: noopLogFunction,
|
||||
error: noopLogFunction,
|
||||
};
|
||||
}
|
||||
exports.createNoopDiagLogger = createNoopDiagLogger;
|
||||
//# sourceMappingURL=noopLogger.js.map
|
||||
+100
@@ -0,0 +1,100 @@
|
||||
export declare type DiagLogFunction = (message: string, ...args: unknown[]) => void;
|
||||
/**
|
||||
* Defines an internal diagnostic logger interface which is used to log internal diagnostic
|
||||
* messages, you can set the default diagnostic logger via the {@link DiagAPI} setLogger function.
|
||||
* API provided implementations include :-
|
||||
* - a No-Op {@link createNoopDiagLogger}
|
||||
* - a {@link DiagLogLevel} filtering wrapper {@link createLogLevelDiagLogger}
|
||||
* - a general Console {@link DiagConsoleLogger} version.
|
||||
*/
|
||||
export interface DiagLogger {
|
||||
/** Log an error scenario that was not expected and caused the requested operation to fail. */
|
||||
error: DiagLogFunction;
|
||||
/**
|
||||
* Log a warning scenario to inform the developer of an issues that should be investigated.
|
||||
* The requested operation may or may not have succeeded or completed.
|
||||
*/
|
||||
warn: DiagLogFunction;
|
||||
/**
|
||||
* Log a general informational message, this should not affect functionality.
|
||||
* This is also the default logging level so this should NOT be used for logging
|
||||
* debugging level information.
|
||||
*/
|
||||
info: DiagLogFunction;
|
||||
/**
|
||||
* Log a general debug message that can be useful for identifying a failure.
|
||||
* Information logged at this level may include diagnostic details that would
|
||||
* help identify a failure scenario.
|
||||
* For example: Logging the order of execution of async operations.
|
||||
*/
|
||||
debug: DiagLogFunction;
|
||||
/**
|
||||
* Log a detailed (verbose) trace level logging that can be used to identify failures
|
||||
* where debug level logging would be insufficient, this level of tracing can include
|
||||
* input and output parameters and as such may include PII information passing through
|
||||
* the API. As such it is recommended that this level of tracing should not be enabled
|
||||
* in a production environment.
|
||||
*/
|
||||
verbose: DiagLogFunction;
|
||||
}
|
||||
/**
|
||||
* Defines the available internal logging levels for the diagnostic logger, the numeric values
|
||||
* of the levels are defined to match the original values from the initial LogLevel to avoid
|
||||
* compatibility/migration issues for any implementation that assume the numeric ordering.
|
||||
*/
|
||||
export declare enum DiagLogLevel {
|
||||
/** Diagnostic Logging level setting to disable all logging (except and forced logs) */
|
||||
NONE = 0,
|
||||
/** Identifies an error scenario */
|
||||
ERROR = 30,
|
||||
/** Identifies a warning scenario */
|
||||
WARN = 50,
|
||||
/** General informational log message */
|
||||
INFO = 60,
|
||||
/** General debug log message */
|
||||
DEBUG = 70,
|
||||
/**
|
||||
* Detailed trace level logging should only be used for development, should only be set
|
||||
* in a development environment.
|
||||
*/
|
||||
VERBOSE = 80,
|
||||
/** Used to set the logging level to include all logging */
|
||||
ALL = 9999
|
||||
}
|
||||
/**
|
||||
* Defines options for ComponentLogger
|
||||
*/
|
||||
export interface ComponentLoggerOptions {
|
||||
namespace: string;
|
||||
}
|
||||
export interface DiagLoggerOptions {
|
||||
/**
|
||||
* The {@link DiagLogLevel} used to filter logs sent to the logger.
|
||||
*
|
||||
* @defaultValue DiagLogLevel.INFO
|
||||
*/
|
||||
logLevel?: DiagLogLevel;
|
||||
/**
|
||||
* Setting this value to `true` will suppress the warning message normally emitted when registering a logger when another logger is already registered.
|
||||
*/
|
||||
suppressOverrideMessage?: boolean;
|
||||
}
|
||||
export interface DiagLoggerApi {
|
||||
/**
|
||||
* Set the global DiagLogger and DiagLogLevel.
|
||||
* If a global diag logger is already set, this will override it.
|
||||
*
|
||||
* @param logger - The {@link DiagLogger} instance to set as the default logger.
|
||||
* @param options - A {@link DiagLoggerOptions} object. If not provided, default values will be set.
|
||||
* @returns `true` if the logger was successfully registered, else `false`
|
||||
*/
|
||||
setLogger(logger: DiagLogger, options?: DiagLoggerOptions): boolean;
|
||||
/**
|
||||
*
|
||||
* @param logger - The {@link DiagLogger} instance to set as the default logger.
|
||||
* @param logLevel - The {@link DiagLogLevel} used to filter logs sent to the logger. If not provided it will default to {@link DiagLogLevel.INFO}.
|
||||
* @returns `true` if the logger was successfully registered, else `false`
|
||||
*/
|
||||
setLogger(logger: DiagLogger, logLevel?: DiagLogLevel): boolean;
|
||||
}
|
||||
//# sourceMappingURL=types.d.ts.map
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
"use strict";
|
||||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.DiagLogLevel = void 0;
|
||||
/**
|
||||
* Defines the available internal logging levels for the diagnostic logger, the numeric values
|
||||
* of the levels are defined to match the original values from the initial LogLevel to avoid
|
||||
* compatibility/migration issues for any implementation that assume the numeric ordering.
|
||||
*/
|
||||
var DiagLogLevel;
|
||||
(function (DiagLogLevel) {
|
||||
/** Diagnostic Logging level setting to disable all logging (except and forced logs) */
|
||||
DiagLogLevel[DiagLogLevel["NONE"] = 0] = "NONE";
|
||||
/** Identifies an error scenario */
|
||||
DiagLogLevel[DiagLogLevel["ERROR"] = 30] = "ERROR";
|
||||
/** Identifies a warning scenario */
|
||||
DiagLogLevel[DiagLogLevel["WARN"] = 50] = "WARN";
|
||||
/** General informational log message */
|
||||
DiagLogLevel[DiagLogLevel["INFO"] = 60] = "INFO";
|
||||
/** General debug log message */
|
||||
DiagLogLevel[DiagLogLevel["DEBUG"] = 70] = "DEBUG";
|
||||
/**
|
||||
* Detailed trace level logging should only be used for development, should only be set
|
||||
* in a development environment.
|
||||
*/
|
||||
DiagLogLevel[DiagLogLevel["VERBOSE"] = 80] = "VERBOSE";
|
||||
/** Used to set the logging level to include all logging */
|
||||
DiagLogLevel[DiagLogLevel["ALL"] = 9999] = "ALL";
|
||||
})(DiagLogLevel = exports.DiagLogLevel || (exports.DiagLogLevel = {}));
|
||||
//# sourceMappingURL=types.js.map
|
||||
Generated
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
export { wrapTracer, SugaredTracer } from './trace/SugaredTracer';
|
||||
export { SugaredSpanOptions } from './trace/SugaredOptions';
|
||||
//# sourceMappingURL=index.d.ts.map
|
||||
Generated
Vendored
+22
@@ -0,0 +1,22 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.SugaredTracer = exports.wrapTracer = void 0;
|
||||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
var SugaredTracer_1 = require("./trace/SugaredTracer");
|
||||
Object.defineProperty(exports, "wrapTracer", { enumerable: true, get: function () { return SugaredTracer_1.wrapTracer; } });
|
||||
Object.defineProperty(exports, "SugaredTracer", { enumerable: true, get: function () { return SugaredTracer_1.SugaredTracer; } });
|
||||
//# sourceMappingURL=index.js.map
|
||||
Generated
Vendored
+13
@@ -0,0 +1,13 @@
|
||||
import { Span, SpanOptions } from '../../';
|
||||
/**
|
||||
* Options needed for span creation
|
||||
*/
|
||||
export interface SugaredSpanOptions extends SpanOptions {
|
||||
/**
|
||||
* function to overwrite default exception behavior to record the exception. No exceptions should be thrown in the function.
|
||||
* @param e Error which triggered this exception
|
||||
* @param span current span from context
|
||||
*/
|
||||
onException?: (e: Error, span: Span) => void;
|
||||
}
|
||||
//# sourceMappingURL=SugaredOptions.d.ts.map
|
||||
Generated
Vendored
+18
@@ -0,0 +1,18 @@
|
||||
"use strict";
|
||||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
//# sourceMappingURL=SugaredOptions.js.map
|
||||
Generated
Vendored
+64
@@ -0,0 +1,64 @@
|
||||
import { SugaredSpanOptions } from './SugaredOptions';
|
||||
import { Context, Span, Tracer } from '../../';
|
||||
/**
|
||||
* return a new SugaredTracer created from the supplied one
|
||||
* @param tracer
|
||||
*/
|
||||
export declare function wrapTracer(tracer: Tracer): SugaredTracer;
|
||||
export declare class SugaredTracer implements Tracer {
|
||||
private readonly _tracer;
|
||||
constructor(tracer: Tracer);
|
||||
startActiveSpan: Tracer['startActiveSpan'];
|
||||
startSpan: Tracer['startSpan'];
|
||||
/**
|
||||
* Starts a new {@link Span} and calls the given function passing it the
|
||||
* created span as first argument.
|
||||
* Additionally, the new span gets set in context and this context is activated
|
||||
* for the duration of the function call.
|
||||
* The span will be closed after the function has executed.
|
||||
* If an exception occurs, it is recorded, the status is set to ERROR and the exception is rethrown.
|
||||
*
|
||||
* @param name The name of the span
|
||||
* @param [options] SugaredSpanOptions used for span creation
|
||||
* @param [context] Context to use to extract parent
|
||||
* @param fn function called in the context of the span and receives the newly created span as an argument
|
||||
* @returns return value of fn
|
||||
* @example
|
||||
* const something = tracer.withActiveSpan('op', span => {
|
||||
* // do some work
|
||||
* });
|
||||
* @example
|
||||
* const something = await tracer.withActiveSpan('op', span => {
|
||||
* // do some async work
|
||||
* });
|
||||
*/
|
||||
withActiveSpan<F extends (span: Span) => ReturnType<F>>(name: string, fn: F): ReturnType<F>;
|
||||
withActiveSpan<F extends (span: Span) => ReturnType<F>>(name: string, options: SugaredSpanOptions, fn: F): ReturnType<F>;
|
||||
withActiveSpan<F extends (span: Span) => ReturnType<F>>(name: string, options: SugaredSpanOptions, context: Context, fn: F): ReturnType<F>;
|
||||
/**
|
||||
* Starts a new {@link Span} and ends it after execution of fn without setting it on context.
|
||||
* The span will be closed after the function has executed.
|
||||
* If an exception occurs, it is recorded, the status is et to ERROR and rethrown.
|
||||
*
|
||||
* This method does NOT modify the current Context.
|
||||
*
|
||||
* @param name The name of the span
|
||||
* @param [options] SugaredSpanOptions used for span creation
|
||||
* @param [context] Context to use to extract parent
|
||||
* @param fn function called in the context of the span and receives the newly created span as an argument
|
||||
* @returns Span The newly created span
|
||||
* @example
|
||||
* const something = tracer.withSpan('op', span => {
|
||||
* // do some work
|
||||
* });
|
||||
* @example
|
||||
* const something = await tracer.withSpan('op', span => {
|
||||
* // do some async work
|
||||
* });
|
||||
*/
|
||||
withSpan<F extends (span: Span) => ReturnType<F>>(name: string, fn: F): ReturnType<F>;
|
||||
withSpan<F extends (span: Span) => ReturnType<F>>(name: string, options: SugaredSpanOptions, fn: F): ReturnType<F>;
|
||||
withSpan<F extends (span: Span) => ReturnType<F>>(name: string, options: SugaredSpanOptions, context: Context, fn: F): ReturnType<F>;
|
||||
withSpan<F extends (span: Span) => ReturnType<F>>(name: string, options: SugaredSpanOptions, context: Context, fn: F): ReturnType<F>;
|
||||
}
|
||||
//# sourceMappingURL=SugaredTracer.d.ts.map
|
||||
Generated
Vendored
+93
@@ -0,0 +1,93 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.SugaredTracer = exports.wrapTracer = void 0;
|
||||
const __1 = require("../../");
|
||||
const defaultOnException = (e, span) => {
|
||||
span.recordException(e);
|
||||
span.setStatus({
|
||||
code: __1.SpanStatusCode.ERROR,
|
||||
});
|
||||
};
|
||||
/**
|
||||
* return a new SugaredTracer created from the supplied one
|
||||
* @param tracer
|
||||
*/
|
||||
function wrapTracer(tracer) {
|
||||
return new SugaredTracer(tracer);
|
||||
}
|
||||
exports.wrapTracer = wrapTracer;
|
||||
class SugaredTracer {
|
||||
constructor(tracer) {
|
||||
this._tracer = tracer;
|
||||
this.startSpan = tracer.startSpan.bind(this._tracer);
|
||||
this.startActiveSpan = tracer.startActiveSpan.bind(this._tracer);
|
||||
}
|
||||
withActiveSpan(name, arg2, arg3, arg4) {
|
||||
const { opts, ctx, fn } = massageParams(arg2, arg3, arg4);
|
||||
return this._tracer.startActiveSpan(name, opts, ctx, (span) => handleFn(span, opts, fn));
|
||||
}
|
||||
withSpan(name, arg2, arg3, arg4) {
|
||||
const { opts, ctx, fn } = massageParams(arg2, arg3, arg4);
|
||||
const span = this._tracer.startSpan(name, opts, ctx);
|
||||
return handleFn(span, opts, fn);
|
||||
}
|
||||
}
|
||||
exports.SugaredTracer = SugaredTracer;
|
||||
/**
|
||||
* Massages parameters of withSpan and withActiveSpan to allow signature overwrites
|
||||
* @param arg
|
||||
* @param arg2
|
||||
* @param arg3
|
||||
*/
|
||||
function massageParams(arg, arg2, arg3) {
|
||||
let opts;
|
||||
let ctx;
|
||||
let fn;
|
||||
if (!arg2 && !arg3) {
|
||||
fn = arg;
|
||||
}
|
||||
else if (!arg3) {
|
||||
opts = arg;
|
||||
fn = arg2;
|
||||
}
|
||||
else {
|
||||
opts = arg;
|
||||
ctx = arg2;
|
||||
fn = arg3;
|
||||
}
|
||||
opts = opts !== null && opts !== void 0 ? opts : {};
|
||||
ctx = ctx !== null && ctx !== void 0 ? ctx : __1.context.active();
|
||||
return { opts, ctx, fn };
|
||||
}
|
||||
/**
|
||||
* Executes fn, returns results and runs onException in the case of exception to allow overwriting of error handling
|
||||
* @param span
|
||||
* @param opts
|
||||
* @param fn
|
||||
*/
|
||||
function handleFn(span, opts, fn) {
|
||||
var _a;
|
||||
const onException = (_a = opts.onException) !== null && _a !== void 0 ? _a : defaultOnException;
|
||||
const errorHandler = (e) => {
|
||||
onException(e, span);
|
||||
span.end();
|
||||
throw e;
|
||||
};
|
||||
try {
|
||||
const ret = fn(span);
|
||||
// if fn is an async function, attach a recordException and spanEnd callback to the promise
|
||||
if (typeof (ret === null || ret === void 0 ? void 0 : ret.then) === 'function') {
|
||||
return ret.then(val => {
|
||||
span.end();
|
||||
return val;
|
||||
}, errorHandler);
|
||||
}
|
||||
span.end();
|
||||
return ret;
|
||||
}
|
||||
catch (e) {
|
||||
// add throw to signal the compiler that this will throw in the inner scope
|
||||
throw errorHandler(e);
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=SugaredTracer.js.map
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
export { BaggageEntry, BaggageEntryMetadata, Baggage } from './baggage/types';
|
||||
export { baggageEntryMetadataFromString } from './baggage/utils';
|
||||
export { Exception } from './common/Exception';
|
||||
export { HrTime, TimeInput } from './common/Time';
|
||||
export { Attributes, AttributeValue } from './common/Attributes';
|
||||
export { createContextKey, ROOT_CONTEXT } from './context/context';
|
||||
export { Context, ContextManager } from './context/types';
|
||||
export type { ContextAPI } from './api/context';
|
||||
export { DiagConsoleLogger } from './diag/consoleLogger';
|
||||
export { DiagLogFunction, DiagLogger, DiagLogLevel, ComponentLoggerOptions, DiagLoggerOptions, } from './diag/types';
|
||||
export type { DiagAPI } from './api/diag';
|
||||
export { createNoopMeter } from './metrics/NoopMeter';
|
||||
export { MeterOptions, Meter } from './metrics/Meter';
|
||||
export { MeterProvider } from './metrics/MeterProvider';
|
||||
export { ValueType, Counter, Gauge, Histogram, MetricOptions, Observable, ObservableCounter, ObservableGauge, ObservableUpDownCounter, UpDownCounter, BatchObservableCallback, MetricAdvice, MetricAttributes, MetricAttributeValue, ObservableCallback, } from './metrics/Metric';
|
||||
export { BatchObservableResult, ObservableResult, } from './metrics/ObservableResult';
|
||||
export type { MetricsAPI } from './api/metrics';
|
||||
export { TextMapPropagator, TextMapSetter, TextMapGetter, defaultTextMapGetter, defaultTextMapSetter, } from './propagation/TextMapPropagator';
|
||||
export type { PropagationAPI } from './api/propagation';
|
||||
export { SpanAttributes, SpanAttributeValue } from './trace/attributes';
|
||||
export { Link } from './trace/link';
|
||||
export { ProxyTracer, TracerDelegator } from './trace/ProxyTracer';
|
||||
export { ProxyTracerProvider } from './trace/ProxyTracerProvider';
|
||||
export { Sampler } from './trace/Sampler';
|
||||
export { SamplingDecision, SamplingResult } from './trace/SamplingResult';
|
||||
export { SpanContext } from './trace/span_context';
|
||||
export { SpanKind } from './trace/span_kind';
|
||||
export { Span } from './trace/span';
|
||||
export { SpanOptions } from './trace/SpanOptions';
|
||||
export { SpanStatus, SpanStatusCode } from './trace/status';
|
||||
export { TraceFlags } from './trace/trace_flags';
|
||||
export { TraceState } from './trace/trace_state';
|
||||
export { createTraceState } from './trace/internal/utils';
|
||||
export { TracerProvider } from './trace/tracer_provider';
|
||||
export { Tracer } from './trace/tracer';
|
||||
export { TracerOptions } from './trace/tracer_options';
|
||||
export { isSpanContextValid, isValidTraceId, isValidSpanId, } from './trace/spancontext-utils';
|
||||
export { INVALID_SPANID, INVALID_TRACEID, INVALID_SPAN_CONTEXT, } from './trace/invalid-span-constants';
|
||||
export type { TraceAPI } from './api/trace';
|
||||
import { context } from './context-api';
|
||||
import { diag } from './diag-api';
|
||||
import { metrics } from './metrics-api';
|
||||
import { propagation } from './propagation-api';
|
||||
import { trace } from './trace-api';
|
||||
export { context, diag, metrics, propagation, trace };
|
||||
declare const _default: {
|
||||
context: import("./api/context").ContextAPI;
|
||||
diag: import("./api/diag").DiagAPI;
|
||||
metrics: import("./api/metrics").MetricsAPI;
|
||||
propagation: import("./api/propagation").PropagationAPI;
|
||||
trace: import("./api/trace").TraceAPI;
|
||||
};
|
||||
export default _default;
|
||||
//# sourceMappingURL=index.d.ts.map
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
"use strict";
|
||||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.trace = exports.propagation = exports.metrics = exports.diag = exports.context = exports.INVALID_SPAN_CONTEXT = exports.INVALID_TRACEID = exports.INVALID_SPANID = exports.isValidSpanId = exports.isValidTraceId = exports.isSpanContextValid = exports.createTraceState = exports.TraceFlags = exports.SpanStatusCode = exports.SpanKind = exports.SamplingDecision = exports.ProxyTracerProvider = exports.ProxyTracer = exports.defaultTextMapSetter = exports.defaultTextMapGetter = exports.ValueType = exports.createNoopMeter = exports.DiagLogLevel = exports.DiagConsoleLogger = exports.ROOT_CONTEXT = exports.createContextKey = exports.baggageEntryMetadataFromString = void 0;
|
||||
var utils_1 = require("./baggage/utils");
|
||||
Object.defineProperty(exports, "baggageEntryMetadataFromString", { enumerable: true, get: function () { return utils_1.baggageEntryMetadataFromString; } });
|
||||
// Context APIs
|
||||
var context_1 = require("./context/context");
|
||||
Object.defineProperty(exports, "createContextKey", { enumerable: true, get: function () { return context_1.createContextKey; } });
|
||||
Object.defineProperty(exports, "ROOT_CONTEXT", { enumerable: true, get: function () { return context_1.ROOT_CONTEXT; } });
|
||||
// Diag APIs
|
||||
var consoleLogger_1 = require("./diag/consoleLogger");
|
||||
Object.defineProperty(exports, "DiagConsoleLogger", { enumerable: true, get: function () { return consoleLogger_1.DiagConsoleLogger; } });
|
||||
var types_1 = require("./diag/types");
|
||||
Object.defineProperty(exports, "DiagLogLevel", { enumerable: true, get: function () { return types_1.DiagLogLevel; } });
|
||||
// Metrics APIs
|
||||
var NoopMeter_1 = require("./metrics/NoopMeter");
|
||||
Object.defineProperty(exports, "createNoopMeter", { enumerable: true, get: function () { return NoopMeter_1.createNoopMeter; } });
|
||||
var Metric_1 = require("./metrics/Metric");
|
||||
Object.defineProperty(exports, "ValueType", { enumerable: true, get: function () { return Metric_1.ValueType; } });
|
||||
// Propagation APIs
|
||||
var TextMapPropagator_1 = require("./propagation/TextMapPropagator");
|
||||
Object.defineProperty(exports, "defaultTextMapGetter", { enumerable: true, get: function () { return TextMapPropagator_1.defaultTextMapGetter; } });
|
||||
Object.defineProperty(exports, "defaultTextMapSetter", { enumerable: true, get: function () { return TextMapPropagator_1.defaultTextMapSetter; } });
|
||||
var ProxyTracer_1 = require("./trace/ProxyTracer");
|
||||
Object.defineProperty(exports, "ProxyTracer", { enumerable: true, get: function () { return ProxyTracer_1.ProxyTracer; } });
|
||||
var ProxyTracerProvider_1 = require("./trace/ProxyTracerProvider");
|
||||
Object.defineProperty(exports, "ProxyTracerProvider", { enumerable: true, get: function () { return ProxyTracerProvider_1.ProxyTracerProvider; } });
|
||||
var SamplingResult_1 = require("./trace/SamplingResult");
|
||||
Object.defineProperty(exports, "SamplingDecision", { enumerable: true, get: function () { return SamplingResult_1.SamplingDecision; } });
|
||||
var span_kind_1 = require("./trace/span_kind");
|
||||
Object.defineProperty(exports, "SpanKind", { enumerable: true, get: function () { return span_kind_1.SpanKind; } });
|
||||
var status_1 = require("./trace/status");
|
||||
Object.defineProperty(exports, "SpanStatusCode", { enumerable: true, get: function () { return status_1.SpanStatusCode; } });
|
||||
var trace_flags_1 = require("./trace/trace_flags");
|
||||
Object.defineProperty(exports, "TraceFlags", { enumerable: true, get: function () { return trace_flags_1.TraceFlags; } });
|
||||
var utils_2 = require("./trace/internal/utils");
|
||||
Object.defineProperty(exports, "createTraceState", { enumerable: true, get: function () { return utils_2.createTraceState; } });
|
||||
var spancontext_utils_1 = require("./trace/spancontext-utils");
|
||||
Object.defineProperty(exports, "isSpanContextValid", { enumerable: true, get: function () { return spancontext_utils_1.isSpanContextValid; } });
|
||||
Object.defineProperty(exports, "isValidTraceId", { enumerable: true, get: function () { return spancontext_utils_1.isValidTraceId; } });
|
||||
Object.defineProperty(exports, "isValidSpanId", { enumerable: true, get: function () { return spancontext_utils_1.isValidSpanId; } });
|
||||
var invalid_span_constants_1 = require("./trace/invalid-span-constants");
|
||||
Object.defineProperty(exports, "INVALID_SPANID", { enumerable: true, get: function () { return invalid_span_constants_1.INVALID_SPANID; } });
|
||||
Object.defineProperty(exports, "INVALID_TRACEID", { enumerable: true, get: function () { return invalid_span_constants_1.INVALID_TRACEID; } });
|
||||
Object.defineProperty(exports, "INVALID_SPAN_CONTEXT", { enumerable: true, get: function () { return invalid_span_constants_1.INVALID_SPAN_CONTEXT; } });
|
||||
// Split module-level variable definition into separate files to allow
|
||||
// tree-shaking on each api instance.
|
||||
const context_api_1 = require("./context-api");
|
||||
Object.defineProperty(exports, "context", { enumerable: true, get: function () { return context_api_1.context; } });
|
||||
const diag_api_1 = require("./diag-api");
|
||||
Object.defineProperty(exports, "diag", { enumerable: true, get: function () { return diag_api_1.diag; } });
|
||||
const metrics_api_1 = require("./metrics-api");
|
||||
Object.defineProperty(exports, "metrics", { enumerable: true, get: function () { return metrics_api_1.metrics; } });
|
||||
const propagation_api_1 = require("./propagation-api");
|
||||
Object.defineProperty(exports, "propagation", { enumerable: true, get: function () { return propagation_api_1.propagation; } });
|
||||
const trace_api_1 = require("./trace-api");
|
||||
Object.defineProperty(exports, "trace", { enumerable: true, get: function () { return trace_api_1.trace; } });
|
||||
// Default export.
|
||||
exports.default = {
|
||||
context: context_api_1.context,
|
||||
diag: diag_api_1.diag,
|
||||
metrics: metrics_api_1.metrics,
|
||||
propagation: propagation_api_1.propagation,
|
||||
trace: trace_api_1.trace,
|
||||
};
|
||||
//# sourceMappingURL=index.js.map
|
||||
Generated
Vendored
+18
@@ -0,0 +1,18 @@
|
||||
import { MeterProvider } from '../metrics/MeterProvider';
|
||||
import { ContextManager } from '../context/types';
|
||||
import { DiagLogger } from '../diag/types';
|
||||
import { TextMapPropagator } from '../propagation/TextMapPropagator';
|
||||
import type { TracerProvider } from '../trace/tracer_provider';
|
||||
export declare function registerGlobal<Type extends keyof OTelGlobalAPI>(type: Type, instance: OTelGlobalAPI[Type], diag: DiagLogger, allowOverride?: boolean): boolean;
|
||||
export declare function getGlobal<Type extends keyof OTelGlobalAPI>(type: Type): OTelGlobalAPI[Type] | undefined;
|
||||
export declare function unregisterGlobal(type: keyof OTelGlobalAPI, diag: DiagLogger): void;
|
||||
declare type OTelGlobalAPI = {
|
||||
version: string;
|
||||
diag?: DiagLogger;
|
||||
trace?: TracerProvider;
|
||||
context?: ContextManager;
|
||||
metrics?: MeterProvider;
|
||||
propagation?: TextMapPropagator;
|
||||
};
|
||||
export {};
|
||||
//# sourceMappingURL=global-utils.d.ts.map
|
||||
Generated
Vendored
+64
@@ -0,0 +1,64 @@
|
||||
"use strict";
|
||||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.unregisterGlobal = exports.getGlobal = exports.registerGlobal = void 0;
|
||||
const platform_1 = require("../platform");
|
||||
const version_1 = require("../version");
|
||||
const semver_1 = require("./semver");
|
||||
const major = version_1.VERSION.split('.')[0];
|
||||
const GLOBAL_OPENTELEMETRY_API_KEY = Symbol.for(`opentelemetry.js.api.${major}`);
|
||||
const _global = platform_1._globalThis;
|
||||
function registerGlobal(type, instance, diag, allowOverride = false) {
|
||||
var _a;
|
||||
const api = (_global[GLOBAL_OPENTELEMETRY_API_KEY] = (_a = _global[GLOBAL_OPENTELEMETRY_API_KEY]) !== null && _a !== void 0 ? _a : {
|
||||
version: version_1.VERSION,
|
||||
});
|
||||
if (!allowOverride && api[type]) {
|
||||
// already registered an API of this type
|
||||
const err = new Error(`@opentelemetry/api: Attempted duplicate registration of API: ${type}`);
|
||||
diag.error(err.stack || err.message);
|
||||
return false;
|
||||
}
|
||||
if (api.version !== version_1.VERSION) {
|
||||
// All registered APIs must be of the same version exactly
|
||||
const err = new Error(`@opentelemetry/api: Registration of version v${api.version} for ${type} does not match previously registered API v${version_1.VERSION}`);
|
||||
diag.error(err.stack || err.message);
|
||||
return false;
|
||||
}
|
||||
api[type] = instance;
|
||||
diag.debug(`@opentelemetry/api: Registered a global for ${type} v${version_1.VERSION}.`);
|
||||
return true;
|
||||
}
|
||||
exports.registerGlobal = registerGlobal;
|
||||
function getGlobal(type) {
|
||||
var _a, _b;
|
||||
const globalVersion = (_a = _global[GLOBAL_OPENTELEMETRY_API_KEY]) === null || _a === void 0 ? void 0 : _a.version;
|
||||
if (!globalVersion || !(0, semver_1.isCompatible)(globalVersion)) {
|
||||
return;
|
||||
}
|
||||
return (_b = _global[GLOBAL_OPENTELEMETRY_API_KEY]) === null || _b === void 0 ? void 0 : _b[type];
|
||||
}
|
||||
exports.getGlobal = getGlobal;
|
||||
function unregisterGlobal(type, diag) {
|
||||
diag.debug(`@opentelemetry/api: Unregistering a global for ${type} v${version_1.VERSION}.`);
|
||||
const api = _global[GLOBAL_OPENTELEMETRY_API_KEY];
|
||||
if (api) {
|
||||
delete api[type];
|
||||
}
|
||||
}
|
||||
exports.unregisterGlobal = unregisterGlobal;
|
||||
//# sourceMappingURL=global-utils.js.map
|
||||
Generated
Vendored
+34
@@ -0,0 +1,34 @@
|
||||
/**
|
||||
* Create a function to test an API version to see if it is compatible with the provided ownVersion.
|
||||
*
|
||||
* The returned function has the following semantics:
|
||||
* - Exact match is always compatible
|
||||
* - Major versions must match exactly
|
||||
* - 1.x package cannot use global 2.x package
|
||||
* - 2.x package cannot use global 1.x package
|
||||
* - The minor version of the API module requesting access to the global API must be less than or equal to the minor version of this API
|
||||
* - 1.3 package may use 1.4 global because the later global contains all functions 1.3 expects
|
||||
* - 1.4 package may NOT use 1.3 global because it may try to call functions which don't exist on 1.3
|
||||
* - If the major version is 0, the minor version is treated as the major and the patch is treated as the minor
|
||||
* - Patch and build tag differences are not considered at this time
|
||||
*
|
||||
* @param ownVersion version which should be checked against
|
||||
*/
|
||||
export declare function _makeCompatibilityCheck(ownVersion: string): (globalVersion: string) => boolean;
|
||||
/**
|
||||
* Test an API version to see if it is compatible with this API.
|
||||
*
|
||||
* - Exact match is always compatible
|
||||
* - Major versions must match exactly
|
||||
* - 1.x package cannot use global 2.x package
|
||||
* - 2.x package cannot use global 1.x package
|
||||
* - The minor version of the API module requesting access to the global API must be less than or equal to the minor version of this API
|
||||
* - 1.3 package may use 1.4 global because the later global contains all functions 1.3 expects
|
||||
* - 1.4 package may NOT use 1.3 global because it may try to call functions which don't exist on 1.3
|
||||
* - If the major version is 0, the minor version is treated as the major and the patch is treated as the minor
|
||||
* - Patch and build tag differences are not considered at this time
|
||||
*
|
||||
* @param version version of the API requesting an instance of the global API
|
||||
*/
|
||||
export declare const isCompatible: (globalVersion: string) => boolean;
|
||||
//# sourceMappingURL=semver.d.ts.map
|
||||
+122
@@ -0,0 +1,122 @@
|
||||
"use strict";
|
||||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.isCompatible = exports._makeCompatibilityCheck = void 0;
|
||||
const version_1 = require("../version");
|
||||
const re = /^(\d+)\.(\d+)\.(\d+)(-(.+))?$/;
|
||||
/**
|
||||
* Create a function to test an API version to see if it is compatible with the provided ownVersion.
|
||||
*
|
||||
* The returned function has the following semantics:
|
||||
* - Exact match is always compatible
|
||||
* - Major versions must match exactly
|
||||
* - 1.x package cannot use global 2.x package
|
||||
* - 2.x package cannot use global 1.x package
|
||||
* - The minor version of the API module requesting access to the global API must be less than or equal to the minor version of this API
|
||||
* - 1.3 package may use 1.4 global because the later global contains all functions 1.3 expects
|
||||
* - 1.4 package may NOT use 1.3 global because it may try to call functions which don't exist on 1.3
|
||||
* - If the major version is 0, the minor version is treated as the major and the patch is treated as the minor
|
||||
* - Patch and build tag differences are not considered at this time
|
||||
*
|
||||
* @param ownVersion version which should be checked against
|
||||
*/
|
||||
function _makeCompatibilityCheck(ownVersion) {
|
||||
const acceptedVersions = new Set([ownVersion]);
|
||||
const rejectedVersions = new Set();
|
||||
const myVersionMatch = ownVersion.match(re);
|
||||
if (!myVersionMatch) {
|
||||
// we cannot guarantee compatibility so we always return noop
|
||||
return () => false;
|
||||
}
|
||||
const ownVersionParsed = {
|
||||
major: +myVersionMatch[1],
|
||||
minor: +myVersionMatch[2],
|
||||
patch: +myVersionMatch[3],
|
||||
prerelease: myVersionMatch[4],
|
||||
};
|
||||
// if ownVersion has a prerelease tag, versions must match exactly
|
||||
if (ownVersionParsed.prerelease != null) {
|
||||
return function isExactmatch(globalVersion) {
|
||||
return globalVersion === ownVersion;
|
||||
};
|
||||
}
|
||||
function _reject(v) {
|
||||
rejectedVersions.add(v);
|
||||
return false;
|
||||
}
|
||||
function _accept(v) {
|
||||
acceptedVersions.add(v);
|
||||
return true;
|
||||
}
|
||||
return function isCompatible(globalVersion) {
|
||||
if (acceptedVersions.has(globalVersion)) {
|
||||
return true;
|
||||
}
|
||||
if (rejectedVersions.has(globalVersion)) {
|
||||
return false;
|
||||
}
|
||||
const globalVersionMatch = globalVersion.match(re);
|
||||
if (!globalVersionMatch) {
|
||||
// cannot parse other version
|
||||
// we cannot guarantee compatibility so we always noop
|
||||
return _reject(globalVersion);
|
||||
}
|
||||
const globalVersionParsed = {
|
||||
major: +globalVersionMatch[1],
|
||||
minor: +globalVersionMatch[2],
|
||||
patch: +globalVersionMatch[3],
|
||||
prerelease: globalVersionMatch[4],
|
||||
};
|
||||
// if globalVersion has a prerelease tag, versions must match exactly
|
||||
if (globalVersionParsed.prerelease != null) {
|
||||
return _reject(globalVersion);
|
||||
}
|
||||
// major versions must match
|
||||
if (ownVersionParsed.major !== globalVersionParsed.major) {
|
||||
return _reject(globalVersion);
|
||||
}
|
||||
if (ownVersionParsed.major === 0) {
|
||||
if (ownVersionParsed.minor === globalVersionParsed.minor &&
|
||||
ownVersionParsed.patch <= globalVersionParsed.patch) {
|
||||
return _accept(globalVersion);
|
||||
}
|
||||
return _reject(globalVersion);
|
||||
}
|
||||
if (ownVersionParsed.minor <= globalVersionParsed.minor) {
|
||||
return _accept(globalVersion);
|
||||
}
|
||||
return _reject(globalVersion);
|
||||
};
|
||||
}
|
||||
exports._makeCompatibilityCheck = _makeCompatibilityCheck;
|
||||
/**
|
||||
* Test an API version to see if it is compatible with this API.
|
||||
*
|
||||
* - Exact match is always compatible
|
||||
* - Major versions must match exactly
|
||||
* - 1.x package cannot use global 2.x package
|
||||
* - 2.x package cannot use global 1.x package
|
||||
* - The minor version of the API module requesting access to the global API must be less than or equal to the minor version of this API
|
||||
* - 1.3 package may use 1.4 global because the later global contains all functions 1.3 expects
|
||||
* - 1.4 package may NOT use 1.3 global because it may try to call functions which don't exist on 1.3
|
||||
* - If the major version is 0, the minor version is treated as the major and the patch is treated as the minor
|
||||
* - Patch and build tag differences are not considered at this time
|
||||
*
|
||||
* @param version version of the API requesting an instance of the global API
|
||||
*/
|
||||
exports.isCompatible = _makeCompatibilityCheck(version_1.VERSION);
|
||||
//# sourceMappingURL=semver.js.map
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
import { MetricsAPI } from './api/metrics';
|
||||
/** Entrypoint for metrics API */
|
||||
export declare const metrics: MetricsAPI;
|
||||
//# sourceMappingURL=metrics-api.d.ts.map
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
"use strict";
|
||||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.metrics = void 0;
|
||||
// Split module-level variable definition into separate files to allow
|
||||
// tree-shaking on each api instance.
|
||||
const metrics_1 = require("./api/metrics");
|
||||
/** Entrypoint for metrics API */
|
||||
exports.metrics = metrics_1.MetricsAPI.getInstance();
|
||||
//# sourceMappingURL=metrics-api.js.map
|
||||
+110
@@ -0,0 +1,110 @@
|
||||
import { BatchObservableCallback, Counter, Gauge, Histogram, MetricAttributes, MetricOptions, Observable, ObservableCounter, ObservableGauge, ObservableUpDownCounter, UpDownCounter } from './Metric';
|
||||
/**
|
||||
* An interface describes additional metadata of a meter.
|
||||
*/
|
||||
export interface MeterOptions {
|
||||
/**
|
||||
* The schemaUrl of the meter or instrumentation library
|
||||
*/
|
||||
schemaUrl?: string;
|
||||
}
|
||||
/**
|
||||
* An interface to allow the recording metrics.
|
||||
*
|
||||
* {@link Metric}s are used for recording pre-defined aggregation (`Counter`),
|
||||
* or raw values (`Histogram`) in which the aggregation and attributes
|
||||
* for the exported metric are deferred.
|
||||
*/
|
||||
export interface Meter {
|
||||
/**
|
||||
* Creates and returns a new `Gauge`.
|
||||
* @param name the name of the metric.
|
||||
* @param [options] the metric options.
|
||||
*/
|
||||
createGauge<AttributesTypes extends MetricAttributes = MetricAttributes>(name: string, options?: MetricOptions): Gauge<AttributesTypes>;
|
||||
/**
|
||||
* Creates and returns a new `Histogram`.
|
||||
* @param name the name of the metric.
|
||||
* @param [options] the metric options.
|
||||
*/
|
||||
createHistogram<AttributesTypes extends MetricAttributes = MetricAttributes>(name: string, options?: MetricOptions): Histogram<AttributesTypes>;
|
||||
/**
|
||||
* Creates a new `Counter` metric. Generally, this kind of metric when the
|
||||
* value is a quantity, the sum is of primary interest, and the event count
|
||||
* and value distribution are not of primary interest.
|
||||
* @param name the name of the metric.
|
||||
* @param [options] the metric options.
|
||||
*/
|
||||
createCounter<AttributesTypes extends MetricAttributes = MetricAttributes>(name: string, options?: MetricOptions): Counter<AttributesTypes>;
|
||||
/**
|
||||
* Creates a new `UpDownCounter` metric. UpDownCounter is a synchronous
|
||||
* instrument and very similar to Counter except that Add(increment)
|
||||
* supports negative increments. It is generally useful for capturing changes
|
||||
* in an amount of resources used, or any quantity that rises and falls
|
||||
* during a request.
|
||||
* Example uses for UpDownCounter:
|
||||
* <ol>
|
||||
* <li> count the number of active requests. </li>
|
||||
* <li> count memory in use by instrumenting new and delete. </li>
|
||||
* <li> count queue size by instrumenting enqueue and dequeue. </li>
|
||||
* <li> count semaphore up and down operations. </li>
|
||||
* </ol>
|
||||
*
|
||||
* @param name the name of the metric.
|
||||
* @param [options] the metric options.
|
||||
*/
|
||||
createUpDownCounter<AttributesTypes extends MetricAttributes = MetricAttributes>(name: string, options?: MetricOptions): UpDownCounter<AttributesTypes>;
|
||||
/**
|
||||
* Creates a new `ObservableGauge` metric.
|
||||
*
|
||||
* The callback SHOULD be safe to be invoked concurrently.
|
||||
*
|
||||
* @param name the name of the metric.
|
||||
* @param [options] the metric options.
|
||||
*/
|
||||
createObservableGauge<AttributesTypes extends MetricAttributes = MetricAttributes>(name: string, options?: MetricOptions): ObservableGauge<AttributesTypes>;
|
||||
/**
|
||||
* Creates a new `ObservableCounter` metric.
|
||||
*
|
||||
* The callback SHOULD be safe to be invoked concurrently.
|
||||
*
|
||||
* @param name the name of the metric.
|
||||
* @param [options] the metric options.
|
||||
*/
|
||||
createObservableCounter<AttributesTypes extends MetricAttributes = MetricAttributes>(name: string, options?: MetricOptions): ObservableCounter<AttributesTypes>;
|
||||
/**
|
||||
* Creates a new `ObservableUpDownCounter` metric.
|
||||
*
|
||||
* The callback SHOULD be safe to be invoked concurrently.
|
||||
*
|
||||
* @param name the name of the metric.
|
||||
* @param [options] the metric options.
|
||||
*/
|
||||
createObservableUpDownCounter<AttributesTypes extends MetricAttributes = MetricAttributes>(name: string, options?: MetricOptions): ObservableUpDownCounter<AttributesTypes>;
|
||||
/**
|
||||
* Sets up a function that will be called whenever a metric collection is
|
||||
* initiated.
|
||||
*
|
||||
* If the function is already in the list of callbacks for this Observable,
|
||||
* the function is not added a second time.
|
||||
*
|
||||
* Only the associated observables can be observed in the callback.
|
||||
* Measurements of observables that are not associated observed in the
|
||||
* callback are dropped.
|
||||
*
|
||||
* @param callback the batch observable callback
|
||||
* @param observables the observables associated with this batch observable callback
|
||||
*/
|
||||
addBatchObservableCallback<AttributesTypes extends MetricAttributes = MetricAttributes>(callback: BatchObservableCallback<AttributesTypes>, observables: Observable<AttributesTypes>[]): void;
|
||||
/**
|
||||
* Removes a callback previously registered with {@link Meter.addBatchObservableCallback}.
|
||||
*
|
||||
* The callback to be removed is identified using a combination of the callback itself,
|
||||
* and the set of the observables associated with it.
|
||||
*
|
||||
* @param callback the batch observable callback
|
||||
* @param observables the observables associated with this batch observable callback
|
||||
*/
|
||||
removeBatchObservableCallback<AttributesTypes extends MetricAttributes = MetricAttributes>(callback: BatchObservableCallback<AttributesTypes>, observables: Observable<AttributesTypes>[]): void;
|
||||
}
|
||||
//# sourceMappingURL=Meter.d.ts.map
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
"use strict";
|
||||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
//# sourceMappingURL=Meter.js.map
|
||||
Generated
Vendored
+17
@@ -0,0 +1,17 @@
|
||||
import { Meter, MeterOptions } from './Meter';
|
||||
/**
|
||||
* A registry for creating named {@link Meter}s.
|
||||
*/
|
||||
export interface MeterProvider {
|
||||
/**
|
||||
* Returns a Meter, creating one if one with the given name, version, and
|
||||
* schemaUrl pair is not already created.
|
||||
*
|
||||
* @param name The name of the meter or instrumentation library.
|
||||
* @param version The version of the meter or instrumentation library.
|
||||
* @param options The options of the meter or instrumentation library.
|
||||
* @returns Meter A Meter with the given name and version
|
||||
*/
|
||||
getMeter(name: string, version?: string, options?: MeterOptions): Meter;
|
||||
}
|
||||
//# sourceMappingURL=MeterProvider.d.ts.map
|
||||
Generated
Vendored
+18
@@ -0,0 +1,18 @@
|
||||
"use strict";
|
||||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
//# sourceMappingURL=MeterProvider.js.map
|
||||
+115
@@ -0,0 +1,115 @@
|
||||
import { Attributes, AttributeValue } from '../common/Attributes';
|
||||
import { Context } from '../context/types';
|
||||
import { BatchObservableResult, ObservableResult } from './ObservableResult';
|
||||
/**
|
||||
* Advisory options influencing aggregation configuration parameters.
|
||||
* @experimental
|
||||
*/
|
||||
export interface MetricAdvice {
|
||||
/**
|
||||
* Hint the explicit bucket boundaries for SDK if the metric is been
|
||||
* aggregated with a HistogramAggregator.
|
||||
*/
|
||||
explicitBucketBoundaries?: number[];
|
||||
}
|
||||
/**
|
||||
* Options needed for metric creation
|
||||
*/
|
||||
export interface MetricOptions {
|
||||
/**
|
||||
* The description of the Metric.
|
||||
* @default ''
|
||||
*/
|
||||
description?: string;
|
||||
/**
|
||||
* The unit of the Metric values.
|
||||
* @default ''
|
||||
*/
|
||||
unit?: string;
|
||||
/**
|
||||
* Indicates the type of the recorded value.
|
||||
* @default {@link ValueType.DOUBLE}
|
||||
*/
|
||||
valueType?: ValueType;
|
||||
/**
|
||||
* The advice influencing aggregation configuration parameters.
|
||||
* @experimental
|
||||
*/
|
||||
advice?: MetricAdvice;
|
||||
}
|
||||
/** The Type of value. It describes how the data is reported. */
|
||||
export declare enum ValueType {
|
||||
INT = 0,
|
||||
DOUBLE = 1
|
||||
}
|
||||
/**
|
||||
* Counter is the most common synchronous instrument. This instrument supports
|
||||
* an `Add(increment)` function for reporting a sum, and is restricted to
|
||||
* non-negative increments. The default aggregation is Sum, as for any additive
|
||||
* instrument.
|
||||
*
|
||||
* Example uses for Counter:
|
||||
* <ol>
|
||||
* <li> count the number of bytes received. </li>
|
||||
* <li> count the number of requests completed. </li>
|
||||
* <li> count the number of accounts created. </li>
|
||||
* <li> count the number of checkpoints run. </li>
|
||||
* <li> count the number of 5xx errors. </li>
|
||||
* <ol>
|
||||
*/
|
||||
export interface Counter<AttributesTypes extends MetricAttributes = MetricAttributes> {
|
||||
/**
|
||||
* Increment value of counter by the input. Inputs must not be negative.
|
||||
*/
|
||||
add(value: number, attributes?: AttributesTypes, context?: Context): void;
|
||||
}
|
||||
export interface UpDownCounter<AttributesTypes extends MetricAttributes = MetricAttributes> {
|
||||
/**
|
||||
* Increment value of counter by the input. Inputs may be negative.
|
||||
*/
|
||||
add(value: number, attributes?: AttributesTypes, context?: Context): void;
|
||||
}
|
||||
export interface Gauge<AttributesTypes extends MetricAttributes = MetricAttributes> {
|
||||
/**
|
||||
* Records a measurement.
|
||||
*/
|
||||
record(value: number, attributes?: AttributesTypes, context?: Context): void;
|
||||
}
|
||||
export interface Histogram<AttributesTypes extends MetricAttributes = MetricAttributes> {
|
||||
/**
|
||||
* Records a measurement. Value of the measurement must not be negative.
|
||||
*/
|
||||
record(value: number, attributes?: AttributesTypes, context?: Context): void;
|
||||
}
|
||||
/**
|
||||
* @deprecated please use {@link Attributes}
|
||||
*/
|
||||
export declare type MetricAttributes = Attributes;
|
||||
/**
|
||||
* @deprecated please use {@link AttributeValue}
|
||||
*/
|
||||
export declare type MetricAttributeValue = AttributeValue;
|
||||
/**
|
||||
* The observable callback for Observable instruments.
|
||||
*/
|
||||
export declare type ObservableCallback<AttributesTypes extends MetricAttributes = MetricAttributes> = (observableResult: ObservableResult<AttributesTypes>) => void | Promise<void>;
|
||||
/**
|
||||
* The observable callback for a batch of Observable instruments.
|
||||
*/
|
||||
export declare type BatchObservableCallback<AttributesTypes extends MetricAttributes = MetricAttributes> = (observableResult: BatchObservableResult<AttributesTypes>) => void | Promise<void>;
|
||||
export interface Observable<AttributesTypes extends MetricAttributes = MetricAttributes> {
|
||||
/**
|
||||
* Sets up a function that will be called whenever a metric collection is initiated.
|
||||
*
|
||||
* If the function is already in the list of callbacks for this Observable, the function is not added a second time.
|
||||
*/
|
||||
addCallback(callback: ObservableCallback<AttributesTypes>): void;
|
||||
/**
|
||||
* Removes a callback previously registered with {@link Observable.addCallback}.
|
||||
*/
|
||||
removeCallback(callback: ObservableCallback<AttributesTypes>): void;
|
||||
}
|
||||
export declare type ObservableCounter<AttributesTypes extends MetricAttributes = MetricAttributes> = Observable<AttributesTypes>;
|
||||
export declare type ObservableUpDownCounter<AttributesTypes extends MetricAttributes = MetricAttributes> = Observable<AttributesTypes>;
|
||||
export declare type ObservableGauge<AttributesTypes extends MetricAttributes = MetricAttributes> = Observable<AttributesTypes>;
|
||||
//# sourceMappingURL=Metric.d.ts.map
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
"use strict";
|
||||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ValueType = void 0;
|
||||
/** The Type of value. It describes how the data is reported. */
|
||||
var ValueType;
|
||||
(function (ValueType) {
|
||||
ValueType[ValueType["INT"] = 0] = "INT";
|
||||
ValueType[ValueType["DOUBLE"] = 1] = "DOUBLE";
|
||||
})(ValueType = exports.ValueType || (exports.ValueType = {}));
|
||||
//# sourceMappingURL=Metric.js.map
|
||||
Generated
Vendored
+82
@@ -0,0 +1,82 @@
|
||||
import { Meter } from './Meter';
|
||||
import { BatchObservableCallback, Counter, Gauge, Histogram, MetricAttributes, MetricOptions, Observable, ObservableCallback, ObservableCounter, ObservableGauge, ObservableUpDownCounter, UpDownCounter } from './Metric';
|
||||
/**
|
||||
* NoopMeter is a noop implementation of the {@link Meter} interface. It reuses
|
||||
* constant NoopMetrics for all of its methods.
|
||||
*/
|
||||
export declare class NoopMeter implements Meter {
|
||||
constructor();
|
||||
/**
|
||||
* @see {@link Meter.createGauge}
|
||||
*/
|
||||
createGauge(_name: string, _options?: MetricOptions): Gauge;
|
||||
/**
|
||||
* @see {@link Meter.createHistogram}
|
||||
*/
|
||||
createHistogram(_name: string, _options?: MetricOptions): Histogram;
|
||||
/**
|
||||
* @see {@link Meter.createCounter}
|
||||
*/
|
||||
createCounter(_name: string, _options?: MetricOptions): Counter;
|
||||
/**
|
||||
* @see {@link Meter.createUpDownCounter}
|
||||
*/
|
||||
createUpDownCounter(_name: string, _options?: MetricOptions): UpDownCounter;
|
||||
/**
|
||||
* @see {@link Meter.createObservableGauge}
|
||||
*/
|
||||
createObservableGauge(_name: string, _options?: MetricOptions): ObservableGauge;
|
||||
/**
|
||||
* @see {@link Meter.createObservableCounter}
|
||||
*/
|
||||
createObservableCounter(_name: string, _options?: MetricOptions): ObservableCounter;
|
||||
/**
|
||||
* @see {@link Meter.createObservableUpDownCounter}
|
||||
*/
|
||||
createObservableUpDownCounter(_name: string, _options?: MetricOptions): ObservableUpDownCounter;
|
||||
/**
|
||||
* @see {@link Meter.addBatchObservableCallback}
|
||||
*/
|
||||
addBatchObservableCallback(_callback: BatchObservableCallback, _observables: Observable[]): void;
|
||||
/**
|
||||
* @see {@link Meter.removeBatchObservableCallback}
|
||||
*/
|
||||
removeBatchObservableCallback(_callback: BatchObservableCallback): void;
|
||||
}
|
||||
export declare class NoopMetric {
|
||||
}
|
||||
export declare class NoopCounterMetric extends NoopMetric implements Counter {
|
||||
add(_value: number, _attributes: MetricAttributes): void;
|
||||
}
|
||||
export declare class NoopUpDownCounterMetric extends NoopMetric implements UpDownCounter {
|
||||
add(_value: number, _attributes: MetricAttributes): void;
|
||||
}
|
||||
export declare class NoopGaugeMetric extends NoopMetric implements Gauge {
|
||||
record(_value: number, _attributes: MetricAttributes): void;
|
||||
}
|
||||
export declare class NoopHistogramMetric extends NoopMetric implements Histogram {
|
||||
record(_value: number, _attributes: MetricAttributes): void;
|
||||
}
|
||||
export declare class NoopObservableMetric {
|
||||
addCallback(_callback: ObservableCallback): void;
|
||||
removeCallback(_callback: ObservableCallback): void;
|
||||
}
|
||||
export declare class NoopObservableCounterMetric extends NoopObservableMetric implements ObservableCounter {
|
||||
}
|
||||
export declare class NoopObservableGaugeMetric extends NoopObservableMetric implements ObservableGauge {
|
||||
}
|
||||
export declare class NoopObservableUpDownCounterMetric extends NoopObservableMetric implements ObservableUpDownCounter {
|
||||
}
|
||||
export declare const NOOP_METER: NoopMeter;
|
||||
export declare const NOOP_COUNTER_METRIC: NoopCounterMetric;
|
||||
export declare const NOOP_GAUGE_METRIC: NoopGaugeMetric;
|
||||
export declare const NOOP_HISTOGRAM_METRIC: NoopHistogramMetric;
|
||||
export declare const NOOP_UP_DOWN_COUNTER_METRIC: NoopUpDownCounterMetric;
|
||||
export declare const NOOP_OBSERVABLE_COUNTER_METRIC: NoopObservableCounterMetric;
|
||||
export declare const NOOP_OBSERVABLE_GAUGE_METRIC: NoopObservableGaugeMetric;
|
||||
export declare const NOOP_OBSERVABLE_UP_DOWN_COUNTER_METRIC: NoopObservableUpDownCounterMetric;
|
||||
/**
|
||||
* Create a no-op Meter
|
||||
*/
|
||||
export declare function createNoopMeter(): Meter;
|
||||
//# sourceMappingURL=NoopMeter.d.ts.map
|
||||
Generated
Vendored
+127
@@ -0,0 +1,127 @@
|
||||
"use strict";
|
||||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.createNoopMeter = exports.NOOP_OBSERVABLE_UP_DOWN_COUNTER_METRIC = exports.NOOP_OBSERVABLE_GAUGE_METRIC = exports.NOOP_OBSERVABLE_COUNTER_METRIC = exports.NOOP_UP_DOWN_COUNTER_METRIC = exports.NOOP_HISTOGRAM_METRIC = exports.NOOP_GAUGE_METRIC = exports.NOOP_COUNTER_METRIC = exports.NOOP_METER = exports.NoopObservableUpDownCounterMetric = exports.NoopObservableGaugeMetric = exports.NoopObservableCounterMetric = exports.NoopObservableMetric = exports.NoopHistogramMetric = exports.NoopGaugeMetric = exports.NoopUpDownCounterMetric = exports.NoopCounterMetric = exports.NoopMetric = exports.NoopMeter = void 0;
|
||||
/**
|
||||
* NoopMeter is a noop implementation of the {@link Meter} interface. It reuses
|
||||
* constant NoopMetrics for all of its methods.
|
||||
*/
|
||||
class NoopMeter {
|
||||
constructor() { }
|
||||
/**
|
||||
* @see {@link Meter.createGauge}
|
||||
*/
|
||||
createGauge(_name, _options) {
|
||||
return exports.NOOP_GAUGE_METRIC;
|
||||
}
|
||||
/**
|
||||
* @see {@link Meter.createHistogram}
|
||||
*/
|
||||
createHistogram(_name, _options) {
|
||||
return exports.NOOP_HISTOGRAM_METRIC;
|
||||
}
|
||||
/**
|
||||
* @see {@link Meter.createCounter}
|
||||
*/
|
||||
createCounter(_name, _options) {
|
||||
return exports.NOOP_COUNTER_METRIC;
|
||||
}
|
||||
/**
|
||||
* @see {@link Meter.createUpDownCounter}
|
||||
*/
|
||||
createUpDownCounter(_name, _options) {
|
||||
return exports.NOOP_UP_DOWN_COUNTER_METRIC;
|
||||
}
|
||||
/**
|
||||
* @see {@link Meter.createObservableGauge}
|
||||
*/
|
||||
createObservableGauge(_name, _options) {
|
||||
return exports.NOOP_OBSERVABLE_GAUGE_METRIC;
|
||||
}
|
||||
/**
|
||||
* @see {@link Meter.createObservableCounter}
|
||||
*/
|
||||
createObservableCounter(_name, _options) {
|
||||
return exports.NOOP_OBSERVABLE_COUNTER_METRIC;
|
||||
}
|
||||
/**
|
||||
* @see {@link Meter.createObservableUpDownCounter}
|
||||
*/
|
||||
createObservableUpDownCounter(_name, _options) {
|
||||
return exports.NOOP_OBSERVABLE_UP_DOWN_COUNTER_METRIC;
|
||||
}
|
||||
/**
|
||||
* @see {@link Meter.addBatchObservableCallback}
|
||||
*/
|
||||
addBatchObservableCallback(_callback, _observables) { }
|
||||
/**
|
||||
* @see {@link Meter.removeBatchObservableCallback}
|
||||
*/
|
||||
removeBatchObservableCallback(_callback) { }
|
||||
}
|
||||
exports.NoopMeter = NoopMeter;
|
||||
class NoopMetric {
|
||||
}
|
||||
exports.NoopMetric = NoopMetric;
|
||||
class NoopCounterMetric extends NoopMetric {
|
||||
add(_value, _attributes) { }
|
||||
}
|
||||
exports.NoopCounterMetric = NoopCounterMetric;
|
||||
class NoopUpDownCounterMetric extends NoopMetric {
|
||||
add(_value, _attributes) { }
|
||||
}
|
||||
exports.NoopUpDownCounterMetric = NoopUpDownCounterMetric;
|
||||
class NoopGaugeMetric extends NoopMetric {
|
||||
record(_value, _attributes) { }
|
||||
}
|
||||
exports.NoopGaugeMetric = NoopGaugeMetric;
|
||||
class NoopHistogramMetric extends NoopMetric {
|
||||
record(_value, _attributes) { }
|
||||
}
|
||||
exports.NoopHistogramMetric = NoopHistogramMetric;
|
||||
class NoopObservableMetric {
|
||||
addCallback(_callback) { }
|
||||
removeCallback(_callback) { }
|
||||
}
|
||||
exports.NoopObservableMetric = NoopObservableMetric;
|
||||
class NoopObservableCounterMetric extends NoopObservableMetric {
|
||||
}
|
||||
exports.NoopObservableCounterMetric = NoopObservableCounterMetric;
|
||||
class NoopObservableGaugeMetric extends NoopObservableMetric {
|
||||
}
|
||||
exports.NoopObservableGaugeMetric = NoopObservableGaugeMetric;
|
||||
class NoopObservableUpDownCounterMetric extends NoopObservableMetric {
|
||||
}
|
||||
exports.NoopObservableUpDownCounterMetric = NoopObservableUpDownCounterMetric;
|
||||
exports.NOOP_METER = new NoopMeter();
|
||||
// Synchronous instruments
|
||||
exports.NOOP_COUNTER_METRIC = new NoopCounterMetric();
|
||||
exports.NOOP_GAUGE_METRIC = new NoopGaugeMetric();
|
||||
exports.NOOP_HISTOGRAM_METRIC = new NoopHistogramMetric();
|
||||
exports.NOOP_UP_DOWN_COUNTER_METRIC = new NoopUpDownCounterMetric();
|
||||
// Asynchronous instruments
|
||||
exports.NOOP_OBSERVABLE_COUNTER_METRIC = new NoopObservableCounterMetric();
|
||||
exports.NOOP_OBSERVABLE_GAUGE_METRIC = new NoopObservableGaugeMetric();
|
||||
exports.NOOP_OBSERVABLE_UP_DOWN_COUNTER_METRIC = new NoopObservableUpDownCounterMetric();
|
||||
/**
|
||||
* Create a no-op Meter
|
||||
*/
|
||||
function createNoopMeter() {
|
||||
return exports.NOOP_METER;
|
||||
}
|
||||
exports.createNoopMeter = createNoopMeter;
|
||||
//# sourceMappingURL=NoopMeter.js.map
|
||||
Generated
Vendored
+11
@@ -0,0 +1,11 @@
|
||||
import { Meter, MeterOptions } from './Meter';
|
||||
import { MeterProvider } from './MeterProvider';
|
||||
/**
|
||||
* An implementation of the {@link MeterProvider} which returns an impotent Meter
|
||||
* for all calls to `getMeter`
|
||||
*/
|
||||
export declare class NoopMeterProvider implements MeterProvider {
|
||||
getMeter(_name: string, _version?: string, _options?: MeterOptions): Meter;
|
||||
}
|
||||
export declare const NOOP_METER_PROVIDER: NoopMeterProvider;
|
||||
//# sourceMappingURL=NoopMeterProvider.d.ts.map
|
||||
Generated
Vendored
+31
@@ -0,0 +1,31 @@
|
||||
"use strict";
|
||||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.NOOP_METER_PROVIDER = exports.NoopMeterProvider = void 0;
|
||||
const NoopMeter_1 = require("./NoopMeter");
|
||||
/**
|
||||
* An implementation of the {@link MeterProvider} which returns an impotent Meter
|
||||
* for all calls to `getMeter`
|
||||
*/
|
||||
class NoopMeterProvider {
|
||||
getMeter(_name, _version, _options) {
|
||||
return NoopMeter_1.NOOP_METER;
|
||||
}
|
||||
}
|
||||
exports.NoopMeterProvider = NoopMeterProvider;
|
||||
exports.NOOP_METER_PROVIDER = new NoopMeterProvider();
|
||||
//# sourceMappingURL=NoopMeterProvider.js.map
|
||||
Generated
Vendored
+31
@@ -0,0 +1,31 @@
|
||||
import { MetricAttributes, Observable } from './Metric';
|
||||
/**
|
||||
* Interface that is being used in callback function for Observable Metric.
|
||||
*/
|
||||
export interface ObservableResult<AttributesTypes extends MetricAttributes = MetricAttributes> {
|
||||
/**
|
||||
* Observe a measurement of the value associated with the given attributes.
|
||||
*
|
||||
* @param value The value to be observed.
|
||||
* @param attributes The attributes associated with the value. If more than
|
||||
* one values associated with the same attributes values, SDK may pick the
|
||||
* last one or simply drop the entire observable result.
|
||||
*/
|
||||
observe(this: ObservableResult<AttributesTypes>, value: number, attributes?: AttributesTypes): void;
|
||||
}
|
||||
/**
|
||||
* Interface that is being used in batch observable callback function.
|
||||
*/
|
||||
export interface BatchObservableResult<AttributesTypes extends MetricAttributes = MetricAttributes> {
|
||||
/**
|
||||
* Observe a measurement of the value associated with the given attributes.
|
||||
*
|
||||
* @param metric The observable metric to be observed.
|
||||
* @param value The value to be observed.
|
||||
* @param attributes The attributes associated with the value. If more than
|
||||
* one values associated with the same attributes values, SDK may pick the
|
||||
* last one or simply drop the entire observable result.
|
||||
*/
|
||||
observe(this: BatchObservableResult<AttributesTypes>, metric: Observable<AttributesTypes>, value: number, attributes?: AttributesTypes): void;
|
||||
}
|
||||
//# sourceMappingURL=ObservableResult.d.ts.map
|
||||
Generated
Vendored
+18
@@ -0,0 +1,18 @@
|
||||
"use strict";
|
||||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
//# sourceMappingURL=ObservableResult.js.map
|
||||
Generated
Vendored
+10
@@ -0,0 +1,10 @@
|
||||
/**
|
||||
* - globalThis (New standard)
|
||||
* - self (Will return the current window instance for supported browsers)
|
||||
* - window (fallback for older browser implementations)
|
||||
* - global (NodeJS implementation)
|
||||
* - <object> (When all else fails)
|
||||
*/
|
||||
/** only globals that common to node and browsers are allowed */
|
||||
export declare const _globalThis: typeof globalThis;
|
||||
//# sourceMappingURL=globalThis.d.ts.map
|
||||
Generated
Vendored
+38
@@ -0,0 +1,38 @@
|
||||
"use strict";
|
||||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports._globalThis = void 0;
|
||||
// Updates to this file should also be replicated to @opentelemetry/core too.
|
||||
/**
|
||||
* - globalThis (New standard)
|
||||
* - self (Will return the current window instance for supported browsers)
|
||||
* - window (fallback for older browser implementations)
|
||||
* - global (NodeJS implementation)
|
||||
* - <object> (When all else fails)
|
||||
*/
|
||||
/** only globals that common to node and browsers are allowed */
|
||||
// eslint-disable-next-line node/no-unsupported-features/es-builtins, no-undef
|
||||
exports._globalThis = typeof globalThis === 'object'
|
||||
? globalThis
|
||||
: typeof self === 'object'
|
||||
? self
|
||||
: typeof window === 'object'
|
||||
? window
|
||||
: typeof global === 'object'
|
||||
? global
|
||||
: {};
|
||||
//# sourceMappingURL=globalThis.js.map
|
||||
Generated
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
export * from './globalThis';
|
||||
//# sourceMappingURL=index.d.ts.map
|
||||
Generated
Vendored
+29
@@ -0,0 +1,29 @@
|
||||
"use strict";
|
||||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
||||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
__exportStar(require("./globalThis"), exports);
|
||||
//# sourceMappingURL=index.js.map
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
export * from './node';
|
||||
//# sourceMappingURL=index.d.ts.map
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
"use strict";
|
||||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
||||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
__exportStar(require("./node"), exports);
|
||||
//# sourceMappingURL=index.js.map
|
||||
Generated
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
/** only globals that common to node and browsers are allowed */
|
||||
export declare const _globalThis: typeof globalThis;
|
||||
//# sourceMappingURL=globalThis.d.ts.map
|
||||
Generated
Vendored
+22
@@ -0,0 +1,22 @@
|
||||
"use strict";
|
||||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports._globalThis = void 0;
|
||||
/** only globals that common to node and browsers are allowed */
|
||||
// eslint-disable-next-line node/no-unsupported-features/es-builtins
|
||||
exports._globalThis = typeof globalThis === 'object' ? globalThis : global;
|
||||
//# sourceMappingURL=globalThis.js.map
|
||||
Generated
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
export * from './globalThis';
|
||||
//# sourceMappingURL=index.d.ts.map
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user