rian 0.0.2-alpha.1 → 0.0.2-alpha.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +10 -8
- package/index.js +74 -56
- package/index.mjs +55 -57
- package/package.json +2 -6
- package/tracecontext.d.ts +0 -1
- package/tracecontext.js +0 -7
- package/tracecontext.mjs +0 -5
package/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Traceparent } from '
|
|
1
|
+
import { Traceparent } from 'tctx';
|
|
2
2
|
|
|
3
3
|
declare type Span = {
|
|
4
4
|
name: string;
|
|
@@ -6,15 +6,15 @@ declare type Span = {
|
|
|
6
6
|
parent?: Traceparent;
|
|
7
7
|
start: number;
|
|
8
8
|
end: number;
|
|
9
|
-
|
|
9
|
+
context: Context;
|
|
10
10
|
};
|
|
11
11
|
declare type Collector = (spans: ReadonlySet<Span>) => any;
|
|
12
|
-
declare type
|
|
13
|
-
[property: string]:
|
|
12
|
+
declare type Context = {
|
|
13
|
+
[property: string]: any;
|
|
14
14
|
};
|
|
15
15
|
declare type Options = {
|
|
16
16
|
collector: Collector;
|
|
17
|
-
traceparent?:
|
|
17
|
+
traceparent?: string;
|
|
18
18
|
};
|
|
19
19
|
declare type OmitScopeParam<T extends unknown[]> = T extends [] ? [] : T extends [infer H, ...infer R] ? H extends Scope ? OmitScopeParam<R> : [H, ...OmitScopeParam<R>] : T;
|
|
20
20
|
interface CallableScope extends Scope {
|
|
@@ -23,8 +23,10 @@ interface CallableScope extends Scope {
|
|
|
23
23
|
interface Scope {
|
|
24
24
|
traceparent: Traceparent;
|
|
25
25
|
fork(name: string, traceparent?: Traceparent): CallableScope;
|
|
26
|
-
measure<Fn extends (...args: any[]) => any, Params extends Parameters<Fn>>(name: string, fn: Fn,
|
|
27
|
-
|
|
26
|
+
measure<Fn extends (...args: any[]) => any, Params extends Parameters<Fn>>(name: string, fn: Fn, // TODO Fix types here
|
|
27
|
+
...args: OmitScopeParam<Params>): ReturnType<Fn>;
|
|
28
|
+
set_context(contextFn: (context: Context) => Context): void;
|
|
29
|
+
set_context(context: Context): void;
|
|
28
30
|
end(): void;
|
|
29
31
|
}
|
|
30
32
|
interface Tracer extends Scope {
|
|
@@ -32,4 +34,4 @@ interface Tracer extends Scope {
|
|
|
32
34
|
}
|
|
33
35
|
declare const create: (name: string, options: Options) => Tracer;
|
|
34
36
|
|
|
35
|
-
export {
|
|
37
|
+
export { Collector, Context, Options, Scope, Span, Tracer, create };
|
package/index.js
CHANGED
|
@@ -1,75 +1,93 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
const tctx = require('tctx');
|
|
4
|
+
|
|
5
|
+
function _interopNamespace(e) {
|
|
6
|
+
if (e && e.__esModule) return e;
|
|
7
|
+
const n = Object.create(null);
|
|
8
|
+
if (e) {
|
|
9
|
+
for (const k in e) {
|
|
10
|
+
if (k !== 'default') {
|
|
11
|
+
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
12
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () { return e[k]; }
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
n["default"] = e;
|
|
20
|
+
return n;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const tctx__namespace = /*#__PURE__*/_interopNamespace(tctx);
|
|
24
|
+
|
|
6
25
|
const measure = (cb, scope, promises) => {
|
|
7
26
|
const set_error = (error) => {
|
|
8
|
-
scope.
|
|
27
|
+
scope.set_context({
|
|
9
28
|
error,
|
|
10
29
|
});
|
|
11
30
|
};
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
31
|
+
return (...args) => {
|
|
32
|
+
try {
|
|
33
|
+
var r = cb(...args, scope), is_promise = r instanceof Promise;
|
|
34
|
+
if (is_promise)
|
|
35
|
+
promises.push(r.catch(set_error).finally(() => scope.end()));
|
|
36
|
+
return r;
|
|
37
|
+
}
|
|
38
|
+
catch (e) {
|
|
39
|
+
set_error(e);
|
|
40
|
+
throw e;
|
|
41
|
+
}
|
|
42
|
+
finally {
|
|
43
|
+
if (is_promise !== true)
|
|
44
|
+
scope.end();
|
|
45
|
+
}
|
|
46
|
+
};
|
|
25
47
|
};
|
|
26
48
|
const create = (name, options) => {
|
|
27
49
|
const spans = new Set();
|
|
28
50
|
const promises = [];
|
|
29
|
-
const
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
const start =
|
|
51
|
+
const span = (name, parent) => {
|
|
52
|
+
const id = parent ? parent.child() : tctx__namespace.make(true);
|
|
53
|
+
let context = {};
|
|
54
|
+
const start = Date.now();
|
|
33
55
|
let ended = false;
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
return measure(() => cb(...args, scope), scope, promises);
|
|
44
|
-
},
|
|
45
|
-
set_attributes(attr) {
|
|
46
|
-
Object.assign(attributes, attr);
|
|
47
|
-
},
|
|
48
|
-
end() {
|
|
49
|
-
if (ended)
|
|
50
|
-
return void 0;
|
|
51
|
-
spans.add({
|
|
52
|
-
id: me,
|
|
53
|
-
parent,
|
|
54
|
-
start,
|
|
55
|
-
end: performance.now(),
|
|
56
|
-
name,
|
|
57
|
-
attributes,
|
|
58
|
-
});
|
|
59
|
-
ended = true;
|
|
60
|
-
},
|
|
56
|
+
// @ts-ignore
|
|
57
|
+
const $ = (cb) => measure(cb, $, promises)();
|
|
58
|
+
$.traceparent = id;
|
|
59
|
+
$.fork = (name) => span(name, id);
|
|
60
|
+
$.measure = (name, cb, ...args) => measure(cb, span(name, id), promises)(...args);
|
|
61
|
+
$.set_context = (ctx) => {
|
|
62
|
+
if (typeof ctx === 'function')
|
|
63
|
+
return void (context = ctx(context));
|
|
64
|
+
Object.assign(context, ctx);
|
|
61
65
|
};
|
|
62
|
-
|
|
66
|
+
$.end = () => {
|
|
67
|
+
if (ended)
|
|
68
|
+
return void 0;
|
|
69
|
+
spans.add({
|
|
70
|
+
id,
|
|
71
|
+
parent,
|
|
72
|
+
start,
|
|
73
|
+
end: Date.now(),
|
|
74
|
+
name,
|
|
75
|
+
context,
|
|
76
|
+
});
|
|
77
|
+
ended = true;
|
|
78
|
+
};
|
|
79
|
+
return $;
|
|
63
80
|
};
|
|
64
|
-
const
|
|
65
|
-
?
|
|
66
|
-
:
|
|
67
|
-
const meEnd =
|
|
68
|
-
|
|
69
|
-
await Promise.all(promises);
|
|
81
|
+
const root = span(name, typeof options.traceparent === 'string'
|
|
82
|
+
? tctx__namespace.parse(options.traceparent)
|
|
83
|
+
: undefined);
|
|
84
|
+
const meEnd = root.end.bind(root);
|
|
85
|
+
root.end = async () => {
|
|
70
86
|
meEnd();
|
|
87
|
+
await Promise.all(promises);
|
|
71
88
|
return options.collector(spans);
|
|
72
89
|
};
|
|
73
|
-
return
|
|
90
|
+
return root;
|
|
74
91
|
};
|
|
92
|
+
|
|
75
93
|
exports.create = create;
|
package/index.mjs
CHANGED
|
@@ -1,73 +1,71 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const tracecontext_1 = require("rian/tracecontext");
|
|
1
|
+
import * as tctx from 'tctx';
|
|
2
|
+
|
|
4
3
|
const measure = (cb, scope, promises) => {
|
|
5
4
|
const set_error = (error) => {
|
|
6
|
-
scope.
|
|
5
|
+
scope.set_context({
|
|
7
6
|
error,
|
|
8
7
|
});
|
|
9
8
|
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
9
|
+
return (...args) => {
|
|
10
|
+
try {
|
|
11
|
+
var r = cb(...args, scope), is_promise = r instanceof Promise;
|
|
12
|
+
if (is_promise)
|
|
13
|
+
promises.push(r.catch(set_error).finally(() => scope.end()));
|
|
14
|
+
return r;
|
|
15
|
+
}
|
|
16
|
+
catch (e) {
|
|
17
|
+
set_error(e);
|
|
18
|
+
throw e;
|
|
19
|
+
}
|
|
20
|
+
finally {
|
|
21
|
+
if (is_promise !== true)
|
|
22
|
+
scope.end();
|
|
23
|
+
}
|
|
24
|
+
};
|
|
23
25
|
};
|
|
24
26
|
const create = (name, options) => {
|
|
25
27
|
const spans = new Set();
|
|
26
28
|
const promises = [];
|
|
27
|
-
const
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
const start =
|
|
29
|
+
const span = (name, parent) => {
|
|
30
|
+
const id = parent ? parent.child() : tctx.make(true);
|
|
31
|
+
let context = {};
|
|
32
|
+
const start = Date.now();
|
|
31
33
|
let ended = false;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
name,
|
|
55
|
-
attributes,
|
|
56
|
-
});
|
|
57
|
-
ended = true;
|
|
58
|
-
},
|
|
34
|
+
// @ts-ignore
|
|
35
|
+
const $ = (cb) => measure(cb, $, promises)();
|
|
36
|
+
$.traceparent = id;
|
|
37
|
+
$.fork = (name) => span(name, id);
|
|
38
|
+
$.measure = (name, cb, ...args) => measure(cb, span(name, id), promises)(...args);
|
|
39
|
+
$.set_context = (ctx) => {
|
|
40
|
+
if (typeof ctx === 'function')
|
|
41
|
+
return void (context = ctx(context));
|
|
42
|
+
Object.assign(context, ctx);
|
|
43
|
+
};
|
|
44
|
+
$.end = () => {
|
|
45
|
+
if (ended)
|
|
46
|
+
return void 0;
|
|
47
|
+
spans.add({
|
|
48
|
+
id,
|
|
49
|
+
parent,
|
|
50
|
+
start,
|
|
51
|
+
end: Date.now(),
|
|
52
|
+
name,
|
|
53
|
+
context,
|
|
54
|
+
});
|
|
55
|
+
ended = true;
|
|
59
56
|
};
|
|
60
|
-
return
|
|
57
|
+
return $;
|
|
61
58
|
};
|
|
62
|
-
const
|
|
63
|
-
?
|
|
64
|
-
:
|
|
65
|
-
const meEnd =
|
|
66
|
-
|
|
67
|
-
await Promise.all(promises);
|
|
59
|
+
const root = span(name, typeof options.traceparent === 'string'
|
|
60
|
+
? tctx.parse(options.traceparent)
|
|
61
|
+
: undefined);
|
|
62
|
+
const meEnd = root.end.bind(root);
|
|
63
|
+
root.end = async () => {
|
|
68
64
|
meEnd();
|
|
65
|
+
await Promise.all(promises);
|
|
69
66
|
return options.collector(spans);
|
|
70
67
|
};
|
|
71
|
-
return
|
|
68
|
+
return root;
|
|
72
69
|
};
|
|
73
|
-
|
|
70
|
+
|
|
71
|
+
export { create };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rian",
|
|
3
|
-
"version": "0.0.2-alpha.
|
|
3
|
+
"version": "0.0.2-alpha.10",
|
|
4
4
|
"description": "A tracer for the edge",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"TODO"
|
|
@@ -19,10 +19,6 @@
|
|
|
19
19
|
"import": "./index.mjs",
|
|
20
20
|
"require": "./index.js"
|
|
21
21
|
},
|
|
22
|
-
"./tracecontext": {
|
|
23
|
-
"import": "./tracecontext.mjs",
|
|
24
|
-
"require": "./tracecontext.js"
|
|
25
|
-
},
|
|
26
22
|
"./package.json": "./package.json"
|
|
27
23
|
},
|
|
28
24
|
"main": "./index.js",
|
|
@@ -34,6 +30,6 @@
|
|
|
34
30
|
"*.d.ts"
|
|
35
31
|
],
|
|
36
32
|
"dependencies": {
|
|
37
|
-
"tctx": "^0.0.
|
|
33
|
+
"tctx": "^0.0.10"
|
|
38
34
|
}
|
|
39
35
|
}
|
package/tracecontext.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { Traceparent, make as make_traceparent, parse as parse_traceparent } from 'tctx';
|
package/tracecontext.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.parse_traceparent = exports.make_traceparent = void 0;
|
|
5
|
-
var tctx_1 = require("tctx");
|
|
6
|
-
Object.defineProperty(exports, "make_traceparent", { enumerable: true, get: function () { return tctx_1.make; } });
|
|
7
|
-
Object.defineProperty(exports, "parse_traceparent", { enumerable: true, get: function () { return tctx_1.parse; } });
|
package/tracecontext.mjs
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
-
exports.parse_traceparent = exports.make_traceparent = void 0;
|
|
3
|
-
var tctx_1 = require("tctx");
|
|
4
|
-
Object.defineProperty(exports, "make_traceparent", { enumerable: true, get: function () { return tctx_1.make; } });
|
|
5
|
-
Object.defineProperty(exports, "parse_traceparent", { enumerable: true, get: function () { return tctx_1.parse; } });
|