rian 0.2.4 → 0.3.0-next.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1 +1 @@
1
- const { name:e, version:t } = require('rian/package.json');var r=e=>{let t=typeof e,n={};return"string"===t?n.stringValue=e:"number"===t?Number.isInteger(e)?n.intValue=e:n.doubleValue=e:"boolean"===t?n.boolValue=e:Array.isArray(e)?n.arrayValue={values:e.map((e=>r(e)))}:e&&(n.kvlistValue={values:a(e)}),n},a=e=>{let t=[];for(let a of Object.keys(e))t.push({key:a,value:r(e[a])});return t},n=e=>{switch(e){default:case"INTERNAL":return 1;case"SERVER":return 2;case"CLIENT":return 3;case"PRODUCER":return 4;case"CONSUMER":return 5}},s=r=>(s,i)=>{let u=[];for(let e of s){let t,{kind:r,error:s,...i}=e.context;s&&(t={code:2},"message"in s&&(t.message=s.message)),u.push({traceId:e.id.trace_id,spanId:e.id.parent_id,parentSpanId:e.parent?.parent_id,name:e.name,kind:n(r||"INTERNAL"),startTimeUnixNano:1e6*e.start,endTimeUnixNano:e.end?1e6*e.end:void 0,droppedAttributesCount:0,droppedEventsCount:0,droppedLinksCount:0,attributes:a(i),status:t||{code:0},events:e.events.map((e=>({name:e.name,attributes:a(e.attributes),droppedAttributesCount:0,timeUnixNano:1e6*e.timestamp})))})}return r({resourceSpans:[{resource:{attributes:a(i),droppedAttributesCount:0},instrumentationLibrarySpans:[{instrumentationLibrary:{name:e,version:t},spans:u}]}]})};exports.exporter=s;
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 +1 @@
1
- import{name as e,version as t}from"rian/package.json";var r=e=>{let t=typeof e,n={};return"string"===t?n.stringValue=e:"number"===t?Number.isInteger(e)?n.intValue=e:n.doubleValue=e:"boolean"===t?n.boolValue=e:Array.isArray(e)?n.arrayValue={values:e.map((e=>r(e)))}:e&&(n.kvlistValue={values:a(e)}),n},a=e=>{let t=[];for(let a of Object.keys(e))t.push({key:a,value:r(e[a])});return t},n=e=>{switch(e){default:case"INTERNAL":return 1;case"SERVER":return 2;case"CLIENT":return 3;case"PRODUCER":return 4;case"CONSUMER":return 5}},s=r=>(s,i)=>{let u=[];for(let e of s){let t,{kind:r,error:s,...i}=e.context;s&&(t={code:2},"message"in s&&(t.message=s.message)),u.push({traceId:e.id.trace_id,spanId:e.id.parent_id,parentSpanId:e.parent?.parent_id,name:e.name,kind:n(r||"INTERNAL"),startTimeUnixNano:1e6*e.start,endTimeUnixNano:e.end?1e6*e.end:void 0,droppedAttributesCount:0,droppedEventsCount:0,droppedLinksCount:0,attributes:a(i),status:t||{code:0},events:e.events.map((e=>({name:e.name,attributes:a(e.attributes),droppedAttributesCount:0,timeUnixNano:1e6*e.timestamp})))})}return r({resourceSpans:[{resource:{attributes:a(i),droppedAttributesCount:0},instrumentationLibrarySpans:[{instrumentationLibrary:{name:e,version:t},spans:u}]}]})};export{s 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.2"},spans:n}]})}return e({resourceSpans:a})};export{n as exporter};
@@ -1 +1 @@
1
- const { flattie:e } = require('flattie');var t=t=>(a,n)=>{let r=[];for(let t of a){let{kind:a,error:i,...s}=t.context;i&&(s.error=!("message"in i)||{name:i.name,message:i.message,stack:i.stack}),r.push({id:t.id.parent_id,traceId:t.id.trace_id,parentId:t.parent?t.parent.parent_id:void 0,name:t.name,kind:"INTERNAL"===a?void 0:a,timestamp:1e3*t.start,duration:t.end?1e3*(t.end-t.start):void 0,localEndpoint:n.localEndpoint||{serviceName:s["service.name"]},tags:e({...n,...s},".",!0),annotations:t.events.map((e=>({value:`${e.name} :: ${JSON.stringify(e.attributes)}`,timestamp:1e3*e.timestamp})))})}return t(r)};exports.exporter=t;
1
+ const { flattie:e } = require('flattie');var t=t=>a=>{let r=[];for(let t of a)for(let a of t.spans){let{kind:n,error:i,...s}=a.context;i&&(s.error=!("message"in i)||{name:i.name,message:i.message,stack:i.stack}),r.push({id:a.id.parent_id,traceId:a.id.trace_id,parentId:a.parent?a.parent.parent_id:void 0,name:a.name,kind:"INTERNAL"===n?void 0:n,timestamp:1e3*a.start,duration:a.end?1e3*(a.end-a.start):void 0,localEndpoint:{serviceName:t.resource["service.name"]},tags:e({...t.resource,...s},".",!0),annotations:a.events.map((e=>({value:`${e.name} :: ${JSON.stringify(e.attributes)}`,timestamp:1e3*e.timestamp})))})}return t(r)};exports.exporter=t;
@@ -1 +1 @@
1
- import{flattie as e}from"flattie";var t=t=>(a,n)=>{let r=[];for(let t of a){let{kind:a,error:i,...s}=t.context;i&&(s.error=!("message"in i)||{name:i.name,message:i.message,stack:i.stack}),r.push({id:t.id.parent_id,traceId:t.id.trace_id,parentId:t.parent?t.parent.parent_id:void 0,name:t.name,kind:"INTERNAL"===a?void 0:a,timestamp:1e3*t.start,duration:t.end?1e3*(t.end-t.start):void 0,localEndpoint:n.localEndpoint||{serviceName:s["service.name"]},tags:e({...n,...s},".",!0),annotations:t.events.map((e=>({value:`${e.name} :: ${JSON.stringify(e.attributes)}`,timestamp:1e3*e.timestamp})))})}return t(r)};export{t as exporter};
1
+ import{flattie as e}from"flattie";var t=t=>a=>{let r=[];for(let t of a)for(let a of t.spans){let{kind:n,error:i,...s}=a.context;i&&(s.error=!("message"in i)||{name:i.name,message:i.message,stack:i.stack}),r.push({id:a.id.parent_id,traceId:a.id.trace_id,parentId:a.parent?a.parent.parent_id:void 0,name:a.name,kind:"INTERNAL"===n?void 0:n,timestamp:1e3*a.start,duration:a.end?1e3*(a.end-a.start):void 0,localEndpoint:{serviceName:t.resource["service.name"]},tags:e({...t.resource,...s},".",!0),annotations:a.events.map((e=>({value:`${e.name} :: ${JSON.stringify(e.attributes)}`,timestamp:1e3*e.timestamp})))})}return t(r)};export{t as exporter};
package/global.d.ts ADDED
@@ -0,0 +1 @@
1
+ declare const RIAN_VERSION: string;
package/index.d.ts CHANGED
@@ -1,3 +1,61 @@
1
+ import type { Traceparent } from 'tctx';
2
+
3
+ // --- tracer
4
+
5
+ /**
6
+ * An exporter is a method called when the parent scope ends, gets given a Set of all spans traced
7
+ * during this execution.
8
+ */
9
+ export type Exporter = (resources: IterableIterator<Resource>) => any;
10
+
11
+ export type Resource = {
12
+ resource: Context;
13
+ spans: ReadonlySet<Readonly<Span>>;
14
+ };
15
+
16
+ export type Options = {
17
+ /**
18
+ * @borrows {@link Sampler}
19
+ */
20
+ sampler?: Sampler | boolean;
21
+
22
+ context?: Context;
23
+
24
+ /**
25
+ * A root, or extracted w3c traceparent stringed header.
26
+ *
27
+ * If the id is malformed, the {@link create} method will throw an exception. If no root is
28
+ * provided then one will be created obeying the {@link Options.sampler|sampling} rules.
29
+ */
30
+ traceparent?: string | null;
31
+ };
32
+
33
+ export type Tracer = Pick<Scope, 'span'>;
34
+
35
+ /**
36
+ * @borrows {@link Span.context}
37
+ */
38
+ export type Context = {
39
+ [property: string]: any;
40
+ };
41
+
42
+ /**
43
+ * Should return true when you want to sample the span, this is ran before the span is traced — so
44
+ * decisions is made preemptively.
45
+ *
46
+ * The Span itself will still be included in the {@link Options.exporter|exporter}, and can be
47
+ * filtered out there.
48
+ *
49
+ * Sampling does impact the traceparent, for injection — and is encoded there.
50
+ */
51
+ export type Sampler = (
52
+ name: string,
53
+ parentId?: Traceparent,
54
+ context?: Context,
55
+ ) => boolean;
56
+
57
+ // --- spans
58
+
1
59
  /**
2
60
  * Spans are units within a distributed trace. Spans encapsulate mainly 3 pieces of information, a
3
61
  * {@link Span.name|name}, and a {@link Span.start|start} and {@link Span.end|end} time.
@@ -18,7 +76,7 @@
18
76
  * Spans are aimed to interoperate with
19
77
  * {@link https://github.com/opentracing/specification/blob/master/specification.md|OpenTracing's Spans}, albeit not entirely api compatible — they do share principles.
20
78
  */
21
- export interface Span {
79
+ export type Span = {
22
80
  /**
23
81
  * A human-readable name for this span. For example the function name, the name of a subtask,
24
82
  * or stage of the larger stack.
@@ -82,9 +140,11 @@ export interface Span {
82
140
  * new span.
83
141
  */
84
142
  events: { name: string; timestamp: number; attributes: Context }[];
85
- }
143
+ };
86
144
 
87
- export interface Scope {
145
+ // --- scopes
146
+
147
+ export type Scope = {
88
148
  /**
89
149
  * A W3C traceparent. One can .toString() this if you want to cross a network.
90
150
  */
@@ -93,7 +153,7 @@ export interface Scope {
93
153
  /**
94
154
  * Forks the span into a new child span.
95
155
  */
96
- fork(name: string): CallableScope;
156
+ span(name: string): CallableScope;
97
157
 
98
158
  /**
99
159
  * Allows the span's context to be set. Passing an object will be `Object.assign`ed into the
@@ -114,70 +174,19 @@ export interface Scope {
114
174
  * timestamp nulled out — when the tracer ends.
115
175
  */
116
176
  end(): void;
117
- }
177
+ };
118
178
 
119
- export interface Tracer extends Omit<Scope, 'end'> {
120
- end(): ReturnType<Exporter>;
121
- }
179
+ export type CallableScope = Scope & {
180
+ (cb: (scope: Omit<Scope, 'end'>) => void): ReturnType<typeof cb>;
181
+ };
122
182
 
123
- /**
124
- * An exporter is a method called when the parent scope ends, gets given a Set of all spans traced
125
- * during this execution.
126
- */
127
- export type Exporter = (
128
- spans: ReadonlySet<Readonly<Span>>,
129
- context: Context,
130
- ) => any;
183
+ // --- main api
131
184
 
132
- /**
133
- * @borrows {@link Span.context}
134
- */
135
- export interface Context {
136
- [property: string]: any;
137
- }
185
+ export function tracer(name: string, options?: Options): Tracer;
138
186
 
139
187
  /**
140
- * Should return true when you want to sample the span, this is ran before the span is traced — so
141
- * decisions is made preemptively.
142
- *
143
- * The Span itself will still be included in the {@link Options.exporter|exporter}, and can be
144
- * filtered out there.
145
- *
146
- * Sampling does impact the traceparent, for injection — and is encoded there.
188
+ * Awaits all active promises, and then calls the {@link Options.exporter|exporter}. Passing all collected spans.
147
189
  */
148
- export type Sampler = (
149
- name: string,
150
- parentId?: Traceparent,
151
- context?: Context,
152
- ) => boolean;
153
-
154
- export interface Options {
155
- /**
156
- * @borrows {@link Exporter}
157
- */
158
- exporter: Exporter;
159
-
160
- /**
161
- * @borrows {@link Sampler}
162
- */
163
- sampler?: Sampler | boolean;
164
-
165
- context?: Context;
166
-
167
- /**
168
- * A root, or extracted w3c traceparent stringed header.
169
- *
170
- * If the id is malformed, the {@link create} method will throw an exception. If no root is
171
- * provided then one will be created obeying the {@link Options.sampler|sampling} rules.
172
- */
173
- traceparent?: string | null;
174
- }
175
-
176
- export const create: (name: string, options: Options) => Tracer;
177
-
178
- // ==> internals
179
-
180
- /** @internal */
181
- export interface CallableScope extends Scope {
182
- (cb: (scope: Omit<Scope, 'end'>) => void): ReturnType<typeof cb>;
183
- }
190
+ export async function report<T extends Exporter>(
191
+ exporter: T,
192
+ ): Promise<ReturnType<T>>;
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={"telemetry.sdk.name":"rian","telemetry.sdk.version":"0.2.4"},r=(r,o)=>{let s=new Set,d=new Set,i=o.sampler||n,p="boolean"!=typeof i,m=(n,a)=>{let r=p?i(n,a,o.context):i,c=a?a.child(r):t.make(r),l={id:c,parent:a,start:Date.now(),name:n,events:[],context:{}};r&&s.add(l);let x=t=>e(x,t);return x.traceparent=c,x.fork=e=>m(e,c),x.set_context=e=>{"function"!=typeof e?Object.assign(l.context,e):l.context=e(l.context)},x.add_event=(e,t)=>{l.events.push({name:e,timestamp:Date.now(),attributes:t||{}})},x.end=()=>{null==l.end&&(l.end=Date.now())},x.__add_promise=d.add.bind(d),x},c=m(r,"string"==typeof o.traceparent?t.parse(o.traceparent):void 0),l=c.end.bind(c);return c.end=async()=>(l(),d.size>0&&await Promise.all([...d.values()]),o.exporter(s,{...o.context||{},...a})),c};exports.create=r;
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;
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={"telemetry.sdk.name":"rian","telemetry.sdk.version":"0.2.4"},r=(r,o)=>{let s=new Set,d=new Set,i=o.sampler||n,p="boolean"!=typeof i,m=(n,a)=>{let r=p?i(n,a,o.context):i,c=a?a.child(r):t.make(r),l={id:c,parent:a,start:Date.now(),name:n,events:[],context:{}};r&&s.add(l);let x=t=>e(x,t);return x.traceparent=c,x.fork=e=>m(e,c),x.set_context=e=>{"function"!=typeof e?Object.assign(l.context,e):l.context=e(l.context)},x.add_event=(e,t)=>{l.events.push({name:e,timestamp:Date.now(),attributes:t||{}})},x.end=()=>{null==l.end&&(l.end=Date.now())},x.__add_promise=d.add.bind(d),x},c=m(r,"string"==typeof o.traceparent?t.parse(o.traceparent):void 0),l=c.end.bind(c);return c.end=async()=>(l(),d.size>0&&await Promise.all([...d.values()]),o.exporter(s,{...o.context||{},...a})),c};export{r as create};
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};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rian",
3
- "version": "0.2.4",
3
+ "version": "0.3.0-next.2",
4
4
  "description": "Effective tracing for the edge and origins",
5
5
  "keywords": [
6
6
  "opentelemetry",
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 `.end()` a tracer, done.
31
+ - ✅ **Simple** — `create` a tracer, and `.report()` a tracer, done.
32
32
 
33
33
  - 🏎 **Performant** — check the [benchmarks](#-benchmark).
34
34
 
@@ -52,21 +52,23 @@ const otel_endpoint = exporter((payload) =>
52
52
  );
53
53
 
54
54
  // ~> Create a tracer — typically "per request" or "per operation"
55
- const tracer = create('GET ~> /data', {
55
+ const tracer = create('my-service', {
56
56
  exporter: otel_endpoint,
57
57
  });
58
58
 
59
59
  // Let us trace
60
60
 
61
- tracer.set_context({
61
+ const req = tracer.span('GET ~> /data');
62
+
63
+ req.set_context({
62
64
  user: request_context.user_id,
63
65
  });
64
66
 
65
67
  // ~> Wrap any method and be timed 🕺🏻
66
- const data = await measure(tracer.fork('db::read'), get_data);
68
+ const data = await measure(req.span('db::read'), get_data);
67
69
 
68
70
  // ~> Maybe have some in-flow spanning
69
- const span = tracer.span('process records');
71
+ const span = req.span('process records');
70
72
 
71
73
  for (let row of data) {
72
74
  span.add_event('doing stuff', { id: row.id });
@@ -75,8 +77,10 @@ for (let row of data) {
75
77
 
76
78
  span.end();
77
79
 
80
+ req.end();
81
+
78
82
  // ~> And finally let's export — will also end the root span.
79
- await tracer.end();
83
+ await tracer.report();
80
84
 
81
85
  /*
82
86
  And we end up with something like this in our reporting tool:
@@ -101,50 +105,10 @@ The main and _default_ module responsible for creating and provisioning spans.
101
105
 
102
106
  Exports the spans created using the zipkin protocol and leaves the shipping up to you.
103
107
 
104
- > 💡 Note ~> with the nature of zipkin, the `localEndpoint` must be set in your span context.
105
- >
106
- > <details><summary>Example</summary>
107
- >
108
- > ```ts
109
- > const tracer = create('example', {
110
- > context: {
111
- > localEndpoint: {
112
- > serviceName: 'my-service', // 👈 important part
113
- > },
114
- > },
115
- > });
116
- > ```
117
- >
118
- > Both of these are functionally equivalent. `service.name` will be used if no `localEndpoint.serviceName` is set.
119
- >
120
- > ```ts
121
- > const tracer = create('example', {
122
- > context: {
123
- > 'service.name': 'my-service',
124
- > },
125
- > });
126
- > ```
127
- >
128
- > </details>
129
-
130
108
  #### Module: [`rian/exporter.otel.http`](./packages/rian/src/exporter.otel.http.ts)
131
109
 
132
110
  Implements the OpenTelemetry protocol for use with http transports.
133
111
 
134
- > 💡 Note ~> services require a `service.name` context value.
135
- >
136
- > <details><summary>Example</summary>
137
- >
138
- > ```ts
139
- > const tracer = create('example', {
140
- > context: {
141
- > 'service.name': 'my-service', // 👈 important part
142
- > },
143
- > });
144
- > ```
145
- >
146
- > </details>
147
-
148
112
  ## 🧑‍🍳 Exporter Recipes
149
113
 
150
114
  <details><summary>NewRelic</summary>
@@ -166,10 +130,7 @@ const newrelic = exporter((payload) =>
166
130
  }),
167
131
  );
168
132
 
169
- const tracer = create('example', {
170
- context: {
171
- 'service.name': 'my-service', // 👈 important part
172
- },
133
+ const tracer = create('my-service', {
173
134
  exporter: newrelic,
174
135
  });
175
136
  ```
@@ -195,10 +156,7 @@ const lightstep = exporter((payload) =>
195
156
  }),
196
157
  );
197
158
 
198
- const tracer = create('example', {
199
- context: {
200
- 'service.name': 'my-service', // 👈 important part
201
- },
159
+ const tracer = create('my-service', {
202
160
  exporter: lightstep,
203
161
  });
204
162
  ```
@@ -246,23 +204,18 @@ Rian is still in active development, but ready for production!
246
204
  Validation :: single span
247
205
  ✔ rian
248
206
  ✔ opentelemetry
249
- ✔ opentracing
250
207
 
251
208
  Benchmark :: single span
252
- rian x 137,181 ops/sec ±2.82% (82 runs sampled)
253
- opentelemetry x 114,197 ops/sec ±11.37% (75 runs sampled)
254
- opentracing x 33,363 ops/sec ±1.27% (89 runs sampled)
209
+ rian x 385,085 ops/sec ±4.26% (85 runs sampled)
210
+ opentelemetry x 205,004 ops/sec ±11.99% (65 runs sampled)
255
211
 
256
212
  Validation :: child span
257
213
  ✔ rian
258
214
  ✔ opentelemetry
259
- ✔ opentracing
260
215
 
261
216
  Benchmark :: child span
262
- rian x 75,567 ops/sec ±7.95% (77 runs sampled)
263
- opentelemetry x 65,618 ops/sec ±8.45% (82 runs sampled)
264
- opentracing x 15,452 ops/sec ±15.35% (77 runs sampled)
265
-
217
+ rian x 206,736 ops/sec ±6.37% (86 runs sampled)
218
+ opentelemetry x 128,298 ops/sec ±14.82% (68 runs sampled)
266
219
  ```
267
220
 
268
221
  > And please... I know these results are anything but the full story. But it's a number and point on comparison.
package/utils/index.d.ts CHANGED
@@ -17,20 +17,19 @@ export type MeasureFn =
17
17
  * @example
18
18
  *
19
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
20
+ * const data = await measure(scope, get_data, 'user_id_123');
21
+ * ^ ^ ^ ^
22
+ * | | | |
23
+ * | | | the first argument to get_data
24
+ * | | |
25
+ * | | function to be called
26
+ * | |
27
+ * | the parent scope
28
+ * return value from get_data
29
29
  * ```
30
30
  */
31
31
  export const measure: <Fn extends MeasureFn>(
32
32
  scope: Scope,
33
- name: string,
34
33
  fn: Fn, // TODO: fn doesnt see scope correctly
35
34
  ...args: RealMeasureFnParams<Parameters<Fn>>
36
35
  ) => ReturnType<Fn>;
@@ -51,7 +50,6 @@ export const measure: <Fn extends MeasureFn>(
51
50
  */
52
51
  export const wrap: <Fn extends MeasureFn>(
53
52
  scope: Scope,
54
- name: string,
55
53
  fn: Fn, // TODO: fn doesnt see scope correctly
56
54
  ) => Fn;
57
55
 
package/utils/index.js CHANGED
@@ -1 +1 @@
1
- var r=(r,t,...e)=>{try{var n=t(...e,r),o=n instanceof Promise;return o&&r.__add_promise(n.catch((t=>{r.set_context({error:t})})).finally((()=>r.end()))),n}catch(t){throw t instanceof Error&&r.set_context({error:t}),t}finally{!0!==o&&r.end()}},t=(t,e,n,...o)=>r(t.fork(e),n,...o),e=(t,e,n)=>function(){return r(t.fork(e),n,...arguments)};exports.measure=t;exports.measureFn=r;exports.wrap=e;
1
+ var r=(r,t,...e)=>{try{var n=t(...e,r),o=n instanceof Promise;return o&&r.__add_promise(n.catch((t=>{r.set_context({error:t})})).finally((()=>r.end()))),n}catch(t){throw t instanceof Error&&r.set_context({error:t}),t}finally{!0!==o&&r.end()}},t=(t,e,...n)=>r(t,e,...n),e=(t,e)=>function(){return r(t,e,...arguments)};exports.measure=t;exports.measureFn=r;exports.wrap=e;
package/utils/index.mjs CHANGED
@@ -1 +1 @@
1
- var r=(r,t,...e)=>{try{var n=t(...e,r),o=n instanceof Promise;return o&&r.__add_promise(n.catch((t=>{r.set_context({error:t})})).finally((()=>r.end()))),n}catch(t){throw t instanceof Error&&r.set_context({error:t}),t}finally{!0!==o&&r.end()}},t=(t,e,n,...o)=>r(t.fork(e),n,...o),e=(t,e,n)=>function(){return r(t.fork(e),n,...arguments)};export{t as measure,r as measureFn,e as wrap};
1
+ var r=(r,t,...e)=>{try{var n=t(...e,r),o=n instanceof Promise;return o&&r.__add_promise(n.catch((t=>{r.set_context({error:t})})).finally((()=>r.end()))),n}catch(t){throw t instanceof Error&&r.set_context({error:t}),t}finally{!0!==o&&r.end()}},t=(t,e,...n)=>r(t,e,...n),e=(t,e)=>function(){return r(t,e,...arguments)};export{t as measure,r as measureFn,e as wrap};