rian 0.3.0-next.2 → 0.3.0-next.4
Sign up to get free protection for your applications and to get access to all the features.
- package/async.d.ts +6 -0
- package/async.js +1 -0
- package/async.mjs +1 -0
- package/{exporter.otel.http/index.js → exporter.otel.http.js} +1 -1
- package/{exporter.otel.http/index.mjs → exporter.otel.http.mjs} +1 -1
- package/index.d.ts +4 -5
- package/index.js +1 -1
- package/index.mjs +1 -1
- package/package.json +16 -10
- package/readme.md +12 -14
- package/global.d.ts +0 -1
- /package/{exporter.otel.http/index.d.ts → exporter.otel.http.d.ts} +0 -0
- /package/{exporter.zipkin/index.d.ts → exporter.zipkin.d.ts} +0 -0
- /package/{exporter.zipkin/index.js → exporter.zipkin.js} +0 -0
- /package/{exporter.zipkin/index.mjs → exporter.zipkin.mjs} +0 -0
- /package/{utils/index.d.ts → utils.d.ts} +0 -0
- /package/{utils/index.js → utils.js} +0 -0
- /package/{utils/index.mjs → utils.mjs} +0 -0
package/async.d.ts
ADDED
package/async.js
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
const { default:e } = require('node:async_hooks');const { measure:t } = require('rian/utils');const { make:n, parse:r, SAMPLED_FLAG:a } = require('tctx');const { is_sampled:o } = require('tctx');var s=new Set,l=new WeakMap;async function c(e){let t=[],n=new Map;for(let[e,r]of s){let a;n.has(r)?a=n.get(r).spans:n.set(r,{resource:r,spans:a=new Set}),a.add(e),l.has(r)&&(t.push(...l.get(r)),l.delete(r))}return s.clear(),t.length&&await Promise.all(t),e(n.values())}function i(e,t){return o(t)}var p=new e.AsyncLocalStorage;function u(){return p.getStore()?.[1]||null}function d(e){let r=p.getStore();if(!r)throw Error("TODO");let a=r[0],o=a.resource,c=r[1],i=a.sampler,u=c?.traceparent??a.root_id,m=u?u.child():n(),f="boolean"!=typeof i?i(e,m,o):i;m.flags;let w={id:m,parent:u,start:Date.now(),name:e,events:[],context:{}};f&&s.add([w,o]);let g=e=>p.run([a,g],t,g,e);g.traceparent=m,g.span=d,g.set_context=e=>{"function"!=typeof e?Object.assign(w.context,e):w.context=e(w.context)},g.add_event=(e,t)=>{w.events.push({name:e,timestamp:Date.now(),attributes:t||{}})},g.end=()=>{null==w.end&&(w.end=Date.now())};let x=l.get(o);return g.__add_promise=e=>{x.add(e),e.then((()=>x.delete(e)))},p.run([a,g],(()=>g))}function m(e,t){let n=t?.sampler??i,a=t?.context||{};a["service.name"]=e,a["telemetry.sdk.name"]="rian",a["telemetry.sdk.version"]="0.3.0-next.4";let o={root_id:"string"==typeof t?.traceparent?r(t.traceparent):void 0,resource:a,sampler:n};return l.set(a,new Set),{span:e=>p.run([o,null],d,e)}}exports.currentSpan=u;exports.report=c;exports.span=d;exports.tracer=m;
|
package/async.mjs
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
import{default as e}from"node:async_hooks";import{measure as t}from"rian/utils";import{make as n,parse as r,SAMPLED_FLAG as a}from"tctx";import{is_sampled as o}from"tctx";var s=new Set,l=new WeakMap;async function c(e){let t=[],n=new Map;for(let[e,r]of s){let a;n.has(r)?a=n.get(r).spans:n.set(r,{resource:r,spans:a=new Set}),a.add(e),l.has(r)&&(t.push(...l.get(r)),l.delete(r))}return s.clear(),t.length&&await Promise.all(t),e(n.values())}function i(e,t){return o(t)}var p=new e.AsyncLocalStorage;function u(){return p.getStore()?.[1]||null}function d(e){let r=p.getStore();if(!r)throw Error("TODO");let a=r[0],o=a.resource,c=r[1],i=a.sampler,u=c?.traceparent??a.root_id,m=u?u.child():n(),f="boolean"!=typeof i?i(e,m,o):i;m.flags;let w={id:m,parent:u,start:Date.now(),name:e,events:[],context:{}};f&&s.add([w,o]);let g=e=>p.run([a,g],t,g,e);g.traceparent=m,g.span=d,g.set_context=e=>{"function"!=typeof e?Object.assign(w.context,e):w.context=e(w.context)},g.add_event=(e,t)=>{w.events.push({name:e,timestamp:Date.now(),attributes:t||{}})},g.end=()=>{null==w.end&&(w.end=Date.now())};let x=l.get(o);return g.__add_promise=e=>{x.add(e),e.then((()=>x.delete(e)))},p.run([a,g],(()=>g))}function m(e,t){let n=t?.sampler??i,a=t?.context||{};a["service.name"]=e,a["telemetry.sdk.name"]="rian",a["telemetry.sdk.version"]="0.3.0-next.4";let o={root_id:"string"==typeof t?.traceparent?r(t.traceparent):void 0,resource:a,sampler:n};return l.set(a,new Set),{span:e=>p.run([o,null],d,e)}}export{u as currentSpan,c as report,d as span,m as tracer};
|
@@ -1 +1 @@
|
|
1
|
-
var e=r=>{let n=typeof r,a={};return"string"===n?a.stringValue=r:"number"===n?Number.isInteger(r)?a.intValue=r:a.doubleValue=r:"boolean"===n?a.boolValue=r:Array.isArray(r)?a.arrayValue={values:r.map((t=>e(t)))}:r&&(a.kvlistValue={values:t(r)}),a},t=t=>{let r=[];for(let n of Object.keys(t))r.push({key:n,value:e(t[n])});return r},r=e=>{switch(e){default:case"INTERNAL":return 1;case"SERVER":return 2;case"CLIENT":return 3;case"PRODUCER":return 4;case"CONSUMER":return 5}},n=e=>n=>{let a=[];for(let{resource:e,spans:s}of n){let n=[];for(let e of s){let a,{kind:s,error:u,...i}=e.context;u&&(a={code:2},"message"in u&&(a.message=u.message)),n.push({traceId:e.id.trace_id,spanId:e.id.parent_id,parentSpanId:e.parent?.parent_id,name:e.name,kind:r(s||"INTERNAL"),startTimeUnixNano:1e6*e.start,endTimeUnixNano:e.end?1e6*e.end:void 0,droppedAttributesCount:0,droppedEventsCount:0,droppedLinksCount:0,attributes:t(i),status:a||{code:0},events:e.events.map((e=>({name:e.name,attributes:t(e.attributes),droppedAttributesCount:0,timeUnixNano:1e6*e.timestamp})))})}a.push({resource:{attributes:t(e),droppedAttributesCount:0},instrumentationLibrarySpans:[{instrumentationLibrary:{name:"rian",version:"0.3.0-next.
|
1
|
+
var e=r=>{let n=typeof r,a={};return"string"===n?a.stringValue=r:"number"===n?Number.isInteger(r)?a.intValue=r:a.doubleValue=r:"boolean"===n?a.boolValue=r:Array.isArray(r)?a.arrayValue={values:r.map((t=>e(t)))}:r&&(a.kvlistValue={values:t(r)}),a},t=t=>{let r=[];for(let n of Object.keys(t))r.push({key:n,value:e(t[n])});return r},r=e=>{switch(e){default:case"INTERNAL":return 1;case"SERVER":return 2;case"CLIENT":return 3;case"PRODUCER":return 4;case"CONSUMER":return 5}},n=e=>n=>{let a=[];for(let{resource:e,spans:s}of n){let n=[];for(let e of s){let a,{kind:s,error:u,...i}=e.context;u&&(a={code:2},"message"in u&&(a.message=u.message)),n.push({traceId:e.id.trace_id,spanId:e.id.parent_id,parentSpanId:e.parent?.parent_id,name:e.name,kind:r(s||"INTERNAL"),startTimeUnixNano:1e6*e.start,endTimeUnixNano:e.end?1e6*e.end:void 0,droppedAttributesCount:0,droppedEventsCount:0,droppedLinksCount:0,attributes:t(i),status:a||{code:0},events:e.events.map((e=>({name:e.name,attributes:t(e.attributes),droppedAttributesCount:0,timeUnixNano:1e6*e.timestamp})))})}a.push({resource:{attributes:t(e),droppedAttributesCount:0},instrumentationLibrarySpans:[{instrumentationLibrary:{name:"rian",version:"0.3.0-next.4"},spans:n}]})}return e({resourceSpans:a})};exports.exporter=n;
|
@@ -1 +1 @@
|
|
1
|
-
var e=r=>{let n=typeof r,a={};return"string"===n?a.stringValue=r:"number"===n?Number.isInteger(r)?a.intValue=r:a.doubleValue=r:"boolean"===n?a.boolValue=r:Array.isArray(r)?a.arrayValue={values:r.map((t=>e(t)))}:r&&(a.kvlistValue={values:t(r)}),a},t=t=>{let r=[];for(let n of Object.keys(t))r.push({key:n,value:e(t[n])});return r},r=e=>{switch(e){default:case"INTERNAL":return 1;case"SERVER":return 2;case"CLIENT":return 3;case"PRODUCER":return 4;case"CONSUMER":return 5}},n=e=>n=>{let a=[];for(let{resource:e,spans:s}of n){let n=[];for(let e of s){let a,{kind:s,error:u,...i}=e.context;u&&(a={code:2},"message"in u&&(a.message=u.message)),n.push({traceId:e.id.trace_id,spanId:e.id.parent_id,parentSpanId:e.parent?.parent_id,name:e.name,kind:r(s||"INTERNAL"),startTimeUnixNano:1e6*e.start,endTimeUnixNano:e.end?1e6*e.end:void 0,droppedAttributesCount:0,droppedEventsCount:0,droppedLinksCount:0,attributes:t(i),status:a||{code:0},events:e.events.map((e=>({name:e.name,attributes:t(e.attributes),droppedAttributesCount:0,timeUnixNano:1e6*e.timestamp})))})}a.push({resource:{attributes:t(e),droppedAttributesCount:0},instrumentationLibrarySpans:[{instrumentationLibrary:{name:"rian",version:"0.3.0-next.
|
1
|
+
var e=r=>{let n=typeof r,a={};return"string"===n?a.stringValue=r:"number"===n?Number.isInteger(r)?a.intValue=r:a.doubleValue=r:"boolean"===n?a.boolValue=r:Array.isArray(r)?a.arrayValue={values:r.map((t=>e(t)))}:r&&(a.kvlistValue={values:t(r)}),a},t=t=>{let r=[];for(let n of Object.keys(t))r.push({key:n,value:e(t[n])});return r},r=e=>{switch(e){default:case"INTERNAL":return 1;case"SERVER":return 2;case"CLIENT":return 3;case"PRODUCER":return 4;case"CONSUMER":return 5}},n=e=>n=>{let a=[];for(let{resource:e,spans:s}of n){let n=[];for(let e of s){let a,{kind:s,error:u,...i}=e.context;u&&(a={code:2},"message"in u&&(a.message=u.message)),n.push({traceId:e.id.trace_id,spanId:e.id.parent_id,parentSpanId:e.parent?.parent_id,name:e.name,kind:r(s||"INTERNAL"),startTimeUnixNano:1e6*e.start,endTimeUnixNano:e.end?1e6*e.end:void 0,droppedAttributesCount:0,droppedEventsCount:0,droppedLinksCount:0,attributes:t(i),status:a||{code:0},events:e.events.map((e=>({name:e.name,attributes:t(e.attributes),droppedAttributesCount:0,timeUnixNano:1e6*e.timestamp})))})}a.push({resource:{attributes:t(e),droppedAttributesCount:0},instrumentationLibrarySpans:[{instrumentationLibrary:{name:"rian",version:"0.3.0-next.4"},spans:n}]})}return e({resourceSpans:a})};export{n as exporter};
|
package/index.d.ts
CHANGED
@@ -43,15 +43,14 @@ export type Context = {
|
|
43
43
|
* Should return true when you want to sample the span, this is ran before the span is traced — so
|
44
44
|
* decisions is made preemptively.
|
45
45
|
*
|
46
|
-
*
|
47
|
-
* filtered out there.
|
46
|
+
* Returning false will not include this span in the {@link Exporter}.
|
48
47
|
*
|
49
48
|
* Sampling does impact the traceparent, for injection — and is encoded there.
|
50
49
|
*/
|
51
50
|
export type Sampler = (
|
52
|
-
name: string,
|
53
|
-
|
54
|
-
context
|
51
|
+
readonly name: string,
|
52
|
+
readonly id: Traceparent,
|
53
|
+
readonly context: Context,
|
55
54
|
) => boolean;
|
56
55
|
|
57
56
|
// --- spans
|
package/index.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
const { measureFn:e } = require('rian/utils');const t = require('tctx');var n=(e,n)
|
1
|
+
const { measureFn:e } = require('rian/utils');const { make:t, parse:n, SAMPLED_FLAG:a } = require('tctx');const { is_sampled:r } = require('tctx');var o=new Set,s=new WeakMap;async function l(e){let t=[],n=new Map;for(let[e,a]of o){let r;n.has(a)?r=n.get(a).spans:n.set(a,{resource:a,spans:r=new Set}),r.add(e),s.has(a)&&(t.push(...s.get(a)),s.delete(a))}return o.clear(),t.length&&await Promise.all(t),e(n.values())}function i(e,t){return r(t)}function d(a,r){let l=r?.sampler??i,d=r?.context||{};d["service.name"]=a,d["telemetry.sdk.name"]="rian",d["telemetry.sdk.version"]="0.3.0-next.4";let p=new Set;s.set(d,p);let c="string"==typeof r?.traceparent?n(r.traceparent):void 0,m=(n,a)=>{let r=a?a.child():t(),s="boolean"!=typeof l?l(n,r,d):l;r.flags;let i={id:r,parent:a,start:Date.now(),name:n,events:[],context:{}};s&&o.add([i,d]);let c=t=>e(c,t);return c.traceparent=r,c.span=e=>m(e,r),c.set_context=e=>"function"==typeof e?void(i.context=e(i.context)):void Object.assign(i.context,e),c.add_event=(e,t)=>{i.events.push({name:e,timestamp:Date.now(),attributes:t||{}})},c.end=()=>{null==i.end&&(i.end=Date.now())},c.__add_promise=e=>{p.add(e),e.then((()=>p.delete(e)))},c};return{span:e=>m(e,c)}}exports.report=l;exports.tracer=d;
|
package/index.mjs
CHANGED
@@ -1 +1 @@
|
|
1
|
-
import{measureFn as e}from"rian/utils";import
|
1
|
+
import{measureFn as e}from"rian/utils";import{make as t,parse as n,SAMPLED_FLAG as a}from"tctx";import{is_sampled as r}from"tctx";var o=new Set,s=new WeakMap;async function l(e){let t=[],n=new Map;for(let[e,a]of o){let r;n.has(a)?r=n.get(a).spans:n.set(a,{resource:a,spans:r=new Set}),r.add(e),s.has(a)&&(t.push(...s.get(a)),s.delete(a))}return o.clear(),t.length&&await Promise.all(t),e(n.values())}function i(e,t){return r(t)}function d(a,r){let l=r?.sampler??i,d=r?.context||{};d["service.name"]=a,d["telemetry.sdk.name"]="rian",d["telemetry.sdk.version"]="0.3.0-next.4";let p=new Set;s.set(d,p);let c="string"==typeof r?.traceparent?n(r.traceparent):void 0,m=(n,a)=>{let r=a?a.child():t(),s="boolean"!=typeof l?l(n,r,d):l;r.flags;let i={id:r,parent:a,start:Date.now(),name:n,events:[],context:{}};s&&o.add([i,d]);let c=t=>e(c,t);return c.traceparent=r,c.span=e=>m(e,r),c.set_context=e=>"function"==typeof e?void(i.context=e(i.context)):void Object.assign(i.context,e),c.add_event=(e,t)=>{i.events.push({name:e,timestamp:Date.now(),attributes:t||{}})},c.end=()=>{null==i.end&&(i.end=Date.now())},c.__add_promise=e=>{p.add(e),e.then((()=>p.delete(e)))},c};return{span:e=>m(e,c)}}export{l as report,d as tracer};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "rian",
|
3
|
-
"version": "0.3.0-next.
|
3
|
+
"version": "0.3.0-next.4",
|
4
4
|
"description": "Effective tracing for the edge and origins",
|
5
5
|
"keywords": [
|
6
6
|
"opentelemetry",
|
@@ -25,20 +25,25 @@
|
|
25
25
|
"import": "./index.mjs",
|
26
26
|
"require": "./index.js"
|
27
27
|
},
|
28
|
+
"./async": {
|
29
|
+
"types": "./async.d.ts",
|
30
|
+
"import": "./async.mjs",
|
31
|
+
"require": "./async.js"
|
32
|
+
},
|
28
33
|
"./exporter.otel.http": {
|
29
|
-
"types": "./exporter.otel.http
|
30
|
-
"import": "./exporter.otel.http
|
31
|
-
"require": "./exporter.otel.http
|
34
|
+
"types": "./exporter.otel.http.d.ts",
|
35
|
+
"import": "./exporter.otel.http.mjs",
|
36
|
+
"require": "./exporter.otel.http.js"
|
32
37
|
},
|
33
38
|
"./exporter.zipkin": {
|
34
|
-
"types": "./exporter.zipkin
|
35
|
-
"import": "./exporter.zipkin
|
36
|
-
"require": "./exporter.zipkin
|
39
|
+
"types": "./exporter.zipkin.d.ts",
|
40
|
+
"import": "./exporter.zipkin.mjs",
|
41
|
+
"require": "./exporter.zipkin.js"
|
37
42
|
},
|
38
43
|
"./utils": {
|
39
|
-
"types": "./utils
|
40
|
-
"import": "./utils
|
41
|
-
"require": "./utils
|
44
|
+
"types": "./utils.d.ts",
|
45
|
+
"import": "./utils.mjs",
|
46
|
+
"require": "./utils.js"
|
42
47
|
},
|
43
48
|
"./package.json": "./package.json"
|
44
49
|
},
|
@@ -49,6 +54,7 @@
|
|
49
54
|
"*.mjs",
|
50
55
|
"*.js",
|
51
56
|
"*.d.ts",
|
57
|
+
"!global.d.ts",
|
52
58
|
"exporter.*/*",
|
53
59
|
"utils/*"
|
54
60
|
],
|
package/readme.md
CHANGED
@@ -28,7 +28,7 @@
|
|
28
28
|
|
29
29
|
- 🤔 **Familiar** — looks very much like OpenTracing.
|
30
30
|
|
31
|
-
- ✅ **Simple** — `create` a tracer, and
|
31
|
+
- ✅ **Simple** — `create` a tracer, and `report()`, done.
|
32
32
|
|
33
33
|
- 🏎 **Performant** — check the [benchmarks](#-benchmark).
|
34
34
|
|
@@ -39,7 +39,7 @@
|
|
39
39
|
> Visit [/examples](/examples) for more info!
|
40
40
|
|
41
41
|
```ts
|
42
|
-
import { create } from 'rian';
|
42
|
+
import { create, report } from 'rian';
|
43
43
|
import { measure } from 'rian/utils';
|
44
44
|
import { exporter } from 'rian/exporter.otel.http';
|
45
45
|
|
@@ -52,9 +52,7 @@ const otel_endpoint = exporter((payload) =>
|
|
52
52
|
);
|
53
53
|
|
54
54
|
// ~> Create a tracer — typically "per request" or "per operation"
|
55
|
-
const tracer = create('my-service'
|
56
|
-
exporter: otel_endpoint,
|
57
|
-
});
|
55
|
+
const tracer = create('my-service');
|
58
56
|
|
59
57
|
// Let us trace
|
60
58
|
|
@@ -80,7 +78,7 @@ span.end();
|
|
80
78
|
req.end();
|
81
79
|
|
82
80
|
// ~> And finally let's export — will also end the root span.
|
83
|
-
await
|
81
|
+
await report(otel_endpoint);
|
84
82
|
|
85
83
|
/*
|
86
84
|
And we end up with something like this in our reporting tool:
|
@@ -114,7 +112,7 @@ Implements the OpenTelemetry protocol for use with http transports.
|
|
114
112
|
<details><summary>NewRelic</summary>
|
115
113
|
|
116
114
|
```ts
|
117
|
-
import { create } from 'rian';
|
115
|
+
import { create, report } from 'rian';
|
118
116
|
import { exporter } from 'rian/exporter.zipkin';
|
119
117
|
|
120
118
|
const newrelic = exporter((payload) =>
|
@@ -130,9 +128,9 @@ const newrelic = exporter((payload) =>
|
|
130
128
|
}),
|
131
129
|
);
|
132
130
|
|
133
|
-
const tracer = create('my-service'
|
134
|
-
|
135
|
-
|
131
|
+
const tracer = create('my-service');
|
132
|
+
|
133
|
+
await report(newrelic);
|
136
134
|
```
|
137
135
|
|
138
136
|
[learn more](https://docs.newrelic.com/docs/distributed-tracing/trace-api/introduction-trace-api/)
|
@@ -142,7 +140,7 @@ const tracer = create('my-service', {
|
|
142
140
|
<details><summary>LightStep</summary>
|
143
141
|
|
144
142
|
```ts
|
145
|
-
import { create } from 'rian';
|
143
|
+
import { create, report } from 'rian';
|
146
144
|
import { exporter } from 'rian/exporter.otel.http';
|
147
145
|
|
148
146
|
const lightstep = exporter((payload) =>
|
@@ -156,9 +154,9 @@ const lightstep = exporter((payload) =>
|
|
156
154
|
}),
|
157
155
|
);
|
158
156
|
|
159
|
-
const tracer = create('my-service'
|
160
|
-
|
161
|
-
|
157
|
+
const tracer = create('my-service');
|
158
|
+
|
159
|
+
await report(lightstep);
|
162
160
|
```
|
163
161
|
|
164
162
|
[learn more](https://opentelemetry.lightstep.com/tracing/)
|
package/global.d.ts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
declare const RIAN_VERSION: string;
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|