rian 0.3.0-next.2 → 0.3.0-next.3

Sign up to get free protection for your applications and to get access to all the features.
package/async.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ import type { CallableScope, Scope, Span } from 'rian';
2
+
3
+ export function currentSpan(): Scope | null;
4
+ export function span(name: string): CallableScope;
5
+
6
+ export { tracer, report } from 'rian';
package/async.js ADDED
@@ -0,0 +1 @@
1
+ const { AsyncLocalStorage:e } = require('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 i(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 c(e,t){return o(t)}var p=new e;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,i=r[1],c=a.sampler,u=i?.traceparent??a.root_id,m=u?u.child():n(),f="boolean"!=typeof c?c(e,m,o):c;m.flags;let w={id:m,parent:u,start:Date.now(),name:e,events:[],context:{}};f&&s.add([w,o]);let x=e=>p.run([a,x],t,x,e);x.traceparent=m,x.span=d,x.set_context=e=>{"function"!=typeof e?Object.assign(w.context,e):w.context=e(w.context)},x.add_event=(e,t)=>{w.events.push({name:e,timestamp:Date.now(),attributes:t||{}})},x.end=()=>{null==w.end&&(w.end=Date.now())};let g=l.get(o);return x.__add_promise=e=>{g.add(e),e.then((()=>g.delete(e)))},p.run([a,x],(()=>x))}function m(e,t){let n=t?.sampler??c,a=t?.context||{};a["service.name"]=e,a["telemetry.sdk.name"]="rian",a["telemetry.sdk.version"]="0.3.0-next.3";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=i;exports.span=d;exports.tracer=m;
package/async.mjs ADDED
@@ -0,0 +1 @@
1
+ import{AsyncLocalStorage as e}from"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 i(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 c(e,t){return o(t)}var p=new e;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,i=r[1],c=a.sampler,u=i?.traceparent??a.root_id,m=u?u.child():n(),f="boolean"!=typeof c?c(e,m,o):c;m.flags;let w={id:m,parent:u,start:Date.now(),name:e,events:[],context:{}};f&&s.add([w,o]);let x=e=>p.run([a,x],t,x,e);x.traceparent=m,x.span=d,x.set_context=e=>{"function"!=typeof e?Object.assign(w.context,e):w.context=e(w.context)},x.add_event=(e,t)=>{w.events.push({name:e,timestamp:Date.now(),attributes:t||{}})},x.end=()=>{null==w.end&&(w.end=Date.now())};let g=l.get(o);return x.__add_promise=e=>{g.add(e),e.then((()=>g.delete(e)))},p.run([a,x],(()=>x))}function m(e,t){let n=t?.sampler??c,a=t?.context||{};a["service.name"]=e,a["telemetry.sdk.name"]="rian",a["telemetry.sdk.version"]="0.3.0-next.3";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,i 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.2"},spans:n}]})}return e({resourceSpans:a})};exports.exporter=n;
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.3"},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.2"},spans:n}]})}return e({resourceSpans:a})};export{n as exporter};
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.3"},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
- * The Span itself will still be included in the {@link Options.exporter|exporter}, and can be
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
- parentId?: Traceparent,
54
- context?: 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)=>!n||t.is_sampled(n),a=new Set,r=new WeakMap;function s(s,o){let l=o?.sampler||n,d="boolean"!=typeof l,i=o?.context||{};i["service.name"]=s,i["telemetry.sdk.name"]="rian",i["telemetry.sdk.version"]="0.3.0-next.2";let p=new Set;r.set(i,p);let c="string"==typeof o?.traceparent?t.parse(o.traceparent):void 0,m=(n,r)=>{let s=d?l(n,r,i):l,o=r?r.child(s):t.make(s),c={id:o,parent:r,start:Date.now(),name:n,events:[],context:{}};s&&a.add([c,i]);let u=t=>e(u,t);return u.traceparent=o,u.span=e=>m(e,o),u.set_context=e=>"function"==typeof e?void(c.context=e(c.context)):void Object.assign(c.context,e),u.add_event=(e,t)=>{c.events.push({name:e,timestamp:Date.now(),attributes:t||{}})},u.end=()=>{null==c.end&&(c.end=Date.now())},u.__add_promise=e=>{p.add(e),e.then((()=>p.delete(e)))},u};return{span:e=>m(e,c)}}async function o(e){let t=[],n=new Map;for(let[e,s]of a){let a;n.has(s)?a=n.get(s).spans:n.set(s,{resource:s,spans:a=new Set}),a.add(e),r.has(s)&&(t.push(...r.get(s)),r.delete(s))}return a.clear(),t.length&&await Promise.all(t),e(n.values())}exports.report=o;exports.tracer=s;
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.3";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*as t from"tctx";var n=(e,n)=>!n||t.is_sampled(n),a=new Set,r=new WeakMap;function s(s,o){let l=o?.sampler||n,d="boolean"!=typeof l,i=o?.context||{};i["service.name"]=s,i["telemetry.sdk.name"]="rian",i["telemetry.sdk.version"]="0.3.0-next.2";let p=new Set;r.set(i,p);let c="string"==typeof o?.traceparent?t.parse(o.traceparent):void 0,m=(n,r)=>{let s=d?l(n,r,i):l,o=r?r.child(s):t.make(s),c={id:o,parent:r,start:Date.now(),name:n,events:[],context:{}};s&&a.add([c,i]);let u=t=>e(u,t);return u.traceparent=o,u.span=e=>m(e,o),u.set_context=e=>"function"==typeof e?void(c.context=e(c.context)):void Object.assign(c.context,e),u.add_event=(e,t)=>{c.events.push({name:e,timestamp:Date.now(),attributes:t||{}})},u.end=()=>{null==c.end&&(c.end=Date.now())},u.__add_promise=e=>{p.add(e),e.then((()=>p.delete(e)))},u};return{span:e=>m(e,c)}}async function o(e){let t=[],n=new Map;for(let[e,s]of a){let a;n.has(s)?a=n.get(s).spans:n.set(s,{resource:s,spans:a=new Set}),a.add(e),r.has(s)&&(t.push(...r.get(s)),r.delete(s))}return a.clear(),t.length&&await Promise.all(t),e(n.values())}export{o as report,s as tracer};
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.3";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.2",
3
+ "version": "0.3.0-next.3",
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/index.d.ts",
30
- "import": "./exporter.otel.http/index.mjs",
31
- "require": "./exporter.otel.http/index.js"
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/index.d.ts",
35
- "import": "./exporter.zipkin/index.mjs",
36
- "require": "./exporter.zipkin/index.js"
39
+ "types": "./exporter.zipkin.d.ts",
40
+ "import": "./exporter.zipkin.mjs",
41
+ "require": "./exporter.zipkin.js"
37
42
  },
38
43
  "./utils": {
39
- "types": "./utils/index.d.ts",
40
- "import": "./utils/index.mjs",
41
- "require": "./utils/index.js"
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 `.report()` a tracer, done.
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 tracer.report();
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
- exporter: newrelic,
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
- exporter: lightstep,
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