rian 0.3.4 → 0.3.6
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/async.js +1 -1
- package/async.mjs +1 -1
- package/index.d.ts +16 -10
- package/index.js +1 -1
- package/index.mjs +1 -1
- package/license +1 -1
- package/package.json +85 -85
- package/readme.md +1 -1
package/async.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
const e = require('node:async_hooks');const { measure:t } = require('rian/utils');const { make:n, parse:r, SAMPLED_FLAG:o } = require('tctx');const { is_sampled:a } = require('tctx');var s={};function
|
1
|
+
const e = require('node:async_hooks');const { measure:t } = require('rian/utils');const { make:n, parse:r, SAMPLED_FLAG:o } = require('tctx');const { is_sampled:a } = require('tctx');var s={};function l(e,t={}){s={...t,"service.name":e,"telemetry.sdk.name":"rian","telemetry.sdk.version":"0.3.6"}}var c=new Set,p=new WeakMap;async function u(e){let t=[],n=new Map;for(let[e,r]of c){let o;n.has(r)?o=n.get(r).spans:n.set(r,{scope:r,spans:o=[]}),o.push(e),p.has(r)&&(t.push(...p.get(r)),p.delete(r))}return c.clear(),t.length&&await Promise.all(t),e({resource:s,scopeSpans:n.values()})}function i(e,t){return a(t)}var m=new e.AsyncLocalStorage;function f(){let e=m.getStore()?.[1];if(null==e)throw new Error("no current span");return e}function d(e,a){let s=m.getStore();if(!s)throw Error("TODO");let l=s[0],u=l.scope,i=s[1],f=l.sampler,g=null!=a?"string"==typeof a?r(a):a:i?.traceparent,w=g?g.child():n(),h="boolean"!=typeof f?f(e,w,u):f;h?w.flags|=o:w.flags&=~o;let k={id:w,parent:g,start:l.clock.now(),name:e,events:[],context:{}};h&&c.add([k,u]);let v=e=>m.run([l,v],t,v,e);v.traceparent=w,v.span=e=>m.run([l,v],d,e),v.set_context=e=>{"function"!=typeof e?Object.assign(k.context,e):k.context=e(k.context)},v.add_event=(e,t)=>{k.events.push({name:e,timestamp:l.clock.now(),attributes:t||{}})},v.end=()=>{null==k.end&&(k.end=l.clock.now())};let x=p.get(u);return v.__add_promise=e=>{x.add(e),e.then((()=>x.delete(e)))},v}function g(e,t){let n={name:e},r={scope:n,sampler:t?.sampler??i,clock:t?.clock??Date};return p.set(n,new Set),function(e){let t=m.getStore();return m.run([r,t?.[1]||null],e)}}exports.configure=l;exports.currentSpan=f;exports.report=u;exports.span=d;exports.tracer=g;
|
package/async.mjs
CHANGED
@@ -1 +1 @@
|
|
1
|
-
import*as e from"node:async_hooks";import{measure as t}from"rian/utils";import{make as n,parse as r,SAMPLED_FLAG as o}from"tctx";import{is_sampled as a}from"tctx";var s={};function
|
1
|
+
import*as e from"node:async_hooks";import{measure as t}from"rian/utils";import{make as n,parse as r,SAMPLED_FLAG as o}from"tctx";import{is_sampled as a}from"tctx";var s={};function l(e,t={}){s={...t,"service.name":e,"telemetry.sdk.name":"rian","telemetry.sdk.version":"0.3.6"}}var c=new Set,p=new WeakMap;async function u(e){let t=[],n=new Map;for(let[e,r]of c){let o;n.has(r)?o=n.get(r).spans:n.set(r,{scope:r,spans:o=[]}),o.push(e),p.has(r)&&(t.push(...p.get(r)),p.delete(r))}return c.clear(),t.length&&await Promise.all(t),e({resource:s,scopeSpans:n.values()})}function i(e,t){return a(t)}var m=new e.AsyncLocalStorage;function f(){let e=m.getStore()?.[1];if(null==e)throw new Error("no current span");return e}function d(e,a){let s=m.getStore();if(!s)throw Error("TODO");let l=s[0],u=l.scope,i=s[1],f=l.sampler,g=null!=a?"string"==typeof a?r(a):a:i?.traceparent,w=g?g.child():n(),h="boolean"!=typeof f?f(e,w,u):f;h?w.flags|=o:w.flags&=~o;let k={id:w,parent:g,start:l.clock.now(),name:e,events:[],context:{}};h&&c.add([k,u]);let v=e=>m.run([l,v],t,v,e);v.traceparent=w,v.span=e=>m.run([l,v],d,e),v.set_context=e=>{"function"!=typeof e?Object.assign(k.context,e):k.context=e(k.context)},v.add_event=(e,t)=>{k.events.push({name:e,timestamp:l.clock.now(),attributes:t||{}})},v.end=()=>{null==k.end&&(k.end=l.clock.now())};let x=p.get(u);return v.__add_promise=e=>{x.add(e),e.then((()=>x.delete(e)))},v}function g(e,t){let n={name:e},r={scope:n,sampler:t?.sampler??i,clock:t?.clock??Date};return p.set(n,new Set),function(e){let t=m.getStore();return m.run([r,t?.[1]||null],e)}}export{l as configure,f as currentSpan,u as report,d as span,g as tracer};
|
package/index.d.ts
CHANGED
@@ -5,10 +5,18 @@ import type { Traceparent } from 'tctx';
|
|
5
5
|
/**
|
6
6
|
* The exporter is called when the {@link report} method is called.
|
7
7
|
*/
|
8
|
-
export type Exporter = (trace:
|
9
|
-
|
8
|
+
export type Exporter = (trace: Trace) => any;
|
9
|
+
|
10
|
+
type Resource = {
|
11
|
+
'service.name': string;
|
12
|
+
'telemetry.sdk.name': string;
|
13
|
+
'telemetry.sdk.version': string;
|
14
|
+
} & Context;
|
15
|
+
|
16
|
+
export type Trace = {
|
17
|
+
resource: Resource;
|
10
18
|
scopeSpans: IterableIterator<ScopedSpans>;
|
11
|
-
}
|
19
|
+
};
|
12
20
|
|
13
21
|
export type ScopedSpans = {
|
14
22
|
readonly scope: { readonly name: string };
|
@@ -43,15 +51,15 @@ export type Sampler = (
|
|
43
51
|
/**
|
44
52
|
* The name of the span.
|
45
53
|
*/
|
46
|
-
|
54
|
+
name: string,
|
47
55
|
/**
|
48
56
|
* The traceparent id of the span.
|
49
57
|
*/
|
50
|
-
|
58
|
+
id: Traceparent,
|
51
59
|
/**
|
52
60
|
* The tracer this span belongs to.
|
53
61
|
*/
|
54
|
-
|
62
|
+
tracer: { readonly name: string },
|
55
63
|
) => boolean;
|
56
64
|
|
57
65
|
// --- spans
|
@@ -209,9 +217,7 @@ export function tracer(name: string, options?: Options): Tracer;
|
|
209
217
|
/**
|
210
218
|
* Awaits all active promises, and then calls the {@link Options.exporter|exporter}. Passing all collected spans.
|
211
219
|
*/
|
212
|
-
export
|
213
|
-
exporter: T,
|
214
|
-
): Promise<ReturnType<T>>;
|
220
|
+
export function report<T extends Exporter>(exporter: T): Promise<ReturnType<T>>;
|
215
221
|
|
216
222
|
/**
|
217
223
|
* Calling this method will set the resource attributes for this runtime. This is useful for things like:
|
@@ -229,7 +235,7 @@ export async function report<T extends Exporter>(
|
|
229
235
|
* configure('my-service', { 'deployment.environment': 'production', 'k8s.namespace.name': 'default' });
|
230
236
|
* ```
|
231
237
|
*/
|
232
|
-
export function configure(name: string, attributes
|
238
|
+
export function configure(name: string, attributes?: Context): void;
|
233
239
|
|
234
240
|
/**
|
235
241
|
* Provinding a clock allows you to control the time of the span.
|
package/index.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
const { measure:e } = require('rian/utils');const { make:t, parse:n, SAMPLED_FLAG:a } = require('tctx');const { is_sampled:
|
1
|
+
const { measure:e } = require('rian/utils');const { make:t, parse:n, SAMPLED_FLAG:a } = require('tctx');const { is_sampled:s } = require('tctx');var o={};function r(e,t={}){o={...t,"service.name":e,"telemetry.sdk.name":"rian","telemetry.sdk.version":"0.3.6"}}var l=new Set,i=new WeakMap;async function p(e){let t=[],n=new Map;for(let[e,a]of l){let s;n.has(a)?s=n.get(a).spans:n.set(a,{scope:a,spans:s=[]}),s.push(e),i.has(a)&&(t.push(...i.get(a)),i.delete(a))}return l.clear(),t.length&&await Promise.all(t),e({resource:o,scopeSpans:n.values()})}function c(e,t){return s(t)}function d(s,o){let r=o?.sampler??c,p=o?.clock??Date,d={name:s},m=new Set;i.set(d,m);let u=(s,o)=>{let i=null!=o?"string"==typeof o?n(o):o:void 0,c=i?i.child():t(),f="boolean"!=typeof r?r(s,c,d):r;f?c.flags|=a:c.flags&=~a;let v={id:c,parent:i,start:p.now(),name:s,events:[],context:{}};f&&l.add([v,d]);let h=t=>e(h,t);return h.traceparent=c,h.span=(e,t)=>u(e,t||c),h.set_context=e=>"function"==typeof e?void(v.context=e(v.context)):void Object.assign(v.context,e),h.add_event=(e,t)=>{v.events.push({name:e,timestamp:p.now(),attributes:t||{}})},h.end=()=>{null==v.end&&(v.end=p.now())},h.__add_promise=e=>{m.add(e),e.then((()=>m.delete(e)))},h};return{span:u}}exports.configure=r;exports.report=p;exports.tracer=d;
|
package/index.mjs
CHANGED
@@ -1 +1 @@
|
|
1
|
-
import{measure as e}from"rian/utils";import{make as t,parse as n,SAMPLED_FLAG as a}from"tctx";import{is_sampled as
|
1
|
+
import{measure as e}from"rian/utils";import{make as t,parse as n,SAMPLED_FLAG as a}from"tctx";import{is_sampled as s}from"tctx";var o={};function r(e,t={}){o={...t,"service.name":e,"telemetry.sdk.name":"rian","telemetry.sdk.version":"0.3.6"}}var l=new Set,i=new WeakMap;async function p(e){let t=[],n=new Map;for(let[e,a]of l){let s;n.has(a)?s=n.get(a).spans:n.set(a,{scope:a,spans:s=[]}),s.push(e),i.has(a)&&(t.push(...i.get(a)),i.delete(a))}return l.clear(),t.length&&await Promise.all(t),e({resource:o,scopeSpans:n.values()})}function c(e,t){return s(t)}function d(s,o){let r=o?.sampler??c,p=o?.clock??Date,d={name:s},m=new Set;i.set(d,m);let u=(s,o)=>{let i=null!=o?"string"==typeof o?n(o):o:void 0,c=i?i.child():t(),f="boolean"!=typeof r?r(s,c,d):r;f?c.flags|=a:c.flags&=~a;let v={id:c,parent:i,start:p.now(),name:s,events:[],context:{}};f&&l.add([v,d]);let h=t=>e(h,t);return h.traceparent=c,h.span=(e,t)=>u(e,t||c),h.set_context=e=>"function"==typeof e?void(v.context=e(v.context)):void Object.assign(v.context,e),h.add_event=(e,t)=>{v.events.push({name:e,timestamp:p.now(),attributes:t||{}})},h.end=()=>{null==v.end&&(v.end=p.now())},h.__add_promise=e=>{m.add(e),e.then((()=>m.delete(e)))},h};return{span:u}}export{r as configure,p as report,d as tracer};
|
package/license
CHANGED
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
18
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
19
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
20
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
-
SOFTWARE.
|
21
|
+
SOFTWARE.
|
package/package.json
CHANGED
@@ -1,87 +1,87 @@
|
|
1
1
|
{
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
2
|
+
"name": "rian",
|
3
|
+
"version": "0.3.6",
|
4
|
+
"description": "Effective tracing for the edge and origins",
|
5
|
+
"keywords": [
|
6
|
+
"opentelemetry",
|
7
|
+
"trace-context",
|
8
|
+
"opentracing",
|
9
|
+
"traceparent",
|
10
|
+
"measure",
|
11
|
+
"monitor",
|
12
|
+
"observe",
|
13
|
+
"tracing",
|
14
|
+
"zipkin",
|
15
|
+
"tracer",
|
16
|
+
"trace"
|
17
|
+
],
|
18
|
+
"repository": "maraisr/rian",
|
19
|
+
"license": "MIT",
|
20
|
+
"author": "Marais Rossow <me@marais.dev> (https://marais.io)",
|
21
|
+
"sideEffects": false,
|
22
|
+
"exports": {
|
23
|
+
".": {
|
24
|
+
"types": "./index.d.ts",
|
25
|
+
"import": "./index.mjs",
|
26
|
+
"require": "./index.js"
|
27
|
+
},
|
28
|
+
"./async": {
|
29
|
+
"types": "./async.d.ts",
|
30
|
+
"import": "./async.mjs",
|
31
|
+
"require": "./async.js"
|
32
|
+
},
|
33
|
+
"./exporter.otel.http": {
|
34
|
+
"types": "./exporter.otel.http.d.ts",
|
35
|
+
"import": "./exporter.otel.http.mjs",
|
36
|
+
"require": "./exporter.otel.http.js"
|
37
|
+
},
|
38
|
+
"./exporter.zipkin": {
|
39
|
+
"types": "./exporter.zipkin.d.ts",
|
40
|
+
"import": "./exporter.zipkin.mjs",
|
41
|
+
"require": "./exporter.zipkin.js"
|
42
|
+
},
|
43
|
+
"./utils": {
|
44
|
+
"types": "./utils.d.ts",
|
45
|
+
"import": "./utils.mjs",
|
46
|
+
"require": "./utils.js"
|
47
|
+
},
|
48
|
+
"./package.json": "./package.json"
|
49
|
+
},
|
50
|
+
"main": "./index.js",
|
51
|
+
"module": "./index.mjs",
|
52
|
+
"types": "index.d.ts",
|
53
|
+
"files": [
|
54
|
+
"*.mjs",
|
55
|
+
"*.js",
|
56
|
+
"*.d.ts",
|
57
|
+
"!global.d.ts",
|
58
|
+
"exporter.*/*",
|
59
|
+
"utils/*"
|
60
|
+
],
|
61
|
+
"scripts": {
|
62
|
+
"bench": "node -r tsm bench/index.ts",
|
63
|
+
"build": "bundt --minify",
|
64
|
+
"format": "prettier --write \"{*,{src,test}/**/*,examples/*/**,bench/*,.github/**/*}.+(ts|js|json|yml|md)\"",
|
65
|
+
"pretest": "pnpm run build",
|
66
|
+
"test": "uvu src \".test.ts$\" -r tsm",
|
67
|
+
"typecheck": "tsc --noEmit"
|
68
|
+
},
|
69
|
+
"prettier": "@marais/prettier",
|
70
|
+
"dependencies": {
|
71
|
+
"flattie": "^1.1.0",
|
72
|
+
"tctx": "^0.0.13"
|
73
|
+
},
|
74
|
+
"devDependencies": {
|
75
|
+
"@marais/prettier": "0.0.4",
|
76
|
+
"@marais/tsconfig": "0.0.4",
|
77
|
+
"bundt": "2.0.0-next.5",
|
78
|
+
"nanospy": "1.0.0",
|
79
|
+
"prettier": "2.8.8",
|
80
|
+
"tsm": "2.3.0",
|
81
|
+
"typescript": "5.1.3",
|
82
|
+
"uvu": "0.5.4"
|
83
|
+
},
|
84
|
+
"volta": {
|
85
|
+
"node": "18.16.1"
|
86
|
+
}
|
87
87
|
}
|
package/readme.md
CHANGED
@@ -87,7 +87,7 @@ http.listen((req, executionCtx) => {
|
|
87
87
|
/*
|
88
88
|
And we end up with something like this in our reporting tool:
|
89
89
|
|
90
|
-
[ GET /data
|
90
|
+
[ GET /data ......................................... (1.2ms) ] { request }
|
91
91
|
[ db::read .... (0.5ms) ] [ process records .... (0.5ms) ]
|
92
92
|
^ ^ ^ ^
|
93
93
|
{ user_id } ev { id: 1 } | |
|