rian 0.0.2-alpha.13 → 0.0.2-alpha.14
Sign up to get free protection for your applications and to get access to all the features.
- package/exporter.otel.http.js +5 -7
- package/exporter.otel.http.mjs +5 -7
- package/exporter.zipkin.js +6 -8
- package/exporter.zipkin.mjs +6 -8
- package/index.d.ts +28 -3
- package/index.js +3 -3
- package/index.mjs +3 -3
- package/package.json +1 -1
package/exporter.otel.http.js
CHANGED
@@ -57,17 +57,15 @@ const map_kind = (kind) => {
|
|
57
57
|
const exporter = (config) => (spans, context) => {
|
58
58
|
const otel_spans = [];
|
59
59
|
for (let span of spans) {
|
60
|
-
const kind = span.context
|
61
|
-
delete span.context.kind;
|
60
|
+
const { kind, error, ...span_ctx } = span.context;
|
62
61
|
let status;
|
63
|
-
if (
|
62
|
+
if (error) {
|
64
63
|
status = {
|
65
64
|
code: SpanStatusCode_ERROR,
|
66
65
|
};
|
67
|
-
if ('message' in
|
68
|
-
status.message =
|
66
|
+
if ('message' in error) {
|
67
|
+
status.message = error.message;
|
69
68
|
}
|
70
|
-
delete span.context.error;
|
71
69
|
}
|
72
70
|
otel_spans.push({
|
73
71
|
traceId: span.id.trace_id,
|
@@ -80,7 +78,7 @@ const exporter = (config) => (spans, context) => {
|
|
80
78
|
droppedAttributesCount: 0,
|
81
79
|
droppedEventsCount: 0,
|
82
80
|
droppedLinksCount: 0,
|
83
|
-
attributes: convert_object_to_kv(
|
81
|
+
attributes: convert_object_to_kv(span_ctx),
|
84
82
|
status: status || { code: SpanStatusCode_UNSET },
|
85
83
|
});
|
86
84
|
}
|
package/exporter.otel.http.mjs
CHANGED
@@ -55,17 +55,15 @@ const map_kind = (kind) => {
|
|
55
55
|
const exporter = (config) => (spans, context) => {
|
56
56
|
const otel_spans = [];
|
57
57
|
for (let span of spans) {
|
58
|
-
const kind = span.context
|
59
|
-
delete span.context.kind;
|
58
|
+
const { kind, error, ...span_ctx } = span.context;
|
60
59
|
let status;
|
61
|
-
if (
|
60
|
+
if (error) {
|
62
61
|
status = {
|
63
62
|
code: SpanStatusCode_ERROR,
|
64
63
|
};
|
65
|
-
if ('message' in
|
66
|
-
status.message =
|
64
|
+
if ('message' in error) {
|
65
|
+
status.message = error.message;
|
67
66
|
}
|
68
|
-
delete span.context.error;
|
69
67
|
}
|
70
68
|
otel_spans.push({
|
71
69
|
traceId: span.id.trace_id,
|
@@ -78,7 +76,7 @@ const exporter = (config) => (spans, context) => {
|
|
78
76
|
droppedAttributesCount: 0,
|
79
77
|
droppedEventsCount: 0,
|
80
78
|
droppedLinksCount: 0,
|
81
|
-
attributes: convert_object_to_kv(
|
79
|
+
attributes: convert_object_to_kv(span_ctx),
|
82
80
|
status: status || { code: SpanStatusCode_UNSET },
|
83
81
|
});
|
84
82
|
}
|
package/exporter.zipkin.js
CHANGED
@@ -5,31 +5,29 @@ const flattie = require('flattie');
|
|
5
5
|
const exporter = (config) => (spans, context) => {
|
6
6
|
const zipkin = [];
|
7
7
|
for (let span of spans) {
|
8
|
-
const kind = span.context
|
9
|
-
|
10
|
-
if ('error' in span.context) {
|
11
|
-
const error = span.context.error;
|
8
|
+
const { kind, error, ...span_ctx } = span.context;
|
9
|
+
if (error) {
|
12
10
|
if ('message' in error) {
|
13
|
-
|
11
|
+
span_ctx.error = {
|
14
12
|
name: error.name,
|
15
13
|
message: error.message,
|
16
14
|
stack: error.stack,
|
17
15
|
};
|
18
16
|
}
|
19
17
|
else {
|
20
|
-
|
18
|
+
span_ctx.error = true;
|
21
19
|
}
|
22
20
|
}
|
23
21
|
zipkin.push({
|
24
22
|
id: span.id.parent_id,
|
25
23
|
traceId: span.id.trace_id,
|
26
|
-
parentId: span.parent
|
24
|
+
parentId: span.parent ? span.parent.parent_id : undefined,
|
27
25
|
name: span.name,
|
28
26
|
kind: kind === 'INTERNAL' ? undefined : kind,
|
29
27
|
timestamp: span.start * 1000,
|
30
28
|
duration: span.end ? (span.end - span.start) * 1000 : undefined,
|
31
29
|
localEndpoint: context.localEndpoint,
|
32
|
-
tags: flattie.flattie(Object.assign({}, context,
|
30
|
+
tags: flattie.flattie(Object.assign({}, context, span_ctx), '.', true),
|
33
31
|
});
|
34
32
|
}
|
35
33
|
return config.onRequest(zipkin);
|
package/exporter.zipkin.mjs
CHANGED
@@ -3,31 +3,29 @@ import { flattie } from 'flattie';
|
|
3
3
|
const exporter = (config) => (spans, context) => {
|
4
4
|
const zipkin = [];
|
5
5
|
for (let span of spans) {
|
6
|
-
const kind = span.context
|
7
|
-
|
8
|
-
if ('error' in span.context) {
|
9
|
-
const error = span.context.error;
|
6
|
+
const { kind, error, ...span_ctx } = span.context;
|
7
|
+
if (error) {
|
10
8
|
if ('message' in error) {
|
11
|
-
|
9
|
+
span_ctx.error = {
|
12
10
|
name: error.name,
|
13
11
|
message: error.message,
|
14
12
|
stack: error.stack,
|
15
13
|
};
|
16
14
|
}
|
17
15
|
else {
|
18
|
-
|
16
|
+
span_ctx.error = true;
|
19
17
|
}
|
20
18
|
}
|
21
19
|
zipkin.push({
|
22
20
|
id: span.id.parent_id,
|
23
21
|
traceId: span.id.trace_id,
|
24
|
-
parentId: span.parent
|
22
|
+
parentId: span.parent ? span.parent.parent_id : undefined,
|
25
23
|
name: span.name,
|
26
24
|
kind: kind === 'INTERNAL' ? undefined : kind,
|
27
25
|
timestamp: span.start * 1000,
|
28
26
|
duration: span.end ? (span.end - span.start) * 1000 : undefined,
|
29
27
|
localEndpoint: context.localEndpoint,
|
30
|
-
tags: flattie(Object.assign({}, context,
|
28
|
+
tags: flattie(Object.assign({}, context, span_ctx), '.', true),
|
31
29
|
});
|
32
30
|
}
|
33
31
|
return config.onRequest(zipkin);
|
package/index.d.ts
CHANGED
@@ -79,7 +79,7 @@ interface Span {
|
|
79
79
|
* An exporter is a method called when the parent scope ends, gets given a Set of all spans traced
|
80
80
|
* during this execution.
|
81
81
|
*/
|
82
|
-
declare type Exporter = (spans: ReadonlySet<Span
|
82
|
+
declare type Exporter = (spans: ReadonlySet<Readonly<Span>>, context: Context) => any;
|
83
83
|
/**
|
84
84
|
* @borrows {@link Span.context}
|
85
85
|
*/
|
@@ -118,12 +118,37 @@ interface CallableScope extends Scope {
|
|
118
118
|
(cb: (scope: Omit<Scope, 'end'>) => void): ReturnType<typeof cb>;
|
119
119
|
}
|
120
120
|
interface Scope {
|
121
|
+
/**
|
122
|
+
* A W3C traceparent. One can .toString() this if you want to cross a network.
|
123
|
+
*/
|
121
124
|
traceparent: Traceparent;
|
125
|
+
/**
|
126
|
+
* Forks the span into a new child span.
|
127
|
+
*/
|
122
128
|
fork(name: string): CallableScope;
|
129
|
+
/**
|
130
|
+
* With a passed function — will start a span, and run the function, when the function finishes
|
131
|
+
* the span finishes.
|
132
|
+
*
|
133
|
+
* The measure method will return whatever the function is, so if it's a promise, it returns a
|
134
|
+
* promise and so on. Any error is caught and re thrown, and automatically tracked in the
|
135
|
+
* context under the `error` property.
|
136
|
+
*
|
137
|
+
* All promises are tracked, and awaited on a `tracer.end`
|
138
|
+
*/
|
123
139
|
measure<Fn extends MeasureFn>(name: string, fn: Fn, // TODO: fn doesnt see scope correctly
|
124
140
|
...args: RealMeasureFnParams<Parameters<Fn>>): ReturnType<Fn>;
|
125
|
-
|
126
|
-
|
141
|
+
/**
|
142
|
+
* Allows the span's context to be set. Passing an object will be `Object.assign`ed into the
|
143
|
+
* current context.
|
144
|
+
*
|
145
|
+
* Passing a function will be available to return a new context.
|
146
|
+
*/
|
147
|
+
set_context(contextFn: Context | ((context: Context) => Context)): void;
|
148
|
+
/**
|
149
|
+
* Ends the current span — setting its `end` timestamp. Not calling this, will have its `end`
|
150
|
+
* timestamp nulled out — when the tracer ends.
|
151
|
+
*/
|
127
152
|
end(): void;
|
128
153
|
}
|
129
154
|
interface Tracer extends Omit<Scope, 'end'> {
|
package/index.js
CHANGED
@@ -71,16 +71,16 @@ const sdk_object = {
|
|
71
71
|
const create = (name, options) => {
|
72
72
|
const spans = new Set();
|
73
73
|
const promises = [];
|
74
|
+
const sampler = options.sampler || defaultSampler;
|
74
75
|
const span = (name, parent) => {
|
75
|
-
const should_sample =
|
76
|
+
const should_sample = sampler(name, parent, options.context);
|
76
77
|
const id = parent
|
77
78
|
? parent.child(should_sample)
|
78
79
|
: tctx__namespace.make(should_sample);
|
79
|
-
const start = Date.now();
|
80
80
|
const span_obj = {
|
81
81
|
id,
|
82
82
|
parent,
|
83
|
-
start,
|
83
|
+
start: Date.now(),
|
84
84
|
name,
|
85
85
|
context: {},
|
86
86
|
};
|
package/index.mjs
CHANGED
@@ -49,16 +49,16 @@ const sdk_object = {
|
|
49
49
|
const create = (name, options) => {
|
50
50
|
const spans = new Set();
|
51
51
|
const promises = [];
|
52
|
+
const sampler = options.sampler || defaultSampler;
|
52
53
|
const span = (name, parent) => {
|
53
|
-
const should_sample =
|
54
|
+
const should_sample = sampler(name, parent, options.context);
|
54
55
|
const id = parent
|
55
56
|
? parent.child(should_sample)
|
56
57
|
: tctx.make(should_sample);
|
57
|
-
const start = Date.now();
|
58
58
|
const span_obj = {
|
59
59
|
id,
|
60
60
|
parent,
|
61
|
-
start,
|
61
|
+
start: Date.now(),
|
62
62
|
name,
|
63
63
|
context: {},
|
64
64
|
};
|