rian 0.0.5 → 0.2.1
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/exporter.otel.http/index.d.ts +3 -0
- package/exporter.otel.http/index.js +110 -0
- package/exporter.otel.http/index.mjs +110 -0
- package/exporter.zipkin/index.d.ts +3 -0
- package/exporter.zipkin/index.js +43 -0
- package/exporter.zipkin/index.mjs +43 -0
- package/index.d.ts +146 -145
- package/index.js +68 -124
- package/index.mjs +70 -104
- package/package.json +22 -6
- package/utils/index.d.ts +68 -0
- package/utils/index.js +30 -0
- package/utils/index.mjs +30 -0
- package/exporter.otel.http.d.ts +0 -5
- package/exporter.otel.http.js +0 -112
- package/exporter.otel.http.mjs +0 -110
- package/exporter.zipkin.d.ts +0 -5
- package/exporter.zipkin.js +0 -45
- package/exporter.zipkin.mjs +0 -43
package/index.js
CHANGED
|
@@ -1,132 +1,76 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const package_json = require('rian/package.json');
|
|
1
|
+
// src/index.ts
|
|
2
|
+
const { name:rian_name, version:rian_version } = require('rian/package.json');
|
|
4
3
|
const tctx = require('tctx');
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
13
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
14
|
-
enumerable: true,
|
|
15
|
-
get: function () { return e[k]; }
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
n["default"] = e;
|
|
21
|
-
return n;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const tctx__namespace = /*#__PURE__*/_interopNamespace(tctx);
|
|
25
|
-
|
|
26
|
-
const set_error = (scope, error) => {
|
|
27
|
-
scope.set_context({
|
|
28
|
-
error,
|
|
29
|
-
});
|
|
4
|
+
const { measureFn } = require('rian/utils');
|
|
5
|
+
var PROMISES = /* @__PURE__ */ new WeakMap();
|
|
6
|
+
var ADD_PROMISE = (scope, promise) => {
|
|
7
|
+
if (PROMISES.has(scope))
|
|
8
|
+
PROMISES.get(scope).push(promise);
|
|
9
|
+
else
|
|
10
|
+
PROMISES.set(scope, [promise]);
|
|
30
11
|
};
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
if (is_promise)
|
|
36
|
-
promises.push(r
|
|
37
|
-
.catch((e) => void set_error(scope, e))
|
|
38
|
-
.finally(() => scope.end()));
|
|
39
|
-
return r;
|
|
40
|
-
}
|
|
41
|
-
catch (e) {
|
|
42
|
-
set_error(scope, e);
|
|
43
|
-
throw e;
|
|
44
|
-
}
|
|
45
|
-
finally {
|
|
46
|
-
if (is_promise !== true)
|
|
47
|
-
scope.end();
|
|
48
|
-
}
|
|
12
|
+
var defaultSampler = (_name, parentId) => {
|
|
13
|
+
if (!parentId)
|
|
14
|
+
return true;
|
|
15
|
+
return tctx.is_sampled(parentId);
|
|
49
16
|
};
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
* The default sampler;
|
|
54
|
-
*
|
|
55
|
-
* If no parent
|
|
56
|
-
* ~> sample
|
|
57
|
-
* if parent was off
|
|
58
|
-
* ~> never sample
|
|
59
|
-
* if parent was on
|
|
60
|
-
* ~> always sample
|
|
61
|
-
*/
|
|
62
|
-
const defaultSampler = (_name, parentId) => {
|
|
63
|
-
if (!parentId)
|
|
64
|
-
return true;
|
|
65
|
-
return tctx__namespace.is_sampled(parentId);
|
|
17
|
+
var sdk_object = {
|
|
18
|
+
"telemetry.sdk.name": rian_name,
|
|
19
|
+
"telemetry.sdk.version": rian_version
|
|
66
20
|
};
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
const
|
|
72
|
-
const
|
|
73
|
-
const
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
if (typeof ctx === 'function')
|
|
99
|
-
return void (span_obj.context = ctx(span_obj.context));
|
|
100
|
-
Object.assign(span_obj.context, ctx);
|
|
101
|
-
};
|
|
102
|
-
$.add_event = (name, attributes) => {
|
|
103
|
-
span_obj.events.push({
|
|
104
|
-
name,
|
|
105
|
-
timestamp: Date.now(),
|
|
106
|
-
attributes: attributes || {},
|
|
107
|
-
});
|
|
108
|
-
};
|
|
109
|
-
$.end = () => {
|
|
110
|
-
if (span_obj.end)
|
|
111
|
-
return void 0;
|
|
112
|
-
span_obj.end = Date.now();
|
|
113
|
-
};
|
|
114
|
-
return $;
|
|
21
|
+
var create = (name, options) => {
|
|
22
|
+
const spans = /* @__PURE__ */ new Set();
|
|
23
|
+
const sampler = options.sampler || defaultSampler;
|
|
24
|
+
const sampler_callable = typeof sampler !== "boolean";
|
|
25
|
+
const span = (name2, parent) => {
|
|
26
|
+
const should_sample = sampler_callable ? sampler(name2, parent, options.context) : sampler;
|
|
27
|
+
const id = parent ? parent.child(should_sample) : tctx.make(should_sample);
|
|
28
|
+
const span_obj = {
|
|
29
|
+
id,
|
|
30
|
+
parent,
|
|
31
|
+
start: Date.now(),
|
|
32
|
+
name: name2,
|
|
33
|
+
events: [],
|
|
34
|
+
context: {}
|
|
35
|
+
};
|
|
36
|
+
if (should_sample)
|
|
37
|
+
spans.add(span_obj);
|
|
38
|
+
const $ = (cb) => measureFn($, cb);
|
|
39
|
+
$.traceparent = id;
|
|
40
|
+
$.fork = (name3) => span(name3, id);
|
|
41
|
+
$.set_context = (ctx) => {
|
|
42
|
+
if (typeof ctx === "function")
|
|
43
|
+
return void (span_obj.context = ctx(span_obj.context));
|
|
44
|
+
Object.assign(span_obj.context, ctx);
|
|
45
|
+
};
|
|
46
|
+
$.add_event = (name3, attributes) => {
|
|
47
|
+
span_obj.events.push({
|
|
48
|
+
name: name3,
|
|
49
|
+
timestamp: Date.now(),
|
|
50
|
+
attributes: attributes || {}
|
|
51
|
+
});
|
|
115
52
|
};
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
const endRoot = root.end.bind(root);
|
|
120
|
-
root.end = async () => {
|
|
121
|
-
endRoot();
|
|
122
|
-
if (promises.length)
|
|
123
|
-
await Promise.all(promises);
|
|
124
|
-
return options.exporter(spans, {
|
|
125
|
-
...(options.context || {}),
|
|
126
|
-
...sdk_object,
|
|
127
|
-
});
|
|
53
|
+
$.end = () => {
|
|
54
|
+
if (span_obj.end == null)
|
|
55
|
+
span_obj.end = Date.now();
|
|
128
56
|
};
|
|
129
|
-
return
|
|
57
|
+
return $;
|
|
58
|
+
};
|
|
59
|
+
const root = span(name, typeof options.traceparent === "string" ? tctx.parse(options.traceparent) : void 0);
|
|
60
|
+
const endRoot = root.end.bind(root);
|
|
61
|
+
root.end = async () => {
|
|
62
|
+
endRoot();
|
|
63
|
+
if (PROMISES.has(root))
|
|
64
|
+
await Promise.all(PROMISES.get(root));
|
|
65
|
+
return options.exporter(spans, {
|
|
66
|
+
...options.context || {},
|
|
67
|
+
...sdk_object
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
return root;
|
|
130
71
|
};
|
|
131
72
|
|
|
132
|
-
|
|
73
|
+
|
|
74
|
+
exports.ADD_PROMISE = ADD_PROMISE;
|
|
75
|
+
exports.PROMISES = PROMISES;
|
|
76
|
+
exports.create = create;
|
package/index.mjs
CHANGED
|
@@ -1,110 +1,76 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
scope,
|
|
11
|
-
try {
|
|
12
|
-
var r = fn(...args, scope), is_promise = r instanceof Promise;
|
|
13
|
-
if (is_promise)
|
|
14
|
-
promises.push(r
|
|
15
|
-
.catch((e) => void set_error(scope, e))
|
|
16
|
-
.finally(() => scope.end()));
|
|
17
|
-
return r;
|
|
18
|
-
}
|
|
19
|
-
catch (e) {
|
|
20
|
-
set_error(scope, e);
|
|
21
|
-
throw e;
|
|
22
|
-
}
|
|
23
|
-
finally {
|
|
24
|
-
if (is_promise !== true)
|
|
25
|
-
scope.end();
|
|
26
|
-
}
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { name as rian_name, version as rian_version } from "rian/package.json";
|
|
3
|
+
import * as tctx from "tctx";
|
|
4
|
+
import { measureFn } from "rian/utils";
|
|
5
|
+
var PROMISES = /* @__PURE__ */ new WeakMap();
|
|
6
|
+
var ADD_PROMISE = (scope, promise) => {
|
|
7
|
+
if (PROMISES.has(scope))
|
|
8
|
+
PROMISES.get(scope).push(promise);
|
|
9
|
+
else
|
|
10
|
+
PROMISES.set(scope, [promise]);
|
|
27
11
|
};
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
*
|
|
33
|
-
* If no parent
|
|
34
|
-
* ~> sample
|
|
35
|
-
* if parent was off
|
|
36
|
-
* ~> never sample
|
|
37
|
-
* if parent was on
|
|
38
|
-
* ~> always sample
|
|
39
|
-
*/
|
|
40
|
-
const defaultSampler = (_name, parentId) => {
|
|
41
|
-
if (!parentId)
|
|
42
|
-
return true;
|
|
43
|
-
return tctx.is_sampled(parentId);
|
|
12
|
+
var defaultSampler = (_name, parentId) => {
|
|
13
|
+
if (!parentId)
|
|
14
|
+
return true;
|
|
15
|
+
return tctx.is_sampled(parentId);
|
|
44
16
|
};
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
17
|
+
var sdk_object = {
|
|
18
|
+
"telemetry.sdk.name": rian_name,
|
|
19
|
+
"telemetry.sdk.version": rian_version
|
|
48
20
|
};
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
$.fork = (name) => span(name, id);
|
|
74
|
-
$.measure = (name, cb, ...args) => measure(cb, span(name, id), promises, ...args);
|
|
75
|
-
$.set_context = (ctx) => {
|
|
76
|
-
if (typeof ctx === 'function')
|
|
77
|
-
return void (span_obj.context = ctx(span_obj.context));
|
|
78
|
-
Object.assign(span_obj.context, ctx);
|
|
79
|
-
};
|
|
80
|
-
$.add_event = (name, attributes) => {
|
|
81
|
-
span_obj.events.push({
|
|
82
|
-
name,
|
|
83
|
-
timestamp: Date.now(),
|
|
84
|
-
attributes: attributes || {},
|
|
85
|
-
});
|
|
86
|
-
};
|
|
87
|
-
$.end = () => {
|
|
88
|
-
if (span_obj.end)
|
|
89
|
-
return void 0;
|
|
90
|
-
span_obj.end = Date.now();
|
|
91
|
-
};
|
|
92
|
-
return $;
|
|
21
|
+
var create = (name, options) => {
|
|
22
|
+
const spans = /* @__PURE__ */ new Set();
|
|
23
|
+
const sampler = options.sampler || defaultSampler;
|
|
24
|
+
const sampler_callable = typeof sampler !== "boolean";
|
|
25
|
+
const span = (name2, parent) => {
|
|
26
|
+
const should_sample = sampler_callable ? sampler(name2, parent, options.context) : sampler;
|
|
27
|
+
const id = parent ? parent.child(should_sample) : tctx.make(should_sample);
|
|
28
|
+
const span_obj = {
|
|
29
|
+
id,
|
|
30
|
+
parent,
|
|
31
|
+
start: Date.now(),
|
|
32
|
+
name: name2,
|
|
33
|
+
events: [],
|
|
34
|
+
context: {}
|
|
35
|
+
};
|
|
36
|
+
if (should_sample)
|
|
37
|
+
spans.add(span_obj);
|
|
38
|
+
const $ = (cb) => measureFn($, cb);
|
|
39
|
+
$.traceparent = id;
|
|
40
|
+
$.fork = (name3) => span(name3, id);
|
|
41
|
+
$.set_context = (ctx) => {
|
|
42
|
+
if (typeof ctx === "function")
|
|
43
|
+
return void (span_obj.context = ctx(span_obj.context));
|
|
44
|
+
Object.assign(span_obj.context, ctx);
|
|
93
45
|
};
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
:
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
if (promises.length)
|
|
101
|
-
await Promise.all(promises);
|
|
102
|
-
return options.exporter(spans, {
|
|
103
|
-
...(options.context || {}),
|
|
104
|
-
...sdk_object,
|
|
105
|
-
});
|
|
46
|
+
$.add_event = (name3, attributes) => {
|
|
47
|
+
span_obj.events.push({
|
|
48
|
+
name: name3,
|
|
49
|
+
timestamp: Date.now(),
|
|
50
|
+
attributes: attributes || {}
|
|
51
|
+
});
|
|
106
52
|
};
|
|
107
|
-
|
|
53
|
+
$.end = () => {
|
|
54
|
+
if (span_obj.end == null)
|
|
55
|
+
span_obj.end = Date.now();
|
|
56
|
+
};
|
|
57
|
+
return $;
|
|
58
|
+
};
|
|
59
|
+
const root = span(name, typeof options.traceparent === "string" ? tctx.parse(options.traceparent) : void 0);
|
|
60
|
+
const endRoot = root.end.bind(root);
|
|
61
|
+
root.end = async () => {
|
|
62
|
+
endRoot();
|
|
63
|
+
if (PROMISES.has(root))
|
|
64
|
+
await Promise.all(PROMISES.get(root));
|
|
65
|
+
return options.exporter(spans, {
|
|
66
|
+
...options.context || {},
|
|
67
|
+
...sdk_object
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
return root;
|
|
71
|
+
};
|
|
72
|
+
export {
|
|
73
|
+
ADD_PROMISE,
|
|
74
|
+
PROMISES,
|
|
75
|
+
create
|
|
108
76
|
};
|
|
109
|
-
|
|
110
|
-
export { create };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rian",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Effective tracing for the edge and origins",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"opentelemetry",
|
|
@@ -26,16 +26,24 @@
|
|
|
26
26
|
"type": "module",
|
|
27
27
|
"exports": {
|
|
28
28
|
".": {
|
|
29
|
+
"types": "./index.d.ts",
|
|
29
30
|
"import": "./index.mjs",
|
|
30
31
|
"require": "./index.js"
|
|
31
32
|
},
|
|
32
33
|
"./exporter.otel.http": {
|
|
33
|
-
"
|
|
34
|
-
"
|
|
34
|
+
"types": "./exporter.otel.http/index.d.ts",
|
|
35
|
+
"import": "./exporter.otel.http/index.mjs",
|
|
36
|
+
"require": "./exporter.otel.http/index.js"
|
|
35
37
|
},
|
|
36
38
|
"./exporter.zipkin": {
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
+
"types": "./exporter.zipkin/index.d.ts",
|
|
40
|
+
"import": "./exporter.zipkin/index.mjs",
|
|
41
|
+
"require": "./exporter.zipkin/index.js"
|
|
42
|
+
},
|
|
43
|
+
"./utils": {
|
|
44
|
+
"types": "./utils/index.d.ts",
|
|
45
|
+
"import": "./utils/index.mjs",
|
|
46
|
+
"require": "./utils/index.js"
|
|
39
47
|
},
|
|
40
48
|
"./package.json": "./package.json"
|
|
41
49
|
},
|
|
@@ -45,10 +53,18 @@
|
|
|
45
53
|
"files": [
|
|
46
54
|
"*.mjs",
|
|
47
55
|
"*.js",
|
|
48
|
-
"*.d.ts"
|
|
56
|
+
"*.d.ts",
|
|
57
|
+
"exporter.*/*",
|
|
58
|
+
"utils/*"
|
|
49
59
|
],
|
|
60
|
+
"scripts": {
|
|
61
|
+
"build": "bundt"
|
|
62
|
+
},
|
|
50
63
|
"dependencies": {
|
|
51
64
|
"flattie": "^1.1.0",
|
|
52
65
|
"tctx": "^0.0.10"
|
|
66
|
+
},
|
|
67
|
+
"devDependencies": {
|
|
68
|
+
"bundt": "2.0.0-next.5"
|
|
53
69
|
}
|
|
54
70
|
}
|
package/utils/index.d.ts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { Scope } from 'rian';
|
|
2
|
+
|
|
3
|
+
export type MeasureFn =
|
|
4
|
+
| ((...args: [...args: any[]]) => any)
|
|
5
|
+
| ((...args: [...args: any[], scope: Scope]) => any);
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* With a passed function — will start a span, and run the function, when the function finishes
|
|
9
|
+
* the span finishes.
|
|
10
|
+
*
|
|
11
|
+
* The measure method will return whatever the function is, so if it's a promise, it returns a
|
|
12
|
+
* promise and so on. Any error is caught and re thrown, and automatically tracked in the
|
|
13
|
+
* context under the `error` property.
|
|
14
|
+
*
|
|
15
|
+
* All promises are tracked, and awaited on a `tracer.end`.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
*
|
|
19
|
+
* ```text
|
|
20
|
+
* const data = await measure(scope, 'name', get_data, 'user_id_123');
|
|
21
|
+
* ^ ^ ^ ^ ^
|
|
22
|
+
* | | | | |
|
|
23
|
+
* | | | | the first argument to get_data
|
|
24
|
+
* | | | function to be called
|
|
25
|
+
* | | the name of the sub scope
|
|
26
|
+
* | |
|
|
27
|
+
* | the parent scope
|
|
28
|
+
* return value from get_data
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export const measure: <Fn extends MeasureFn>(
|
|
32
|
+
scope: Scope,
|
|
33
|
+
name: string,
|
|
34
|
+
fn: Fn, // TODO: fn doesnt see scope correctly
|
|
35
|
+
...args: RealMeasureFnParams<Parameters<Fn>>
|
|
36
|
+
) => ReturnType<Fn>;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Wraps any function with a measured scoped function. Useful for when defer function execution
|
|
40
|
+
* till a later time.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
*
|
|
44
|
+
* ```js
|
|
45
|
+
* const wrapped = wrap(scope, "run something", my_function);
|
|
46
|
+
*
|
|
47
|
+
* // ... lots of things, where the access to `scope` is lost.
|
|
48
|
+
*
|
|
49
|
+
* wrapped();
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export const wrap: <Fn extends MeasureFn>(
|
|
53
|
+
scope: Scope,
|
|
54
|
+
name: string,
|
|
55
|
+
fn: Fn, // TODO: fn doesnt see scope correctly
|
|
56
|
+
) => Fn;
|
|
57
|
+
|
|
58
|
+
// ==> internals
|
|
59
|
+
|
|
60
|
+
/** @internal */
|
|
61
|
+
export type RealMeasureFnParams<T extends unknown[]> = T extends []
|
|
62
|
+
? []
|
|
63
|
+
: T extends [...rest: infer U, scope: Scope]
|
|
64
|
+
? U
|
|
65
|
+
: T;
|
|
66
|
+
|
|
67
|
+
/** @internal */
|
|
68
|
+
export const measureFn: (scope: Scope, fn: any, ...args: any[]) => any;
|
package/utils/index.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// src/utils.ts
|
|
2
|
+
const { ADD_PROMISE, PROMISES } = require('rian');
|
|
3
|
+
var measureFn = (scope, fn, ...args) => {
|
|
4
|
+
try {
|
|
5
|
+
var r = fn(...args, scope), is_promise = r instanceof Promise;
|
|
6
|
+
if (is_promise && !PROMISES.has(scope))
|
|
7
|
+
ADD_PROMISE(scope, r.catch((e) => void scope.set_context({
|
|
8
|
+
error: e
|
|
9
|
+
})).finally(() => scope.end()));
|
|
10
|
+
return r;
|
|
11
|
+
} catch (e) {
|
|
12
|
+
if (e instanceof Error)
|
|
13
|
+
scope.set_context({
|
|
14
|
+
error: e
|
|
15
|
+
});
|
|
16
|
+
throw e;
|
|
17
|
+
} finally {
|
|
18
|
+
if (is_promise !== true)
|
|
19
|
+
scope.end();
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
var measure = (scope, name, fn, ...args) => measureFn(scope.fork(name), fn, ...args);
|
|
23
|
+
var wrap = (scope, name, fn) => function() {
|
|
24
|
+
return measureFn(scope.fork(name), fn, ...arguments);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
exports.measure = measure;
|
|
29
|
+
exports.measureFn = measureFn;
|
|
30
|
+
exports.wrap = wrap;
|
package/utils/index.mjs
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// src/utils.ts
|
|
2
|
+
import { ADD_PROMISE, PROMISES } from "rian";
|
|
3
|
+
var measureFn = (scope, fn, ...args) => {
|
|
4
|
+
try {
|
|
5
|
+
var r = fn(...args, scope), is_promise = r instanceof Promise;
|
|
6
|
+
if (is_promise && !PROMISES.has(scope))
|
|
7
|
+
ADD_PROMISE(scope, r.catch((e) => void scope.set_context({
|
|
8
|
+
error: e
|
|
9
|
+
})).finally(() => scope.end()));
|
|
10
|
+
return r;
|
|
11
|
+
} catch (e) {
|
|
12
|
+
if (e instanceof Error)
|
|
13
|
+
scope.set_context({
|
|
14
|
+
error: e
|
|
15
|
+
});
|
|
16
|
+
throw e;
|
|
17
|
+
} finally {
|
|
18
|
+
if (is_promise !== true)
|
|
19
|
+
scope.end();
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
var measure = (scope, name, fn, ...args) => measureFn(scope.fork(name), fn, ...args);
|
|
23
|
+
var wrap = (scope, name, fn) => function() {
|
|
24
|
+
return measureFn(scope.fork(name), fn, ...arguments);
|
|
25
|
+
};
|
|
26
|
+
export {
|
|
27
|
+
measure,
|
|
28
|
+
measureFn,
|
|
29
|
+
wrap
|
|
30
|
+
};
|