rian 0.0.5 → 0.2.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/exporter.otel.http/index.d.ts +3 -0
- package/exporter.otel.http/index.js +110 -0
- package/exporter.otel.http/index.mjs +110 -0
- package/exporter.zipkin/index.d.ts +3 -0
- package/exporter.zipkin/index.js +43 -0
- package/exporter.zipkin/index.mjs +43 -0
- package/index.d.ts +146 -145
- package/index.js +68 -124
- package/index.mjs +70 -104
- package/package.json +22 -6
- package/utils/index.d.ts +68 -0
- package/utils/index.js +30 -0
- package/utils/index.mjs +30 -0
- package/exporter.otel.http.d.ts +0 -5
- package/exporter.otel.http.js +0 -112
- package/exporter.otel.http.mjs +0 -110
- package/exporter.zipkin.d.ts +0 -5
- package/exporter.zipkin.js +0 -45
- package/exporter.zipkin.mjs +0 -43
package/exporter.otel.http.js
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const package_json = require('rian/package.json');
|
|
4
|
-
|
|
5
|
-
const SpanStatusCode_UNSET = 0;
|
|
6
|
-
const SpanStatusCode_ERROR = 2;
|
|
7
|
-
const convert_value_to_anyvalue = (value) => {
|
|
8
|
-
let type = typeof value, any_value = {};
|
|
9
|
-
if (type === 'string')
|
|
10
|
-
any_value.stringValue = value;
|
|
11
|
-
else if (type === 'number')
|
|
12
|
-
if (Number.isInteger(value))
|
|
13
|
-
any_value.intValue = value;
|
|
14
|
-
else
|
|
15
|
-
any_value.doubleValue = value;
|
|
16
|
-
else if (type === 'boolean')
|
|
17
|
-
any_value.boolValue = value;
|
|
18
|
-
else if (Array.isArray(value))
|
|
19
|
-
any_value.arrayValue = {
|
|
20
|
-
values: value.map((i) => convert_value_to_anyvalue(i)),
|
|
21
|
-
};
|
|
22
|
-
else if (value)
|
|
23
|
-
any_value.kvlistValue = { values: convert_object_to_kv(value) };
|
|
24
|
-
return any_value;
|
|
25
|
-
};
|
|
26
|
-
const convert_object_to_kv = (input) => {
|
|
27
|
-
const value = [];
|
|
28
|
-
for (let key of Object.keys(input)) {
|
|
29
|
-
value.push({
|
|
30
|
-
key,
|
|
31
|
-
value: convert_value_to_anyvalue(input[key]),
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
return value;
|
|
35
|
-
};
|
|
36
|
-
// https://github.com/open-telemetry/opentelemetry-proto/blob/b43e9b18b76abf3ee040164b55b9c355217151f3/opentelemetry/proto/trace/v1/trace.proto#L127-L155
|
|
37
|
-
const map_kind = (kind) => {
|
|
38
|
-
switch (kind) {
|
|
39
|
-
default:
|
|
40
|
-
case 'INTERNAL': {
|
|
41
|
-
return 1;
|
|
42
|
-
}
|
|
43
|
-
case 'SERVER': {
|
|
44
|
-
return 2;
|
|
45
|
-
}
|
|
46
|
-
case 'CLIENT': {
|
|
47
|
-
return 3;
|
|
48
|
-
}
|
|
49
|
-
case 'PRODUCER': {
|
|
50
|
-
return 4;
|
|
51
|
-
}
|
|
52
|
-
case 'CONSUMER': {
|
|
53
|
-
return 5;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
const exporter = (request) => (spans, context) => {
|
|
58
|
-
const otel_spans = [];
|
|
59
|
-
for (let span of spans) {
|
|
60
|
-
const { kind, error, ...span_ctx } = span.context;
|
|
61
|
-
let status;
|
|
62
|
-
if (error) {
|
|
63
|
-
status = {
|
|
64
|
-
code: SpanStatusCode_ERROR,
|
|
65
|
-
};
|
|
66
|
-
if ('message' in error) {
|
|
67
|
-
status.message = error.message;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
otel_spans.push({
|
|
71
|
-
traceId: span.id.trace_id,
|
|
72
|
-
spanId: span.id.parent_id,
|
|
73
|
-
parentSpanId: span.parent?.parent_id,
|
|
74
|
-
name: span.name,
|
|
75
|
-
kind: map_kind(kind || 'INTERNAL'),
|
|
76
|
-
startTimeUnixNano: span.start * 1000000,
|
|
77
|
-
endTimeUnixNano: span.end ? span.end * 1000000 : undefined,
|
|
78
|
-
droppedAttributesCount: 0,
|
|
79
|
-
droppedEventsCount: 0,
|
|
80
|
-
droppedLinksCount: 0,
|
|
81
|
-
attributes: convert_object_to_kv(span_ctx),
|
|
82
|
-
status: status || { code: SpanStatusCode_UNSET },
|
|
83
|
-
events: span.events.map((i) => ({
|
|
84
|
-
name: i.name,
|
|
85
|
-
attributes: convert_object_to_kv(i.attributes),
|
|
86
|
-
droppedAttributesCount: 0,
|
|
87
|
-
timeUnixNano: i.timestamp * 1000000,
|
|
88
|
-
})),
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
return request({
|
|
92
|
-
resourceSpans: [
|
|
93
|
-
{
|
|
94
|
-
resource: {
|
|
95
|
-
attributes: convert_object_to_kv(context),
|
|
96
|
-
droppedAttributesCount: 0,
|
|
97
|
-
},
|
|
98
|
-
instrumentationLibrarySpans: [
|
|
99
|
-
{
|
|
100
|
-
instrumentationLibrary: {
|
|
101
|
-
name: package_json.name,
|
|
102
|
-
version: package_json.version,
|
|
103
|
-
},
|
|
104
|
-
spans: otel_spans,
|
|
105
|
-
},
|
|
106
|
-
],
|
|
107
|
-
},
|
|
108
|
-
],
|
|
109
|
-
});
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
exports.exporter = exporter;
|
package/exporter.otel.http.mjs
DELETED
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import { name, version } from 'rian/package.json';
|
|
2
|
-
|
|
3
|
-
const SpanStatusCode_UNSET = 0;
|
|
4
|
-
const SpanStatusCode_ERROR = 2;
|
|
5
|
-
const convert_value_to_anyvalue = (value) => {
|
|
6
|
-
let type = typeof value, any_value = {};
|
|
7
|
-
if (type === 'string')
|
|
8
|
-
any_value.stringValue = value;
|
|
9
|
-
else if (type === 'number')
|
|
10
|
-
if (Number.isInteger(value))
|
|
11
|
-
any_value.intValue = value;
|
|
12
|
-
else
|
|
13
|
-
any_value.doubleValue = value;
|
|
14
|
-
else if (type === 'boolean')
|
|
15
|
-
any_value.boolValue = value;
|
|
16
|
-
else if (Array.isArray(value))
|
|
17
|
-
any_value.arrayValue = {
|
|
18
|
-
values: value.map((i) => convert_value_to_anyvalue(i)),
|
|
19
|
-
};
|
|
20
|
-
else if (value)
|
|
21
|
-
any_value.kvlistValue = { values: convert_object_to_kv(value) };
|
|
22
|
-
return any_value;
|
|
23
|
-
};
|
|
24
|
-
const convert_object_to_kv = (input) => {
|
|
25
|
-
const value = [];
|
|
26
|
-
for (let key of Object.keys(input)) {
|
|
27
|
-
value.push({
|
|
28
|
-
key,
|
|
29
|
-
value: convert_value_to_anyvalue(input[key]),
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
return value;
|
|
33
|
-
};
|
|
34
|
-
// https://github.com/open-telemetry/opentelemetry-proto/blob/b43e9b18b76abf3ee040164b55b9c355217151f3/opentelemetry/proto/trace/v1/trace.proto#L127-L155
|
|
35
|
-
const map_kind = (kind) => {
|
|
36
|
-
switch (kind) {
|
|
37
|
-
default:
|
|
38
|
-
case 'INTERNAL': {
|
|
39
|
-
return 1;
|
|
40
|
-
}
|
|
41
|
-
case 'SERVER': {
|
|
42
|
-
return 2;
|
|
43
|
-
}
|
|
44
|
-
case 'CLIENT': {
|
|
45
|
-
return 3;
|
|
46
|
-
}
|
|
47
|
-
case 'PRODUCER': {
|
|
48
|
-
return 4;
|
|
49
|
-
}
|
|
50
|
-
case 'CONSUMER': {
|
|
51
|
-
return 5;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
const exporter = (request) => (spans, context) => {
|
|
56
|
-
const otel_spans = [];
|
|
57
|
-
for (let span of spans) {
|
|
58
|
-
const { kind, error, ...span_ctx } = span.context;
|
|
59
|
-
let status;
|
|
60
|
-
if (error) {
|
|
61
|
-
status = {
|
|
62
|
-
code: SpanStatusCode_ERROR,
|
|
63
|
-
};
|
|
64
|
-
if ('message' in error) {
|
|
65
|
-
status.message = error.message;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
otel_spans.push({
|
|
69
|
-
traceId: span.id.trace_id,
|
|
70
|
-
spanId: span.id.parent_id,
|
|
71
|
-
parentSpanId: span.parent?.parent_id,
|
|
72
|
-
name: span.name,
|
|
73
|
-
kind: map_kind(kind || 'INTERNAL'),
|
|
74
|
-
startTimeUnixNano: span.start * 1000000,
|
|
75
|
-
endTimeUnixNano: span.end ? span.end * 1000000 : undefined,
|
|
76
|
-
droppedAttributesCount: 0,
|
|
77
|
-
droppedEventsCount: 0,
|
|
78
|
-
droppedLinksCount: 0,
|
|
79
|
-
attributes: convert_object_to_kv(span_ctx),
|
|
80
|
-
status: status || { code: SpanStatusCode_UNSET },
|
|
81
|
-
events: span.events.map((i) => ({
|
|
82
|
-
name: i.name,
|
|
83
|
-
attributes: convert_object_to_kv(i.attributes),
|
|
84
|
-
droppedAttributesCount: 0,
|
|
85
|
-
timeUnixNano: i.timestamp * 1000000,
|
|
86
|
-
})),
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
return request({
|
|
90
|
-
resourceSpans: [
|
|
91
|
-
{
|
|
92
|
-
resource: {
|
|
93
|
-
attributes: convert_object_to_kv(context),
|
|
94
|
-
droppedAttributesCount: 0,
|
|
95
|
-
},
|
|
96
|
-
instrumentationLibrarySpans: [
|
|
97
|
-
{
|
|
98
|
-
instrumentationLibrary: {
|
|
99
|
-
name: name,
|
|
100
|
-
version: version,
|
|
101
|
-
},
|
|
102
|
-
spans: otel_spans,
|
|
103
|
-
},
|
|
104
|
-
],
|
|
105
|
-
},
|
|
106
|
-
],
|
|
107
|
-
});
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
export { exporter };
|
package/exporter.zipkin.d.ts
DELETED
package/exporter.zipkin.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const flattie = require('flattie');
|
|
4
|
-
|
|
5
|
-
const exporter = (request) => (spans, context) => {
|
|
6
|
-
const zipkin = [];
|
|
7
|
-
for (let span of spans) {
|
|
8
|
-
const { kind, error, ...span_ctx } = span.context;
|
|
9
|
-
if (error) {
|
|
10
|
-
if ('message' in error) {
|
|
11
|
-
span_ctx.error = {
|
|
12
|
-
name: error.name,
|
|
13
|
-
message: error.message,
|
|
14
|
-
stack: error.stack,
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
else {
|
|
18
|
-
span_ctx.error = true;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
zipkin.push({
|
|
22
|
-
id: span.id.parent_id,
|
|
23
|
-
traceId: span.id.trace_id,
|
|
24
|
-
parentId: span.parent ? span.parent.parent_id : undefined,
|
|
25
|
-
name: span.name,
|
|
26
|
-
kind: kind === 'INTERNAL' ? undefined : kind,
|
|
27
|
-
timestamp: span.start * 1000,
|
|
28
|
-
duration: span.end ? (span.end - span.start) * 1000 : undefined,
|
|
29
|
-
localEndpoint: context.localEndpoint || {
|
|
30
|
-
serviceName: span_ctx['service.name'],
|
|
31
|
-
},
|
|
32
|
-
tags: flattie.flattie({
|
|
33
|
-
...context,
|
|
34
|
-
...span_ctx,
|
|
35
|
-
}, '.', true),
|
|
36
|
-
annotations: span.events.map((i) => ({
|
|
37
|
-
value: `${i.name} :: ${JSON.stringify(i.attributes)}`,
|
|
38
|
-
timestamp: i.timestamp * 1000,
|
|
39
|
-
})),
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
return request(zipkin);
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
exports.exporter = exporter;
|
package/exporter.zipkin.mjs
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { flattie } from 'flattie';
|
|
2
|
-
|
|
3
|
-
const exporter = (request) => (spans, context) => {
|
|
4
|
-
const zipkin = [];
|
|
5
|
-
for (let span of spans) {
|
|
6
|
-
const { kind, error, ...span_ctx } = span.context;
|
|
7
|
-
if (error) {
|
|
8
|
-
if ('message' in error) {
|
|
9
|
-
span_ctx.error = {
|
|
10
|
-
name: error.name,
|
|
11
|
-
message: error.message,
|
|
12
|
-
stack: error.stack,
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
else {
|
|
16
|
-
span_ctx.error = true;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
zipkin.push({
|
|
20
|
-
id: span.id.parent_id,
|
|
21
|
-
traceId: span.id.trace_id,
|
|
22
|
-
parentId: span.parent ? span.parent.parent_id : undefined,
|
|
23
|
-
name: span.name,
|
|
24
|
-
kind: kind === 'INTERNAL' ? undefined : kind,
|
|
25
|
-
timestamp: span.start * 1000,
|
|
26
|
-
duration: span.end ? (span.end - span.start) * 1000 : undefined,
|
|
27
|
-
localEndpoint: context.localEndpoint || {
|
|
28
|
-
serviceName: span_ctx['service.name'],
|
|
29
|
-
},
|
|
30
|
-
tags: flattie({
|
|
31
|
-
...context,
|
|
32
|
-
...span_ctx,
|
|
33
|
-
}, '.', true),
|
|
34
|
-
annotations: span.events.map((i) => ({
|
|
35
|
-
value: `${i.name} :: ${JSON.stringify(i.attributes)}`,
|
|
36
|
-
timestamp: i.timestamp * 1000,
|
|
37
|
-
})),
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
return request(zipkin);
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
export { exporter };
|