@libo11y/server 0.8.0 → 0.9.0
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/dist/edge.d.ts +4 -8
- package/dist/edge.js +4 -8
- package/dist/exporters.d.ts +0 -15
- package/dist/exporters.js +101 -37
- package/dist/index.d.ts +1 -3
- package/dist/index.js +1 -3
- package/dist/otlp-transport.d.ts +3 -8
- package/dist/otlp-transport.js +87 -86
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +4 -4
- package/dist/fetch.d.ts +0 -35
- package/dist/fetch.js +0 -150
- package/dist/glob.d.ts +0 -14
- package/dist/glob.js +0 -177
- package/dist/http-common.d.ts +0 -78
- package/dist/http-common.js +0 -215
- package/dist/otlp-proto-metrics.d.ts +0 -21
- package/dist/otlp-proto-metrics.js +0 -401
- package/dist/serve.d.ts +0 -94
- package/dist/serve.js +0 -375
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* OTLP/protobuf metrics with exemplars. Upstream's ProtobufMetricsSerializer writes no exemplars, so
|
|
3
|
-
* this is a dependency-free encoder of opentelemetry-proto's ExportMetricsServiceRequest. It writes
|
|
4
|
-
* every field upstream writes, in upstream's order, so a collection without exemplars encodes to
|
|
5
|
-
* upstream's bytes exactly, and adds each data point's exemplars (NumberDataPoint field 5,
|
|
6
|
-
* HistogramDataPoint field 8, ExponentialHistogramDataPoint field 11).
|
|
7
|
-
*
|
|
8
|
-
* It walks the SDK's ResourceMetrics rather than the OTLP/JSON object core's JSON serializer builds,
|
|
9
|
-
* because JSON has no NaN or Infinity: a NaN gauge or an empty exponential histogram's infinite
|
|
10
|
-
* bounds would come back as null.
|
|
11
|
-
*/
|
|
12
|
-
import { type ResourceMetricsWithExemplars } from "@libo11y/core";
|
|
13
|
-
import { type IExportMetricsServiceResponse, type ISerializer } from "@opentelemetry/otlp-transformer";
|
|
14
|
-
import { type ResourceMetrics } from "@opentelemetry/sdk-metrics";
|
|
15
|
-
/**
|
|
16
|
-
* Encodes an ExportMetricsServiceRequest holding each collection in order, with the exemplars
|
|
17
|
-
* ExemplarStore.attach gave its data points.
|
|
18
|
-
*/
|
|
19
|
-
export declare function encodeMetricsRequest(collections: readonly ResourceMetricsWithExemplars[]): Uint8Array;
|
|
20
|
-
/** OTLP/protobuf metrics with exemplars, for upstream's OTLP HTTP export delegate. */
|
|
21
|
-
export declare const OtlpProtobufMetricsSerializer: ISerializer<ResourceMetrics | ResourceMetricsWithExemplars, IExportMetricsServiceResponse>;
|
|
@@ -1,401 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* OTLP/protobuf metrics with exemplars. Upstream's ProtobufMetricsSerializer writes no exemplars, so
|
|
3
|
-
* this is a dependency-free encoder of opentelemetry-proto's ExportMetricsServiceRequest. It writes
|
|
4
|
-
* every field upstream writes, in upstream's order, so a collection without exemplars encodes to
|
|
5
|
-
* upstream's bytes exactly, and adds each data point's exemplars (NumberDataPoint field 5,
|
|
6
|
-
* HistogramDataPoint field 8, ExponentialHistogramDataPoint field 11).
|
|
7
|
-
*
|
|
8
|
-
* It walks the SDK's ResourceMetrics rather than the OTLP/JSON object core's JSON serializer builds,
|
|
9
|
-
* because JSON has no NaN or Infinity: a NaN gauge or an empty exponential histogram's infinite
|
|
10
|
-
* bounds would come back as null.
|
|
11
|
-
*/
|
|
12
|
-
import { exemplarsOf } from "@libo11y/core";
|
|
13
|
-
import { ValueType } from "@opentelemetry/api";
|
|
14
|
-
import { ProtobufMetricsSerializer, } from "@opentelemetry/otlp-transformer";
|
|
15
|
-
import { AggregationTemporality, DataPointType, } from "@opentelemetry/sdk-metrics";
|
|
16
|
-
const VARINT = 0;
|
|
17
|
-
const FIXED64 = 1;
|
|
18
|
-
const LEN = 2;
|
|
19
|
-
const TWO_32 = 4294967296;
|
|
20
|
-
const MIN_INT64 = -(2 ** 63);
|
|
21
|
-
const MAX_INT64 = 2 ** 63;
|
|
22
|
-
const encoder = new TextEncoder();
|
|
23
|
-
/** A protobuf wire writer. Embedded messages are written to their own writer and then copied in. */
|
|
24
|
-
class Writer {
|
|
25
|
-
buf = new Uint8Array(256);
|
|
26
|
-
pos = 0;
|
|
27
|
-
reserve(n) {
|
|
28
|
-
if (this.pos + n <= this.buf.length)
|
|
29
|
-
return;
|
|
30
|
-
let size = this.buf.length * 2;
|
|
31
|
-
while (size < this.pos + n)
|
|
32
|
-
size *= 2;
|
|
33
|
-
const next = new Uint8Array(size);
|
|
34
|
-
next.set(this.buf.subarray(0, this.pos));
|
|
35
|
-
this.buf = next;
|
|
36
|
-
}
|
|
37
|
-
byte(b) {
|
|
38
|
-
this.reserve(1);
|
|
39
|
-
this.buf[this.pos++] = b;
|
|
40
|
-
}
|
|
41
|
-
tag(field, wireType) {
|
|
42
|
-
this.varint((field << 3) | wireType);
|
|
43
|
-
}
|
|
44
|
-
/** A varint from a 64-bit two's complement pair. */
|
|
45
|
-
varint64(low, high) {
|
|
46
|
-
let lo = low >>> 0;
|
|
47
|
-
let hi = high >>> 0;
|
|
48
|
-
while (hi > 0 || lo > 0x7f) {
|
|
49
|
-
this.byte((lo & 0x7f) | 0x80);
|
|
50
|
-
lo = ((lo >>> 7) | (hi << 25)) >>> 0;
|
|
51
|
-
hi >>>= 7;
|
|
52
|
-
}
|
|
53
|
-
this.byte(lo);
|
|
54
|
-
}
|
|
55
|
-
/** A varint for an integer number; a negative one is written as its 64-bit two's complement. */
|
|
56
|
-
varint(value) {
|
|
57
|
-
const [low, high] = split64(value);
|
|
58
|
-
this.varint64(low, high);
|
|
59
|
-
}
|
|
60
|
-
/** A zigzag varint, as sint32 fields take. */
|
|
61
|
-
sint32(value) {
|
|
62
|
-
this.varint64(((value << 1) ^ (value >> 31)) >>> 0, 0);
|
|
63
|
-
}
|
|
64
|
-
fixed64(low, high) {
|
|
65
|
-
this.reserve(8);
|
|
66
|
-
const l = low >>> 0;
|
|
67
|
-
const h = high >>> 0;
|
|
68
|
-
this.buf[this.pos++] = l & 0xff;
|
|
69
|
-
this.buf[this.pos++] = (l >>> 8) & 0xff;
|
|
70
|
-
this.buf[this.pos++] = (l >>> 16) & 0xff;
|
|
71
|
-
this.buf[this.pos++] = (l >>> 24) & 0xff;
|
|
72
|
-
this.buf[this.pos++] = h & 0xff;
|
|
73
|
-
this.buf[this.pos++] = (h >>> 8) & 0xff;
|
|
74
|
-
this.buf[this.pos++] = (h >>> 16) & 0xff;
|
|
75
|
-
this.buf[this.pos++] = (h >>> 24) & 0xff;
|
|
76
|
-
}
|
|
77
|
-
/** An unsigned or signed 64-bit integer number as fixed64 or sfixed64, as upstream converts it. */
|
|
78
|
-
fixed64Number(value) {
|
|
79
|
-
const [low, high] = split64(value);
|
|
80
|
-
this.fixed64(low, high);
|
|
81
|
-
}
|
|
82
|
-
fixed64BigInt(value) {
|
|
83
|
-
const v = BigInt.asUintN(64, value);
|
|
84
|
-
this.fixed64(Number(v & 0xffffffffn), Number(v >> 32n));
|
|
85
|
-
}
|
|
86
|
-
double(value) {
|
|
87
|
-
this.reserve(8);
|
|
88
|
-
new DataView(this.buf.buffer, this.buf.byteOffset + this.pos, 8).setFloat64(0, value, true);
|
|
89
|
-
this.pos += 8;
|
|
90
|
-
}
|
|
91
|
-
bytes(value) {
|
|
92
|
-
this.varint(value.length);
|
|
93
|
-
this.reserve(value.length);
|
|
94
|
-
this.buf.set(value, this.pos);
|
|
95
|
-
this.pos += value.length;
|
|
96
|
-
}
|
|
97
|
-
string(value) {
|
|
98
|
-
this.bytes(encoder.encode(value));
|
|
99
|
-
}
|
|
100
|
-
/** A length-delimited field whose content fn writes. */
|
|
101
|
-
message(field, fn) {
|
|
102
|
-
const inner = new Writer();
|
|
103
|
-
fn(inner);
|
|
104
|
-
this.tag(field, LEN);
|
|
105
|
-
this.bytes(inner.finish());
|
|
106
|
-
}
|
|
107
|
-
finish() {
|
|
108
|
-
return this.buf.slice(0, this.pos);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
// split64 is upstream's conversion of a number to a 64-bit two's complement pair: the low and high
|
|
112
|
-
// 32 bits of its magnitude, negated for a negative value.
|
|
113
|
-
function split64(value) {
|
|
114
|
-
if (value >= 0)
|
|
115
|
-
return [value >>> 0, (value / TWO_32) >>> 0];
|
|
116
|
-
const abs = Math.abs(value);
|
|
117
|
-
let low = ~(abs >>> 0) >>> 0;
|
|
118
|
-
let high = ~((abs / TWO_32) >>> 0) >>> 0;
|
|
119
|
-
low = (low + 1) >>> 0;
|
|
120
|
-
if (low === 0)
|
|
121
|
-
high = (high + 1) >>> 0;
|
|
122
|
-
return [low, high];
|
|
123
|
-
}
|
|
124
|
-
function hrTimeNanos(t) {
|
|
125
|
-
return BigInt(Math.trunc(t[0])) * 1000000000n + BigInt(Math.trunc(t[1]));
|
|
126
|
-
}
|
|
127
|
-
function hex(id) {
|
|
128
|
-
const out = new Uint8Array(id.length >>> 1);
|
|
129
|
-
for (let i = 0; i < out.length; i++)
|
|
130
|
-
out[i] = Number.parseInt(id.slice(i * 2, i * 2 + 2), 16);
|
|
131
|
-
return out;
|
|
132
|
-
}
|
|
133
|
-
// anyValue writes an AnyValue's content as upstream's writeAnyValue does.
|
|
134
|
-
function anyValue(w, value) {
|
|
135
|
-
switch (typeof value) {
|
|
136
|
-
case "string":
|
|
137
|
-
w.tag(1, LEN);
|
|
138
|
-
w.string(value);
|
|
139
|
-
return;
|
|
140
|
-
case "boolean":
|
|
141
|
-
w.tag(2, VARINT);
|
|
142
|
-
w.varint(value ? 1 : 0);
|
|
143
|
-
return;
|
|
144
|
-
case "number":
|
|
145
|
-
if (Number.isInteger(value) && value >= MIN_INT64 && value < MAX_INT64) {
|
|
146
|
-
w.tag(3, VARINT);
|
|
147
|
-
w.varint(value);
|
|
148
|
-
}
|
|
149
|
-
else {
|
|
150
|
-
w.tag(4, FIXED64);
|
|
151
|
-
w.double(value);
|
|
152
|
-
}
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
if (value instanceof Uint8Array) {
|
|
156
|
-
w.tag(7, LEN);
|
|
157
|
-
w.bytes(value);
|
|
158
|
-
}
|
|
159
|
-
else if (Array.isArray(value)) {
|
|
160
|
-
w.message(5, (arr) => {
|
|
161
|
-
for (const item of value)
|
|
162
|
-
arr.message(1, (v) => anyValue(v, item));
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
else if (typeof value === "object" && value !== null) {
|
|
166
|
-
w.message(6, (list) => {
|
|
167
|
-
for (const [k, v] of Object.entries(value))
|
|
168
|
-
list.message(1, (kv) => keyValue(kv, k, v));
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
function keyValue(w, key, value) {
|
|
173
|
-
w.tag(1, LEN);
|
|
174
|
-
w.string(key);
|
|
175
|
-
w.message(2, (v) => anyValue(v, value));
|
|
176
|
-
}
|
|
177
|
-
function attributes(w, field, attrs) {
|
|
178
|
-
if (attrs === undefined)
|
|
179
|
-
return;
|
|
180
|
-
for (const [key, value] of Object.entries(attrs))
|
|
181
|
-
w.message(field, (kv) => keyValue(kv, key, value));
|
|
182
|
-
}
|
|
183
|
-
function exemplars(w, field, point, valueType) {
|
|
184
|
-
for (const e of exemplarsOf(point)) {
|
|
185
|
-
w.message(field, (x) => {
|
|
186
|
-
attributes(x, 7, e.filteredAttributes);
|
|
187
|
-
x.tag(2, FIXED64);
|
|
188
|
-
x.fixed64BigInt(e.timeUnixNano);
|
|
189
|
-
if (valueType === ValueType.INT) {
|
|
190
|
-
x.tag(6, FIXED64);
|
|
191
|
-
x.fixed64Number(e.value);
|
|
192
|
-
}
|
|
193
|
-
else {
|
|
194
|
-
x.tag(3, FIXED64);
|
|
195
|
-
x.double(e.value);
|
|
196
|
-
}
|
|
197
|
-
if (e.traceId !== undefined && e.spanId !== undefined) {
|
|
198
|
-
x.tag(4, LEN);
|
|
199
|
-
x.bytes(hex(e.spanId));
|
|
200
|
-
x.tag(5, LEN);
|
|
201
|
-
x.bytes(hex(e.traceId));
|
|
202
|
-
}
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
function times(w, point) {
|
|
207
|
-
w.tag(2, FIXED64);
|
|
208
|
-
w.fixed64BigInt(hrTimeNanos(point.startTime));
|
|
209
|
-
w.tag(3, FIXED64);
|
|
210
|
-
w.fixed64BigInt(hrTimeNanos(point.endTime));
|
|
211
|
-
}
|
|
212
|
-
function numberPoint(w, point, valueType) {
|
|
213
|
-
times(w, point);
|
|
214
|
-
if (valueType === ValueType.INT) {
|
|
215
|
-
w.tag(6, FIXED64);
|
|
216
|
-
w.fixed64Number(point.value);
|
|
217
|
-
}
|
|
218
|
-
else {
|
|
219
|
-
w.tag(4, FIXED64);
|
|
220
|
-
w.double(point.value);
|
|
221
|
-
}
|
|
222
|
-
attributes(w, 7, point.attributes);
|
|
223
|
-
exemplars(w, 5, point, valueType);
|
|
224
|
-
}
|
|
225
|
-
function histogramPoint(w, point, valueType) {
|
|
226
|
-
const h = point.value;
|
|
227
|
-
times(w, point);
|
|
228
|
-
w.tag(4, FIXED64);
|
|
229
|
-
w.fixed64Number(h.count);
|
|
230
|
-
if (h.sum !== undefined) {
|
|
231
|
-
w.tag(5, FIXED64);
|
|
232
|
-
w.double(h.sum);
|
|
233
|
-
}
|
|
234
|
-
if (h.buckets.counts.length > 0) {
|
|
235
|
-
w.message(6, (p) => {
|
|
236
|
-
for (const c of h.buckets.counts)
|
|
237
|
-
p.fixed64Number(c);
|
|
238
|
-
});
|
|
239
|
-
}
|
|
240
|
-
if (h.buckets.boundaries.length > 0) {
|
|
241
|
-
w.message(7, (p) => {
|
|
242
|
-
for (const b of h.buckets.boundaries)
|
|
243
|
-
p.double(b);
|
|
244
|
-
});
|
|
245
|
-
}
|
|
246
|
-
attributes(w, 9, point.attributes);
|
|
247
|
-
if (h.min !== undefined) {
|
|
248
|
-
w.tag(11, FIXED64);
|
|
249
|
-
w.double(h.min);
|
|
250
|
-
}
|
|
251
|
-
if (h.max !== undefined) {
|
|
252
|
-
w.tag(12, FIXED64);
|
|
253
|
-
w.double(h.max);
|
|
254
|
-
}
|
|
255
|
-
exemplars(w, 8, point, valueType);
|
|
256
|
-
}
|
|
257
|
-
function buckets(w, field, offset, counts) {
|
|
258
|
-
w.message(field, (b) => {
|
|
259
|
-
if (offset !== 0) {
|
|
260
|
-
b.tag(1, VARINT);
|
|
261
|
-
b.sint32(offset);
|
|
262
|
-
}
|
|
263
|
-
if (counts.length > 0) {
|
|
264
|
-
b.message(2, (p) => {
|
|
265
|
-
for (const c of counts)
|
|
266
|
-
p.varint(c);
|
|
267
|
-
});
|
|
268
|
-
}
|
|
269
|
-
});
|
|
270
|
-
}
|
|
271
|
-
function exponentialPoint(w, point, valueType) {
|
|
272
|
-
const h = point.value;
|
|
273
|
-
attributes(w, 1, point.attributes);
|
|
274
|
-
times(w, point);
|
|
275
|
-
w.tag(4, FIXED64);
|
|
276
|
-
w.fixed64Number(h.count);
|
|
277
|
-
if (h.sum !== undefined) {
|
|
278
|
-
w.tag(5, FIXED64);
|
|
279
|
-
w.double(h.sum);
|
|
280
|
-
}
|
|
281
|
-
if (h.scale !== 0) {
|
|
282
|
-
w.tag(6, VARINT);
|
|
283
|
-
w.sint32(h.scale);
|
|
284
|
-
}
|
|
285
|
-
w.tag(7, FIXED64);
|
|
286
|
-
w.fixed64Number(h.zeroCount);
|
|
287
|
-
buckets(w, 8, h.positive.offset, h.positive.bucketCounts);
|
|
288
|
-
buckets(w, 9, h.negative.offset, h.negative.bucketCounts);
|
|
289
|
-
if (h.min !== undefined) {
|
|
290
|
-
w.tag(12, FIXED64);
|
|
291
|
-
w.double(h.min);
|
|
292
|
-
}
|
|
293
|
-
if (h.max !== undefined) {
|
|
294
|
-
w.tag(13, FIXED64);
|
|
295
|
-
w.double(h.max);
|
|
296
|
-
}
|
|
297
|
-
exemplars(w, 11, point, valueType);
|
|
298
|
-
}
|
|
299
|
-
function temporality(w, t) {
|
|
300
|
-
const value = t === AggregationTemporality.DELTA ? 1 : t === AggregationTemporality.CUMULATIVE ? 2 : 0;
|
|
301
|
-
if (value === 0)
|
|
302
|
-
return;
|
|
303
|
-
w.tag(2, VARINT);
|
|
304
|
-
w.varint(value);
|
|
305
|
-
}
|
|
306
|
-
function metric(w, m) {
|
|
307
|
-
const valueType = m.descriptor.valueType;
|
|
308
|
-
w.tag(1, LEN);
|
|
309
|
-
w.string(m.descriptor.name);
|
|
310
|
-
if (m.descriptor.description) {
|
|
311
|
-
w.tag(2, LEN);
|
|
312
|
-
w.string(m.descriptor.description);
|
|
313
|
-
}
|
|
314
|
-
if (m.descriptor.unit) {
|
|
315
|
-
w.tag(3, LEN);
|
|
316
|
-
w.string(m.descriptor.unit);
|
|
317
|
-
}
|
|
318
|
-
switch (m.dataPointType) {
|
|
319
|
-
case DataPointType.GAUGE:
|
|
320
|
-
w.message(5, (g) => {
|
|
321
|
-
for (const p of m.dataPoints)
|
|
322
|
-
g.message(1, (dp) => numberPoint(dp, p, valueType));
|
|
323
|
-
});
|
|
324
|
-
return;
|
|
325
|
-
case DataPointType.SUM:
|
|
326
|
-
w.message(7, (s) => {
|
|
327
|
-
for (const p of m.dataPoints)
|
|
328
|
-
s.message(1, (dp) => numberPoint(dp, p, valueType));
|
|
329
|
-
temporality(s, m.aggregationTemporality);
|
|
330
|
-
if (m.isMonotonic) {
|
|
331
|
-
s.tag(3, VARINT);
|
|
332
|
-
s.varint(1);
|
|
333
|
-
}
|
|
334
|
-
});
|
|
335
|
-
return;
|
|
336
|
-
case DataPointType.HISTOGRAM:
|
|
337
|
-
w.message(9, (h) => {
|
|
338
|
-
for (const p of m.dataPoints)
|
|
339
|
-
h.message(1, (dp) => histogramPoint(dp, p, valueType));
|
|
340
|
-
temporality(h, m.aggregationTemporality);
|
|
341
|
-
});
|
|
342
|
-
return;
|
|
343
|
-
case DataPointType.EXPONENTIAL_HISTOGRAM:
|
|
344
|
-
w.message(10, (h) => {
|
|
345
|
-
for (const p of m.dataPoints)
|
|
346
|
-
h.message(1, (dp) => exponentialPoint(dp, p, valueType));
|
|
347
|
-
temporality(h, m.aggregationTemporality);
|
|
348
|
-
});
|
|
349
|
-
return;
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
function scopeMetrics(w, sm) {
|
|
353
|
-
const scope = sm.scope;
|
|
354
|
-
w.message(1, (s) => {
|
|
355
|
-
s.tag(1, LEN);
|
|
356
|
-
s.string(scope.name);
|
|
357
|
-
if (scope.version) {
|
|
358
|
-
s.tag(2, LEN);
|
|
359
|
-
s.string(scope.version);
|
|
360
|
-
}
|
|
361
|
-
attributes(s, 3, scope.attributes);
|
|
362
|
-
if (scope.droppedAttributesCount) {
|
|
363
|
-
s.tag(4, VARINT);
|
|
364
|
-
s.varint(scope.droppedAttributesCount);
|
|
365
|
-
}
|
|
366
|
-
});
|
|
367
|
-
for (const m of sm.metrics)
|
|
368
|
-
w.message(2, (mw) => metric(mw, m));
|
|
369
|
-
if (scope.schemaUrl) {
|
|
370
|
-
w.tag(3, LEN);
|
|
371
|
-
w.string(scope.schemaUrl);
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
function resourceMetrics(w, rm) {
|
|
375
|
-
w.message(1, (r) => {
|
|
376
|
-
attributes(r, 1, rm.resource.attributes);
|
|
377
|
-
r.tag(2, VARINT);
|
|
378
|
-
r.varint(0);
|
|
379
|
-
});
|
|
380
|
-
for (const sm of rm.scopeMetrics)
|
|
381
|
-
w.message(2, (s) => scopeMetrics(s, sm));
|
|
382
|
-
if (rm.resource.schemaUrl) {
|
|
383
|
-
w.tag(3, LEN);
|
|
384
|
-
w.string(rm.resource.schemaUrl);
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
/**
|
|
388
|
-
* Encodes an ExportMetricsServiceRequest holding each collection in order, with the exemplars
|
|
389
|
-
* ExemplarStore.attach gave its data points.
|
|
390
|
-
*/
|
|
391
|
-
export function encodeMetricsRequest(collections) {
|
|
392
|
-
const w = new Writer();
|
|
393
|
-
for (const rm of collections)
|
|
394
|
-
w.message(1, (r) => resourceMetrics(r, rm));
|
|
395
|
-
return w.finish();
|
|
396
|
-
}
|
|
397
|
-
/** OTLP/protobuf metrics with exemplars, for upstream's OTLP HTTP export delegate. */
|
|
398
|
-
export const OtlpProtobufMetricsSerializer = {
|
|
399
|
-
serializeRequest: (rm) => encodeMetricsRequest([rm]),
|
|
400
|
-
deserializeResponse: (data) => ProtobufMetricsSerializer.deserializeResponse(data),
|
|
401
|
-
};
|
package/dist/serve.d.ts
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* instrumentServe: server instrumentation for fetch-style handlers, `(Request) => Response`, as
|
|
3
|
-
* Bun.serve, Hono, Elysia and node:http adapters use. It is the counterpart of Go's
|
|
4
|
-
* o11yhttp.NewHandler: a SERVER span named "<METHOD> <route>", http.server.request.duration with
|
|
5
|
-
* exemplars, and optionally the o11y.request.summary canonical line.
|
|
6
|
-
*
|
|
7
|
-
* For a watched body (HTML and event streams by default), the span, the duration and the summary
|
|
8
|
-
* end when the response body finishes, errors or is cancelled, from a body wrapper that holds the
|
|
9
|
-
* span itself. For any other response they end when the handler returns. Nothing at the end reads
|
|
10
|
-
* the active context, because Bun 1.3 loses it inside an async generator body after its first
|
|
11
|
-
* await (oven-sh/bun#24199).
|
|
12
|
-
*/
|
|
13
|
-
import { type Telemetry } from "@libo11y/core";
|
|
14
|
-
/** Options for {@link instrumentServe}. */
|
|
15
|
-
export interface ServeOptions {
|
|
16
|
-
/** The telemetry whose providers and propagator to use. Without it, the globals setup installs. */
|
|
17
|
-
readonly telemetry?: Telemetry;
|
|
18
|
-
/**
|
|
19
|
-
* Resolves the route template of a request, such as "/projects/:id", for the span name,
|
|
20
|
-
* http.route and the metric. A method prefix such as "GET /x" is removed from the template.
|
|
21
|
-
* The span name uses the normalized request method followed by the route when present.
|
|
22
|
-
* A function that throws leaves the request unrouted, and is reported to the error handler by the
|
|
23
|
-
* class of what it threw, never with its message, which can quote the URL.
|
|
24
|
-
*/
|
|
25
|
-
readonly route?: (req: Request) => string | undefined;
|
|
26
|
-
/**
|
|
27
|
-
* An internet-facing server: inbound trace context starts a new root span linked to it instead
|
|
28
|
-
* of becoming its parent, so untrusted callers cannot graft onto internal traces. Baggage is
|
|
29
|
-
* still extracted.
|
|
30
|
-
*/
|
|
31
|
-
readonly publicEndpoint?: boolean;
|
|
32
|
-
/**
|
|
33
|
-
* URL paths to leave uninstrumented, as Go path.Match patterns ("/healthz", "/debug/*"). They
|
|
34
|
-
* match the percent-decoded path, as in Go, so "/café" matches a request for "/caf%C3%A9". A
|
|
35
|
-
* matching request gets no span, metric or summary. A malformed pattern never matches.
|
|
36
|
-
*/
|
|
37
|
-
readonly ignorePaths?: readonly string[];
|
|
38
|
-
/**
|
|
39
|
-
* Adds `Server-Timing: traceparent;desc="00-<trace>-<span>-<flags>"` to text/html responses, so
|
|
40
|
-
* the page can join the server's trace. A span without a valid span context, as from a no-op or
|
|
41
|
-
* disabled tracer provider, adds no entry. It works whether or not the body is watched (see
|
|
42
|
-
* watchBody); the headers of an unwatched response are changed in place when they are mutable.
|
|
43
|
-
*/
|
|
44
|
-
readonly serverTiming?: boolean;
|
|
45
|
-
/**
|
|
46
|
-
* Emits one o11y.request.summary event per request, carrying the request's wide record (see
|
|
47
|
-
* currentRecord in the core package) and then the method, status, outcome, duration and route. It
|
|
48
|
-
* needs telemetry; without it this option is a silent no-op, as in Go.
|
|
49
|
-
*/
|
|
50
|
-
readonly canonicalLine?: boolean;
|
|
51
|
-
/**
|
|
52
|
-
* Decides whether a response's body is watched, so that the span, the duration and the summary end
|
|
53
|
-
* when the body finishes, errors or is cancelled rather than when the handler returns. A watched
|
|
54
|
-
* body is passed through a stream wrapper, so a body of known length is sent chunked, without
|
|
55
|
-
* Content-Length, and Bun cannot send a Bun.file body with sendfile. An unwatched response is
|
|
56
|
-
* returned exactly as the handler made it, and its duration excludes the body's transfer.
|
|
57
|
-
*
|
|
58
|
-
* The default watches responses whose content type is text/html or text/event-stream, compared
|
|
59
|
-
* case-insensitively without parameters: pages that stream as they render, and event streams.
|
|
60
|
-
* A predicate that throws watches nothing, and is reported to the error handler by the class of
|
|
61
|
-
* what it threw. Responses to HEAD requests and with status 101, 204, 205 or 304 are never
|
|
62
|
-
* watched, since they carry no body.
|
|
63
|
-
*/
|
|
64
|
-
readonly watchBody?: (res: Response) => boolean;
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Wraps a fetch-style handler with server instrumentation. Extra handler arguments, such as
|
|
68
|
-
* Bun.serve's server, pass through. The handler runs inside the server span's context, so spans and
|
|
69
|
-
* logs it makes are children of it. A throw marks the span failed, records the exception and a 500,
|
|
70
|
-
* and is re-thrown. A watched body (see ServeOptions.watchBody: HTML and event streams by default)
|
|
71
|
-
* is passed through a wrapper that ends the span when the body finishes; that wrapper is a stream,
|
|
72
|
-
* so a body of known length is sent chunked. Any other response ends the span when the handler
|
|
73
|
-
* returns and is passed on untouched.
|
|
74
|
-
*
|
|
75
|
-
* The telemetry never fails the request. A propagator that throws on extract leaves the request
|
|
76
|
-
* without the inbound context, a span that cannot start leaves it uninstrumented, and a span that
|
|
77
|
-
* cannot end changes nothing the caller sees. Each is reported to the error handler, and the handler
|
|
78
|
-
* runs exactly once either way. Only the handler's own error reaches the caller.
|
|
79
|
-
*/
|
|
80
|
-
export declare function instrumentServe<A extends unknown[]>(handler: (req: Request, ...rest: A) => Response | Promise<Response>, opts?: ServeOptions): (req: Request, ...rest: A) => Promise<Response>;
|
|
81
|
-
/**
|
|
82
|
-
* Sets the route template of the server request being handled, such as "/projects/:id", for
|
|
83
|
-
* frameworks that route inside the handler, as TanStack Start does. It is the counterpart of Go
|
|
84
|
-
* reading r.Pattern after the ServeMux has run. When the request ends, the route set last names
|
|
85
|
-
* the span using the normalized request method and the route template
|
|
86
|
-
* and is the http.route of the span, the duration metric and the summary, in place of the one
|
|
87
|
-
* ServeOptions.route resolved. The span starts under the name ServeOptions.route gives, so a
|
|
88
|
-
* sampler sees that one.
|
|
89
|
-
*
|
|
90
|
-
* It finds the request through the active context, which instrumentServe sets for the handler, so
|
|
91
|
-
* it needs a context manager (setup installs one). Outside a request, after it has ended, or with
|
|
92
|
-
* an empty route, it does nothing.
|
|
93
|
-
*/
|
|
94
|
-
export declare function setRoute(route: string): void;
|