rian 0.3.0-next.9 → 0.3.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/async.d.ts +56 -3
- package/async.js +1 -93
- package/async.mjs +1 -93
- package/exporter.otel.http.js +1 -77
- package/exporter.otel.http.mjs +1 -77
- package/exporter.zipkin.js +1 -41
- package/exporter.zipkin.mjs +1 -41
- package/index.d.ts +76 -22
- package/index.js +1 -74
- package/index.mjs +1 -74
- package/package.json +2 -2
- package/readme.md +125 -79
- package/utils.d.ts +10 -51
- package/utils.js +1 -26
- package/utils.mjs +1 -26
- package/exporter.otel.http/index.d.ts +0 -3
- package/exporter.otel.http/index.js +0 -1
- package/exporter.otel.http/index.mjs +0 -1
- package/exporter.zipkin/index.d.ts +0 -3
- package/exporter.zipkin/index.js +0 -1
- package/exporter.zipkin/index.mjs +0 -1
- package/utils/index.d.ts +0 -68
- package/utils/index.js +0 -1
- package/utils/index.mjs +0 -1
package/async.d.ts
CHANGED
@@ -1,6 +1,59 @@
|
|
1
|
-
import type { CallableScope,
|
1
|
+
import type { CallableScope, Options, Scope } from 'rian';
|
2
2
|
|
3
|
-
export
|
3
|
+
export { report, configure } from 'rian';
|
4
|
+
|
5
|
+
/**
|
6
|
+
* Returns the current span in the current execution context.
|
7
|
+
*
|
8
|
+
* This will throw an error if there is no current span.
|
9
|
+
*
|
10
|
+
* @example
|
11
|
+
*
|
12
|
+
* ```ts
|
13
|
+
* function doWork() {
|
14
|
+
* const span = currentSpan();
|
15
|
+
* span.set_context({ foo: 'bar' });
|
16
|
+
* }
|
17
|
+
*
|
18
|
+
* span('some-name')(() => {
|
19
|
+
* doWork(); // will guarantee `currentSpan` returns this span
|
20
|
+
* });
|
21
|
+
* ```
|
22
|
+
*/
|
23
|
+
export function currentSpan(): Scope;
|
24
|
+
|
25
|
+
/**
|
26
|
+
* Creates a new span for the currently active tracer.
|
27
|
+
*
|
28
|
+
* @example
|
29
|
+
*
|
30
|
+
* ```ts
|
31
|
+
* tracer('some-name')(() => {
|
32
|
+
* // some deeply nested moments later
|
33
|
+
* const s = span('my-span');
|
34
|
+
* });
|
35
|
+
* ```
|
36
|
+
*/
|
4
37
|
export function span(name: string): CallableScope;
|
5
38
|
|
6
|
-
export
|
39
|
+
export type Tracer<T> = (cb: T) => ReturnType<T>;
|
40
|
+
|
41
|
+
/**
|
42
|
+
* A tracer is a logical unit in your application. This alleviates the need to pass around a tracer instance.
|
43
|
+
*
|
44
|
+
* All spans produced by a tracer will all collect into a single span collection that is given to {@link report}.
|
45
|
+
*
|
46
|
+
* @example
|
47
|
+
*
|
48
|
+
* ```ts
|
49
|
+
* const trace = tracer('server');
|
50
|
+
*
|
51
|
+
* trace(() => {
|
52
|
+
* // application logic
|
53
|
+
* });
|
54
|
+
* ```
|
55
|
+
*/
|
56
|
+
export function tracer<T extends () => any>(
|
57
|
+
name: string,
|
58
|
+
options?: Options,
|
59
|
+
): Tracer<T>;
|
package/async.js
CHANGED
@@ -1,93 +1 @@
|
|
1
|
-
|
2
|
-
const async_hooks = require('node:async_hooks');
|
3
|
-
const { measure } = require('rian/utils');
|
4
|
-
const { make, parse, SAMPLED_FLAG } = require('tctx');
|
5
|
-
|
6
|
-
// src/_internal/index.ts
|
7
|
-
const { is_sampled } = require('tctx');
|
8
|
-
var resource = {};
|
9
|
-
function configure(name, attributes = {}) {
|
10
|
-
resource = {
|
11
|
-
...attributes,
|
12
|
-
["service.name"]: name,
|
13
|
-
["telemetry.sdk.name"]: "rian",
|
14
|
-
["telemetry.sdk.version"]: "0.3.0-next.9"
|
15
|
-
};
|
16
|
-
}
|
17
|
-
var span_buffer = /* @__PURE__ */ new Set(), wait_promises = /* @__PURE__ */ new WeakMap();
|
18
|
-
async function report(exporter) {
|
19
|
-
let ps = [], scopes = /* @__PURE__ */ new Map();
|
20
|
-
for (let [span2, scope] of span_buffer) {
|
21
|
-
let spans;
|
22
|
-
scopes.has(scope) ? spans = scopes.get(scope).spans : scopes.set(scope, {
|
23
|
-
scope,
|
24
|
-
spans: spans = []
|
25
|
-
}), spans.push(span2), wait_promises.has(scope) && (ps.push(...wait_promises.get(scope)), wait_promises.delete(scope));
|
26
|
-
}
|
27
|
-
return span_buffer.clear(), ps.length && await Promise.all(ps), exporter({
|
28
|
-
resource,
|
29
|
-
scopeSpans: scopes.values()
|
30
|
-
});
|
31
|
-
}
|
32
|
-
function defaultSampler(_name, id) {
|
33
|
-
return is_sampled(id);
|
34
|
-
}
|
35
|
-
|
36
|
-
// src/async.ts
|
37
|
-
var resourceStore = new async_hooks.AsyncLocalStorage();
|
38
|
-
function currentSpan() {
|
39
|
-
return resourceStore.getStore()?.[1] || null;
|
40
|
-
}
|
41
|
-
function span(name) {
|
42
|
-
let context = resourceStore.getStore();
|
43
|
-
if (!context)
|
44
|
-
throw Error("TODO");
|
45
|
-
let api = context[0], scope = api.scope, current_span = context[1], sampler = api.sampler, parent = current_span?.traceparent ?? api.root_id, id = parent ? parent.child() : make(), should_sample = typeof sampler != "boolean" ? sampler(name, id, scope) : sampler;
|
46
|
-
should_sample ? id.flags | SAMPLED_FLAG : id.flags & ~SAMPLED_FLAG;
|
47
|
-
let span_obj = {
|
48
|
-
id,
|
49
|
-
parent,
|
50
|
-
start: Date.now(),
|
51
|
-
name,
|
52
|
-
events: [],
|
53
|
-
context: {}
|
54
|
-
};
|
55
|
-
should_sample && span_buffer.add([span_obj, scope]);
|
56
|
-
let $ = (cb) => resourceStore.run([api, $], measure, $, cb);
|
57
|
-
$.traceparent = id, $.span = span, $.set_context = (ctx) => {
|
58
|
-
if (typeof ctx == "function")
|
59
|
-
return void (span_obj.context = ctx(span_obj.context));
|
60
|
-
Object.assign(span_obj.context, ctx);
|
61
|
-
}, $.add_event = (name2, attributes) => {
|
62
|
-
span_obj.events.push({
|
63
|
-
name: name2,
|
64
|
-
timestamp: Date.now(),
|
65
|
-
attributes: attributes || {}
|
66
|
-
});
|
67
|
-
}, $.end = () => {
|
68
|
-
span_obj.end == null && (span_obj.end = Date.now());
|
69
|
-
};
|
70
|
-
let ps = wait_promises.get(scope);
|
71
|
-
return $.__add_promise = (p) => {
|
72
|
-
ps.add(p), p.then(() => ps.delete(p));
|
73
|
-
}, resourceStore.run([api, $], () => $);
|
74
|
-
}
|
75
|
-
function tracer(name, options) {
|
76
|
-
let sampler = options?.sampler ?? defaultSampler, scope = { name }, api = {
|
77
|
-
root_id: typeof options?.traceparent == "string" ? parse(options.traceparent) : resourceStore.getStore()?.[0].root_id,
|
78
|
-
scope,
|
79
|
-
sampler
|
80
|
-
};
|
81
|
-
return wait_promises.set(scope, /* @__PURE__ */ new Set()), {
|
82
|
-
span(name2) {
|
83
|
-
return resourceStore.run([api, null], span, name2);
|
84
|
-
}
|
85
|
-
};
|
86
|
-
}
|
87
|
-
|
88
|
-
|
89
|
-
exports.configure = configure;
|
90
|
-
exports.currentSpan = currentSpan;
|
91
|
-
exports.report = report;
|
92
|
-
exports.span = span;
|
93
|
-
exports.tracer = tracer;
|
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 c(e,t={}){s={...t,"service.name":e,"telemetry.sdk.name":"rian","telemetry.sdk.version":"0.3.1"}}var l=new Set,i=new WeakMap;async function p(e){let t=[],n=new Map;for(let[e,r]of l){let o;n.has(r)?o=n.get(r).spans:n.set(r,{scope:r,spans:o=[]}),o.push(e),i.has(r)&&(t.push(...i.get(r)),i.delete(r))}return l.clear(),t.length&&await Promise.all(t),e({resource:s,scopeSpans:n.values()})}function u(e,t){return a(t)}var d=new e.AsyncLocalStorage;function m(){let e=d.getStore()?.[1];if(null==e)throw new Error("no current span");return e}function f(e){let r=d.getStore();if(!r)throw Error("TODO");let o=r[0],a=o.scope,s=r[1],c=o.sampler,p=s?.traceparent??o.root_id,u=p?p.child():n(),m="boolean"!=typeof c?c(e,u,a):c;u.flags;let w={id:u,parent:p,start:o.clock.now(),name:e,events:[],context:{}};m&&l.add([w,a]);let g=e=>d.run([o,g],t,g,e);g.traceparent=u,g.span=e=>d.run([o,g],f,e),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:o.clock.now(),attributes:t||{}})},g.end=()=>{null==w.end&&(w.end=o.clock.now())};let h=i.get(a);return g.__add_promise=e=>{h.add(e),e.then((()=>h.delete(e)))},g}function w(e,t){let n=t?.sampler??u,o={name:e},a={root_id:"string"==typeof t?.traceparent?r(t.traceparent):void 0,scope:o,sampler:n,clock:t?.clock??Date};return i.set(o,new Set),function(e){let t=d.getStore();return a.root_id||(a.root_id=t?.[0].root_id),d.run([a,t?.[1]||null],e)}}exports.configure=c;exports.currentSpan=m;exports.report=p;exports.span=f;exports.tracer=w;
|
package/async.mjs
CHANGED
@@ -1,93 +1 @@
|
|
1
|
-
|
2
|
-
import * as async_hooks from "node:async_hooks";
|
3
|
-
import { measure } from "rian/utils";
|
4
|
-
import { make, parse, SAMPLED_FLAG } from "tctx";
|
5
|
-
|
6
|
-
// src/_internal/index.ts
|
7
|
-
import { is_sampled } from "tctx";
|
8
|
-
var resource = {};
|
9
|
-
function configure(name, attributes = {}) {
|
10
|
-
resource = {
|
11
|
-
...attributes,
|
12
|
-
["service.name"]: name,
|
13
|
-
["telemetry.sdk.name"]: "rian",
|
14
|
-
["telemetry.sdk.version"]: "0.3.0-next.9"
|
15
|
-
};
|
16
|
-
}
|
17
|
-
var span_buffer = /* @__PURE__ */ new Set(), wait_promises = /* @__PURE__ */ new WeakMap();
|
18
|
-
async function report(exporter) {
|
19
|
-
let ps = [], scopes = /* @__PURE__ */ new Map();
|
20
|
-
for (let [span2, scope] of span_buffer) {
|
21
|
-
let spans;
|
22
|
-
scopes.has(scope) ? spans = scopes.get(scope).spans : scopes.set(scope, {
|
23
|
-
scope,
|
24
|
-
spans: spans = []
|
25
|
-
}), spans.push(span2), wait_promises.has(scope) && (ps.push(...wait_promises.get(scope)), wait_promises.delete(scope));
|
26
|
-
}
|
27
|
-
return span_buffer.clear(), ps.length && await Promise.all(ps), exporter({
|
28
|
-
resource,
|
29
|
-
scopeSpans: scopes.values()
|
30
|
-
});
|
31
|
-
}
|
32
|
-
function defaultSampler(_name, id) {
|
33
|
-
return is_sampled(id);
|
34
|
-
}
|
35
|
-
|
36
|
-
// src/async.ts
|
37
|
-
var resourceStore = new async_hooks.AsyncLocalStorage();
|
38
|
-
function currentSpan() {
|
39
|
-
return resourceStore.getStore()?.[1] || null;
|
40
|
-
}
|
41
|
-
function span(name) {
|
42
|
-
let context = resourceStore.getStore();
|
43
|
-
if (!context)
|
44
|
-
throw Error("TODO");
|
45
|
-
let api = context[0], scope = api.scope, current_span = context[1], sampler = api.sampler, parent = current_span?.traceparent ?? api.root_id, id = parent ? parent.child() : make(), should_sample = typeof sampler != "boolean" ? sampler(name, id, scope) : sampler;
|
46
|
-
should_sample ? id.flags | SAMPLED_FLAG : id.flags & ~SAMPLED_FLAG;
|
47
|
-
let span_obj = {
|
48
|
-
id,
|
49
|
-
parent,
|
50
|
-
start: Date.now(),
|
51
|
-
name,
|
52
|
-
events: [],
|
53
|
-
context: {}
|
54
|
-
};
|
55
|
-
should_sample && span_buffer.add([span_obj, scope]);
|
56
|
-
let $ = (cb) => resourceStore.run([api, $], measure, $, cb);
|
57
|
-
$.traceparent = id, $.span = span, $.set_context = (ctx) => {
|
58
|
-
if (typeof ctx == "function")
|
59
|
-
return void (span_obj.context = ctx(span_obj.context));
|
60
|
-
Object.assign(span_obj.context, ctx);
|
61
|
-
}, $.add_event = (name2, attributes) => {
|
62
|
-
span_obj.events.push({
|
63
|
-
name: name2,
|
64
|
-
timestamp: Date.now(),
|
65
|
-
attributes: attributes || {}
|
66
|
-
});
|
67
|
-
}, $.end = () => {
|
68
|
-
span_obj.end == null && (span_obj.end = Date.now());
|
69
|
-
};
|
70
|
-
let ps = wait_promises.get(scope);
|
71
|
-
return $.__add_promise = (p) => {
|
72
|
-
ps.add(p), p.then(() => ps.delete(p));
|
73
|
-
}, resourceStore.run([api, $], () => $);
|
74
|
-
}
|
75
|
-
function tracer(name, options) {
|
76
|
-
let sampler = options?.sampler ?? defaultSampler, scope = { name }, api = {
|
77
|
-
root_id: typeof options?.traceparent == "string" ? parse(options.traceparent) : resourceStore.getStore()?.[0].root_id,
|
78
|
-
scope,
|
79
|
-
sampler
|
80
|
-
};
|
81
|
-
return wait_promises.set(scope, /* @__PURE__ */ new Set()), {
|
82
|
-
span(name2) {
|
83
|
-
return resourceStore.run([api, null], span, name2);
|
84
|
-
}
|
85
|
-
};
|
86
|
-
}
|
87
|
-
export {
|
88
|
-
configure,
|
89
|
-
currentSpan,
|
90
|
-
report,
|
91
|
-
span,
|
92
|
-
tracer
|
93
|
-
};
|
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 c(e,t={}){s={...t,"service.name":e,"telemetry.sdk.name":"rian","telemetry.sdk.version":"0.3.1"}}var l=new Set,i=new WeakMap;async function p(e){let t=[],n=new Map;for(let[e,r]of l){let o;n.has(r)?o=n.get(r).spans:n.set(r,{scope:r,spans:o=[]}),o.push(e),i.has(r)&&(t.push(...i.get(r)),i.delete(r))}return l.clear(),t.length&&await Promise.all(t),e({resource:s,scopeSpans:n.values()})}function u(e,t){return a(t)}var d=new e.AsyncLocalStorage;function m(){let e=d.getStore()?.[1];if(null==e)throw new Error("no current span");return e}function f(e){let r=d.getStore();if(!r)throw Error("TODO");let o=r[0],a=o.scope,s=r[1],c=o.sampler,p=s?.traceparent??o.root_id,u=p?p.child():n(),m="boolean"!=typeof c?c(e,u,a):c;u.flags;let w={id:u,parent:p,start:o.clock.now(),name:e,events:[],context:{}};m&&l.add([w,a]);let g=e=>d.run([o,g],t,g,e);g.traceparent=u,g.span=e=>d.run([o,g],f,e),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:o.clock.now(),attributes:t||{}})},g.end=()=>{null==w.end&&(w.end=o.clock.now())};let h=i.get(a);return g.__add_promise=e=>{h.add(e),e.then((()=>h.delete(e)))},g}function w(e,t){let n=t?.sampler??u,o={name:e},a={root_id:"string"==typeof t?.traceparent?r(t.traceparent):void 0,scope:o,sampler:n,clock:t?.clock??Date};return i.set(o,new Set),function(e){let t=d.getStore();return a.root_id||(a.root_id=t?.[0].root_id),d.run([a,t?.[1]||null],e)}}export{c as configure,m as currentSpan,p as report,f as span,w as tracer};
|
package/exporter.otel.http.js
CHANGED
@@ -1,77 +1 @@
|
|
1
|
-
|
2
|
-
var convert_value_to_anyvalue = (value) => {
|
3
|
-
let type = typeof value, any_value = {};
|
4
|
-
return type === "string" ? any_value.stringValue = value : type === "number" ? Number.isInteger(value) ? any_value.intValue = value : any_value.doubleValue = value : type === "boolean" ? any_value.boolValue = value : Array.isArray(value) ? any_value.arrayValue = {
|
5
|
-
values: value.map((i) => convert_value_to_anyvalue(i))
|
6
|
-
} : value && (any_value.kvlistValue = { values: convert_object_to_kv(value) }), any_value;
|
7
|
-
}, convert_object_to_kv = (input) => {
|
8
|
-
let value = [];
|
9
|
-
for (let key of Object.keys(input))
|
10
|
-
value.push({
|
11
|
-
key,
|
12
|
-
value: convert_value_to_anyvalue(input[key])
|
13
|
-
});
|
14
|
-
return value;
|
15
|
-
}, map_kind = (kind) => {
|
16
|
-
switch (kind) {
|
17
|
-
default:
|
18
|
-
case "INTERNAL":
|
19
|
-
return 1;
|
20
|
-
case "SERVER":
|
21
|
-
return 2;
|
22
|
-
case "CLIENT":
|
23
|
-
return 3;
|
24
|
-
case "PRODUCER":
|
25
|
-
return 4;
|
26
|
-
case "CONSUMER":
|
27
|
-
return 5;
|
28
|
-
}
|
29
|
-
}, exporter = (request) => (trace) => {
|
30
|
-
let scopeSpans = [];
|
31
|
-
for (let scope of trace.scopeSpans) {
|
32
|
-
let spans = [];
|
33
|
-
scopeSpans.push({
|
34
|
-
scope: scope.scope,
|
35
|
-
spans
|
36
|
-
});
|
37
|
-
for (let span of scope.spans) {
|
38
|
-
let { kind, error, ...span_ctx } = span.context, status;
|
39
|
-
error && (status = {
|
40
|
-
code: 2
|
41
|
-
}, "message" in error && (status.message = error.message)), spans.push({
|
42
|
-
traceId: span.id.trace_id,
|
43
|
-
spanId: span.id.parent_id,
|
44
|
-
parentSpanId: span.parent?.parent_id,
|
45
|
-
name: span.name,
|
46
|
-
kind: map_kind(kind || "INTERNAL"),
|
47
|
-
startTimeUnixNano: span.start * 1e6,
|
48
|
-
endTimeUnixNano: span.end ? span.end * 1e6 : void 0,
|
49
|
-
droppedAttributesCount: 0,
|
50
|
-
droppedEventsCount: 0,
|
51
|
-
droppedLinksCount: 0,
|
52
|
-
attributes: convert_object_to_kv(span_ctx),
|
53
|
-
status: status || { code: 0 },
|
54
|
-
events: span.events.map((i) => ({
|
55
|
-
name: i.name,
|
56
|
-
attributes: convert_object_to_kv(i.attributes),
|
57
|
-
droppedAttributesCount: 0,
|
58
|
-
timeUnixNano: i.timestamp * 1e6
|
59
|
-
}))
|
60
|
-
});
|
61
|
-
}
|
62
|
-
}
|
63
|
-
return request({
|
64
|
-
resourceSpans: [
|
65
|
-
{
|
66
|
-
resource: {
|
67
|
-
attributes: convert_object_to_kv(trace.resource),
|
68
|
-
droppedAttributesCount: 0
|
69
|
-
},
|
70
|
-
scopeSpans
|
71
|
-
}
|
72
|
-
]
|
73
|
-
});
|
74
|
-
};
|
75
|
-
|
76
|
-
|
77
|
-
exports.exporter = exporter;
|
1
|
+
var e=r=>{let a=typeof r,s={};return"string"===a?s.stringValue=r:"number"===a?Number.isInteger(r)?s.intValue=r:s.doubleValue=r:"boolean"===a?s.boolValue=r:Array.isArray(r)?s.arrayValue={values:r.map((t=>e(t)))}:r&&(s.kvlistValue={values:t(r)}),s},t=t=>{let r=[];for(let a of Object.keys(t))r.push({key:a,value:e(t[a])});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}},a=e=>a=>{let s=[];for(let e of a.scopeSpans){let a=[];s.push({scope:e.scope,spans:a});for(let s of e.spans){let e,{kind:n,error:u,...o}=s.context;u&&(e={code:2},"message"in u&&(e.message=u.message)),a.push({traceId:s.id.trace_id,spanId:s.id.parent_id,parentSpanId:s.parent?.parent_id,name:s.name,kind:r(n||"INTERNAL"),startTimeUnixNano:1e6*s.start,endTimeUnixNano:s.end?1e6*s.end:void 0,droppedAttributesCount:0,droppedEventsCount:0,droppedLinksCount:0,attributes:t(o),status:e||{code:0},events:s.events.map((e=>({name:e.name,attributes:t(e.attributes),droppedAttributesCount:0,timeUnixNano:1e6*e.timestamp})))})}}return e({resourceSpans:[{resource:{attributes:t(a.resource),droppedAttributesCount:0},scopeSpans:s}]})};exports.exporter=a;
|
package/exporter.otel.http.mjs
CHANGED
@@ -1,77 +1 @@
|
|
1
|
-
|
2
|
-
var convert_value_to_anyvalue = (value) => {
|
3
|
-
let type = typeof value, any_value = {};
|
4
|
-
return type === "string" ? any_value.stringValue = value : type === "number" ? Number.isInteger(value) ? any_value.intValue = value : any_value.doubleValue = value : type === "boolean" ? any_value.boolValue = value : Array.isArray(value) ? any_value.arrayValue = {
|
5
|
-
values: value.map((i) => convert_value_to_anyvalue(i))
|
6
|
-
} : value && (any_value.kvlistValue = { values: convert_object_to_kv(value) }), any_value;
|
7
|
-
}, convert_object_to_kv = (input) => {
|
8
|
-
let value = [];
|
9
|
-
for (let key of Object.keys(input))
|
10
|
-
value.push({
|
11
|
-
key,
|
12
|
-
value: convert_value_to_anyvalue(input[key])
|
13
|
-
});
|
14
|
-
return value;
|
15
|
-
}, map_kind = (kind) => {
|
16
|
-
switch (kind) {
|
17
|
-
default:
|
18
|
-
case "INTERNAL":
|
19
|
-
return 1;
|
20
|
-
case "SERVER":
|
21
|
-
return 2;
|
22
|
-
case "CLIENT":
|
23
|
-
return 3;
|
24
|
-
case "PRODUCER":
|
25
|
-
return 4;
|
26
|
-
case "CONSUMER":
|
27
|
-
return 5;
|
28
|
-
}
|
29
|
-
}, exporter = (request) => (trace) => {
|
30
|
-
let scopeSpans = [];
|
31
|
-
for (let scope of trace.scopeSpans) {
|
32
|
-
let spans = [];
|
33
|
-
scopeSpans.push({
|
34
|
-
scope: scope.scope,
|
35
|
-
spans
|
36
|
-
});
|
37
|
-
for (let span of scope.spans) {
|
38
|
-
let { kind, error, ...span_ctx } = span.context, status;
|
39
|
-
error && (status = {
|
40
|
-
code: 2
|
41
|
-
}, "message" in error && (status.message = error.message)), spans.push({
|
42
|
-
traceId: span.id.trace_id,
|
43
|
-
spanId: span.id.parent_id,
|
44
|
-
parentSpanId: span.parent?.parent_id,
|
45
|
-
name: span.name,
|
46
|
-
kind: map_kind(kind || "INTERNAL"),
|
47
|
-
startTimeUnixNano: span.start * 1e6,
|
48
|
-
endTimeUnixNano: span.end ? span.end * 1e6 : void 0,
|
49
|
-
droppedAttributesCount: 0,
|
50
|
-
droppedEventsCount: 0,
|
51
|
-
droppedLinksCount: 0,
|
52
|
-
attributes: convert_object_to_kv(span_ctx),
|
53
|
-
status: status || { code: 0 },
|
54
|
-
events: span.events.map((i) => ({
|
55
|
-
name: i.name,
|
56
|
-
attributes: convert_object_to_kv(i.attributes),
|
57
|
-
droppedAttributesCount: 0,
|
58
|
-
timeUnixNano: i.timestamp * 1e6
|
59
|
-
}))
|
60
|
-
});
|
61
|
-
}
|
62
|
-
}
|
63
|
-
return request({
|
64
|
-
resourceSpans: [
|
65
|
-
{
|
66
|
-
resource: {
|
67
|
-
attributes: convert_object_to_kv(trace.resource),
|
68
|
-
droppedAttributesCount: 0
|
69
|
-
},
|
70
|
-
scopeSpans
|
71
|
-
}
|
72
|
-
]
|
73
|
-
});
|
74
|
-
};
|
75
|
-
export {
|
76
|
-
exporter
|
77
|
-
};
|
1
|
+
var e=r=>{let a=typeof r,s={};return"string"===a?s.stringValue=r:"number"===a?Number.isInteger(r)?s.intValue=r:s.doubleValue=r:"boolean"===a?s.boolValue=r:Array.isArray(r)?s.arrayValue={values:r.map((t=>e(t)))}:r&&(s.kvlistValue={values:t(r)}),s},t=t=>{let r=[];for(let a of Object.keys(t))r.push({key:a,value:e(t[a])});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}},a=e=>a=>{let s=[];for(let e of a.scopeSpans){let a=[];s.push({scope:e.scope,spans:a});for(let s of e.spans){let e,{kind:n,error:u,...o}=s.context;u&&(e={code:2},"message"in u&&(e.message=u.message)),a.push({traceId:s.id.trace_id,spanId:s.id.parent_id,parentSpanId:s.parent?.parent_id,name:s.name,kind:r(n||"INTERNAL"),startTimeUnixNano:1e6*s.start,endTimeUnixNano:s.end?1e6*s.end:void 0,droppedAttributesCount:0,droppedEventsCount:0,droppedLinksCount:0,attributes:t(o),status:e||{code:0},events:s.events.map((e=>({name:e.name,attributes:t(e.attributes),droppedAttributesCount:0,timeUnixNano:1e6*e.timestamp})))})}}return e({resourceSpans:[{resource:{attributes:t(a.resource),droppedAttributesCount:0},scopeSpans:s}]})};export{a as exporter};
|
package/exporter.zipkin.js
CHANGED
@@ -1,41 +1 @@
|
|
1
|
-
|
2
|
-
const { flattie } = require('flattie');
|
3
|
-
var exporter = (request) => (trace) => {
|
4
|
-
let zipkin = [];
|
5
|
-
for (let scope of trace.scopeSpans)
|
6
|
-
for (let span of scope.spans) {
|
7
|
-
let { kind, error, ...span_ctx } = span.context;
|
8
|
-
error && ("message" in error ? span_ctx.error = {
|
9
|
-
name: error.name,
|
10
|
-
message: error.message,
|
11
|
-
stack: error.stack
|
12
|
-
} : span_ctx.error = !0), zipkin.push({
|
13
|
-
id: span.id.parent_id,
|
14
|
-
traceId: span.id.trace_id,
|
15
|
-
parentId: span.parent ? span.parent.parent_id : void 0,
|
16
|
-
name: span.name,
|
17
|
-
kind: kind === "INTERNAL" ? void 0 : kind,
|
18
|
-
timestamp: span.start * 1e3,
|
19
|
-
duration: span.end ? (span.end - span.start) * 1e3 : void 0,
|
20
|
-
localEndpoint: {
|
21
|
-
serviceName: `${trace.resource["service.name"]}@${scope.scope.name}`
|
22
|
-
},
|
23
|
-
tags: flattie(
|
24
|
-
{
|
25
|
-
...trace.resource,
|
26
|
-
...span_ctx
|
27
|
-
},
|
28
|
-
".",
|
29
|
-
!0
|
30
|
-
),
|
31
|
-
annotations: span.events.map((i) => ({
|
32
|
-
value: `${i.name} :: ${JSON.stringify(i.attributes)}`,
|
33
|
-
timestamp: i.timestamp * 1e3
|
34
|
-
}))
|
35
|
-
});
|
36
|
-
}
|
37
|
-
return request(zipkin);
|
38
|
-
};
|
39
|
-
|
40
|
-
|
41
|
-
exports.exporter = exporter;
|
1
|
+
const { flattie:e } = require('flattie');var t=t=>a=>{let r=[];for(let t of a.scopeSpans)for(let n of t.spans){let{kind:s,error:i,...o}=n.context;i&&(o.error=!("message"in i)||{name:i.name,message:i.message,stack:i.stack}),r.push({id:n.id.parent_id,traceId:n.id.trace_id,parentId:n.parent?n.parent.parent_id:void 0,name:n.name,kind:"INTERNAL"===s?void 0:s,timestamp:1e3*n.start,duration:n.end?1e3*(n.end-n.start):void 0,localEndpoint:{serviceName:`${a.resource["service.name"]}@${t.scope.name}`},tags:e({...a.resource,...o},".",!0),annotations:n.events.map((e=>({value:`${e.name} :: ${JSON.stringify(e.attributes)}`,timestamp:1e3*e.timestamp})))})}return t(r)};exports.exporter=t;
|
package/exporter.zipkin.mjs
CHANGED
@@ -1,41 +1 @@
|
|
1
|
-
|
2
|
-
import { flattie } from "flattie";
|
3
|
-
var exporter = (request) => (trace) => {
|
4
|
-
let zipkin = [];
|
5
|
-
for (let scope of trace.scopeSpans)
|
6
|
-
for (let span of scope.spans) {
|
7
|
-
let { kind, error, ...span_ctx } = span.context;
|
8
|
-
error && ("message" in error ? span_ctx.error = {
|
9
|
-
name: error.name,
|
10
|
-
message: error.message,
|
11
|
-
stack: error.stack
|
12
|
-
} : span_ctx.error = !0), zipkin.push({
|
13
|
-
id: span.id.parent_id,
|
14
|
-
traceId: span.id.trace_id,
|
15
|
-
parentId: span.parent ? span.parent.parent_id : void 0,
|
16
|
-
name: span.name,
|
17
|
-
kind: kind === "INTERNAL" ? void 0 : kind,
|
18
|
-
timestamp: span.start * 1e3,
|
19
|
-
duration: span.end ? (span.end - span.start) * 1e3 : void 0,
|
20
|
-
localEndpoint: {
|
21
|
-
serviceName: `${trace.resource["service.name"]}@${scope.scope.name}`
|
22
|
-
},
|
23
|
-
tags: flattie(
|
24
|
-
{
|
25
|
-
...trace.resource,
|
26
|
-
...span_ctx
|
27
|
-
},
|
28
|
-
".",
|
29
|
-
!0
|
30
|
-
),
|
31
|
-
annotations: span.events.map((i) => ({
|
32
|
-
value: `${i.name} :: ${JSON.stringify(i.attributes)}`,
|
33
|
-
timestamp: i.timestamp * 1e3
|
34
|
-
}))
|
35
|
-
});
|
36
|
-
}
|
37
|
-
return request(zipkin);
|
38
|
-
};
|
39
|
-
export {
|
40
|
-
exporter
|
41
|
-
};
|
1
|
+
import{flattie as e}from"flattie";var t=t=>a=>{let r=[];for(let t of a.scopeSpans)for(let n of t.spans){let{kind:s,error:i,...o}=n.context;i&&(o.error=!("message"in i)||{name:i.name,message:i.message,stack:i.stack}),r.push({id:n.id.parent_id,traceId:n.id.trace_id,parentId:n.parent?n.parent.parent_id:void 0,name:n.name,kind:"INTERNAL"===s?void 0:s,timestamp:1e3*n.start,duration:n.end?1e3*(n.end-n.start):void 0,localEndpoint:{serviceName:`${a.resource["service.name"]}@${t.scope.name}`},tags:e({...a.resource,...o},".",!0),annotations:n.events.map((e=>({value:`${e.name} :: ${JSON.stringify(e.attributes)}`,timestamp:1e3*e.timestamp})))})}return t(r)};export{t as exporter};
|