@nextscope/next 0.1.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/LICENSE +21 -0
- package/README.md +272 -0
- package/dist/config.d.ts +43 -0
- package/dist/config.js +155 -0
- package/dist/config.js.map +1 -0
- package/dist/forwarder.d.ts +26 -0
- package/dist/forwarder.js +88 -0
- package/dist/forwarder.js.map +1 -0
- package/dist/inspector/model/index.d.ts +79 -0
- package/dist/inspector/model/index.js +514 -0
- package/dist/inspector/model/index.js.map +1 -0
- package/dist/inspector/model/types.d.ts +152 -0
- package/dist/inspector/model/types.js +3 -0
- package/dist/inspector/model/types.js.map +1 -0
- package/dist/inspector-assets.d.ts +2 -0
- package/dist/inspector-assets.js +7 -0
- package/dist/inspector-assets.js.map +1 -0
- package/dist/next-types.d.ts +26 -0
- package/dist/next-types.js +3 -0
- package/dist/next-types.js.map +1 -0
- package/dist/otel.d.ts +102 -0
- package/dist/otel.js +137 -0
- package/dist/otel.js.map +1 -0
- package/dist/server.d.ts +12 -0
- package/dist/server.js +179 -0
- package/dist/server.js.map +1 -0
- package/dist/store.d.ts +164 -0
- package/dist/store.js +479 -0
- package/dist/store.js.map +1 -0
- package/dist/suppression.d.ts +8 -0
- package/dist/suppression.js +115 -0
- package/dist/suppression.js.map +1 -0
- package/dist/ui.d.ts +3 -0
- package/dist/ui.js +27 -0
- package/dist/ui.js.map +1 -0
- package/package.json +60 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inspector-assets.js","sourceRoot":"","sources":["../src/inspector-assets.ts"],"names":[],"mappings":";;;AAAA,mEAAmE;AACtD,QAAA,YAAY,GAAG,02hBAA02hB,CAAA;AACz3hB,QAAA,WAAW,GAAG,yk0OAAyk0O,CAAA"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export type NextConfig = object & {
|
|
2
|
+
rewrites?: () => Promise<Rewrites> | Rewrites;
|
|
3
|
+
};
|
|
4
|
+
export type Rewrites = Rewrite[] | RewriteGroups;
|
|
5
|
+
export interface Rewrite {
|
|
6
|
+
source: string;
|
|
7
|
+
destination: string;
|
|
8
|
+
basePath?: false;
|
|
9
|
+
locale?: false;
|
|
10
|
+
has?: RouteHas[];
|
|
11
|
+
missing?: RouteHas[];
|
|
12
|
+
}
|
|
13
|
+
export type RouteHas = {
|
|
14
|
+
type: 'header' | 'cookie' | 'query';
|
|
15
|
+
key: string;
|
|
16
|
+
value?: string;
|
|
17
|
+
} | {
|
|
18
|
+
type: 'host';
|
|
19
|
+
key?: undefined;
|
|
20
|
+
value: string;
|
|
21
|
+
};
|
|
22
|
+
export interface RewriteGroups {
|
|
23
|
+
beforeFiles?: Rewrite[];
|
|
24
|
+
afterFiles?: Rewrite[];
|
|
25
|
+
fallback?: Rewrite[];
|
|
26
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"next-types.js","sourceRoot":"","sources":["../src/next-types.ts"],"names":[],"mappings":""}
|
package/dist/otel.d.ts
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
export interface OtlpJsonBatch {
|
|
2
|
+
resourceSpans?: OtlpResourceSpan[];
|
|
3
|
+
}
|
|
4
|
+
export interface OtlpResourceSpan {
|
|
5
|
+
resource?: {
|
|
6
|
+
attributes?: OtlpAttribute[];
|
|
7
|
+
};
|
|
8
|
+
scopeSpans?: OtlpScopeSpan[];
|
|
9
|
+
instrumentationLibrarySpans?: OtlpScopeSpan[];
|
|
10
|
+
}
|
|
11
|
+
export interface OtlpScopeSpan {
|
|
12
|
+
scope?: {
|
|
13
|
+
name?: string;
|
|
14
|
+
version?: string;
|
|
15
|
+
attributes?: OtlpAttribute[];
|
|
16
|
+
};
|
|
17
|
+
instrumentationLibrary?: {
|
|
18
|
+
name?: string;
|
|
19
|
+
version?: string;
|
|
20
|
+
attributes?: OtlpAttribute[];
|
|
21
|
+
};
|
|
22
|
+
spans?: OtlpSpan[];
|
|
23
|
+
}
|
|
24
|
+
export interface OtlpSpan {
|
|
25
|
+
traceId?: string;
|
|
26
|
+
spanId?: string;
|
|
27
|
+
parentSpanId?: string;
|
|
28
|
+
name?: string;
|
|
29
|
+
kind?: string | number;
|
|
30
|
+
startTimeUnixNano?: string | number;
|
|
31
|
+
endTimeUnixNano?: string | number;
|
|
32
|
+
attributes?: OtlpAttribute[];
|
|
33
|
+
events?: OtlpSpanEvent[];
|
|
34
|
+
links?: OtlpSpanLink[];
|
|
35
|
+
status?: {
|
|
36
|
+
code?: string | number;
|
|
37
|
+
message?: string;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
export interface OtlpSpanEvent {
|
|
41
|
+
timeUnixNano?: string | number;
|
|
42
|
+
name?: string;
|
|
43
|
+
attributes?: OtlpAttribute[];
|
|
44
|
+
}
|
|
45
|
+
export interface OtlpSpanLink {
|
|
46
|
+
traceId?: string;
|
|
47
|
+
spanId?: string;
|
|
48
|
+
traceState?: string;
|
|
49
|
+
attributes?: OtlpAttribute[];
|
|
50
|
+
}
|
|
51
|
+
export interface OtlpAttribute {
|
|
52
|
+
key?: string;
|
|
53
|
+
value?: {
|
|
54
|
+
stringValue?: string;
|
|
55
|
+
intValue?: string | number;
|
|
56
|
+
doubleValue?: string | number;
|
|
57
|
+
boolValue?: boolean;
|
|
58
|
+
arrayValue?: {
|
|
59
|
+
values?: OtlpAttribute['value'][];
|
|
60
|
+
};
|
|
61
|
+
kvlistValue?: {
|
|
62
|
+
values?: OtlpAttribute[];
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
export interface NormalizedSpan {
|
|
67
|
+
traceId: string;
|
|
68
|
+
spanId: string;
|
|
69
|
+
parentSpanId?: string;
|
|
70
|
+
name: string;
|
|
71
|
+
kind?: string | number;
|
|
72
|
+
startTimeUnixNano: bigint;
|
|
73
|
+
endTimeUnixNano: bigint;
|
|
74
|
+
durationMs: number;
|
|
75
|
+
attributes: Record<string, unknown>;
|
|
76
|
+
resourceAttributes: Record<string, unknown>;
|
|
77
|
+
events: NormalizedSpanEvent[];
|
|
78
|
+
links: NormalizedSpanLink[];
|
|
79
|
+
status?: {
|
|
80
|
+
code?: string | number;
|
|
81
|
+
message?: string;
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
export interface NormalizedSpanEvent {
|
|
85
|
+
timeUnixNano: bigint;
|
|
86
|
+
name: string;
|
|
87
|
+
attributes: Record<string, unknown>;
|
|
88
|
+
}
|
|
89
|
+
export interface NormalizedSpanLink {
|
|
90
|
+
traceId?: string;
|
|
91
|
+
spanId?: string;
|
|
92
|
+
traceState?: string;
|
|
93
|
+
attributes: Record<string, unknown>;
|
|
94
|
+
}
|
|
95
|
+
export declare class OtlpParseError extends Error {
|
|
96
|
+
constructor(message: string);
|
|
97
|
+
}
|
|
98
|
+
export declare function normalizeOtlpJsonBatch(batch: OtlpJsonBatch): NormalizedSpan[];
|
|
99
|
+
export declare function attributesToRecord(attributes: OtlpAttribute[]): Record<string, unknown>;
|
|
100
|
+
export declare function decodeValue(value: OtlpAttribute['value']): unknown;
|
|
101
|
+
export declare function toBigInt(value: string | number | undefined): bigint;
|
|
102
|
+
export declare function toTimestampNano(value: string | number | undefined, fieldName?: string): bigint;
|
package/dist/otel.js
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OtlpParseError = void 0;
|
|
4
|
+
exports.normalizeOtlpJsonBatch = normalizeOtlpJsonBatch;
|
|
5
|
+
exports.attributesToRecord = attributesToRecord;
|
|
6
|
+
exports.decodeValue = decodeValue;
|
|
7
|
+
exports.toBigInt = toBigInt;
|
|
8
|
+
exports.toTimestampNano = toTimestampNano;
|
|
9
|
+
class OtlpParseError extends Error {
|
|
10
|
+
constructor(message) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.name = 'OtlpParseError';
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.OtlpParseError = OtlpParseError;
|
|
16
|
+
function normalizeOtlpJsonBatch(batch) {
|
|
17
|
+
const spans = [];
|
|
18
|
+
for (const resourceSpan of batch.resourceSpans ?? []) {
|
|
19
|
+
const resourceAttributes = attributesToRecord(resourceSpan.resource?.attributes ?? []);
|
|
20
|
+
const scopeSpans = resourceSpan.scopeSpans ?? resourceSpan.instrumentationLibrarySpans ?? [];
|
|
21
|
+
for (const scopeSpan of scopeSpans) {
|
|
22
|
+
for (const span of scopeSpan.spans ?? []) {
|
|
23
|
+
if (!span.traceId || !span.spanId) {
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
const startTimeUnixNano = toTimestampNano(span.startTimeUnixNano, 'span.startTimeUnixNano');
|
|
27
|
+
const endTimeUnixNano = toTimestampNano(span.endTimeUnixNano, 'span.endTimeUnixNano');
|
|
28
|
+
if (endTimeUnixNano < startTimeUnixNano) {
|
|
29
|
+
throw new OtlpParseError('span.endTimeUnixNano must be greater than or equal to span.startTimeUnixNano');
|
|
30
|
+
}
|
|
31
|
+
spans.push({
|
|
32
|
+
traceId: span.traceId,
|
|
33
|
+
spanId: span.spanId,
|
|
34
|
+
parentSpanId: span.parentSpanId || undefined,
|
|
35
|
+
name: span.name ?? '(unnamed span)',
|
|
36
|
+
kind: span.kind,
|
|
37
|
+
startTimeUnixNano,
|
|
38
|
+
endTimeUnixNano,
|
|
39
|
+
durationMs: nanosToMillis(endTimeUnixNano - startTimeUnixNano),
|
|
40
|
+
attributes: attributesToRecord(span.attributes ?? []),
|
|
41
|
+
resourceAttributes,
|
|
42
|
+
events: normalizeEvents(span.events ?? []),
|
|
43
|
+
links: normalizeLinks(span.links ?? []),
|
|
44
|
+
status: span.status,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return spans;
|
|
50
|
+
}
|
|
51
|
+
function normalizeEvents(events) {
|
|
52
|
+
return events.map((event) => ({
|
|
53
|
+
timeUnixNano: toTimestampNano(event.timeUnixNano, 'span.events[].timeUnixNano'),
|
|
54
|
+
name: event.name ?? '(unnamed event)',
|
|
55
|
+
attributes: attributesToRecord(event.attributes ?? []),
|
|
56
|
+
}));
|
|
57
|
+
}
|
|
58
|
+
function normalizeLinks(links) {
|
|
59
|
+
return links.map((link) => ({
|
|
60
|
+
traceId: link.traceId,
|
|
61
|
+
spanId: link.spanId,
|
|
62
|
+
traceState: link.traceState,
|
|
63
|
+
attributes: attributesToRecord(link.attributes ?? []),
|
|
64
|
+
}));
|
|
65
|
+
}
|
|
66
|
+
function attributesToRecord(attributes) {
|
|
67
|
+
const record = {};
|
|
68
|
+
for (const attribute of attributes) {
|
|
69
|
+
if (!attribute.key) {
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
record[attribute.key] = decodeValue(attribute.value);
|
|
73
|
+
}
|
|
74
|
+
return record;
|
|
75
|
+
}
|
|
76
|
+
function decodeValue(value) {
|
|
77
|
+
if (!value) {
|
|
78
|
+
return undefined;
|
|
79
|
+
}
|
|
80
|
+
if ('stringValue' in value) {
|
|
81
|
+
return value.stringValue;
|
|
82
|
+
}
|
|
83
|
+
if ('intValue' in value) {
|
|
84
|
+
return decodeIntegerValue(value.intValue);
|
|
85
|
+
}
|
|
86
|
+
if ('doubleValue' in value) {
|
|
87
|
+
return Number(value.doubleValue);
|
|
88
|
+
}
|
|
89
|
+
if ('boolValue' in value) {
|
|
90
|
+
return value.boolValue;
|
|
91
|
+
}
|
|
92
|
+
if ('arrayValue' in value) {
|
|
93
|
+
return (value.arrayValue?.values ?? []).map(decodeValue);
|
|
94
|
+
}
|
|
95
|
+
if ('kvlistValue' in value) {
|
|
96
|
+
return attributesToRecord(value.kvlistValue?.values ?? []);
|
|
97
|
+
}
|
|
98
|
+
return undefined;
|
|
99
|
+
}
|
|
100
|
+
function toBigInt(value) {
|
|
101
|
+
if (value === undefined) {
|
|
102
|
+
return 0n;
|
|
103
|
+
}
|
|
104
|
+
return BigInt(value);
|
|
105
|
+
}
|
|
106
|
+
function toTimestampNano(value, fieldName = 'timestamp') {
|
|
107
|
+
if (value === undefined) {
|
|
108
|
+
return 0n;
|
|
109
|
+
}
|
|
110
|
+
if (typeof value === 'number') {
|
|
111
|
+
if (!Number.isSafeInteger(value) || value < 0) {
|
|
112
|
+
throw new OtlpParseError(`${fieldName} must be a non-negative safe integer`);
|
|
113
|
+
}
|
|
114
|
+
return BigInt(value);
|
|
115
|
+
}
|
|
116
|
+
if (!/^\d+$/.test(value)) {
|
|
117
|
+
throw new OtlpParseError(`${fieldName} must be a non-negative integer string`);
|
|
118
|
+
}
|
|
119
|
+
return BigInt(value);
|
|
120
|
+
}
|
|
121
|
+
function decodeIntegerValue(value) {
|
|
122
|
+
if (value === undefined) {
|
|
123
|
+
return undefined;
|
|
124
|
+
}
|
|
125
|
+
if (typeof value === 'number') {
|
|
126
|
+
return Number.isSafeInteger(value) ? value : String(value);
|
|
127
|
+
}
|
|
128
|
+
if (!/^-?\d+$/.test(value)) {
|
|
129
|
+
return Number(value);
|
|
130
|
+
}
|
|
131
|
+
const parsed = Number(value);
|
|
132
|
+
return Number.isSafeInteger(parsed) ? parsed : value;
|
|
133
|
+
}
|
|
134
|
+
function nanosToMillis(value) {
|
|
135
|
+
return Number(value) / 1_000_000;
|
|
136
|
+
}
|
|
137
|
+
//# sourceMappingURL=otel.js.map
|
package/dist/otel.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"otel.js","sourceRoot":"","sources":["../src/otel.ts"],"names":[],"mappings":";;;AA2GA,wDAmDC;AAsBD,gDAWC;AAED,kCAuBC;AAED,4BAKC;AAED,0CAoBC;AAjJD,MAAa,cAAe,SAAQ,KAAK;IACvC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAA;IAC9B,CAAC;CACF;AALD,wCAKC;AAED,SAAgB,sBAAsB,CAAC,KAAoB;IACzD,MAAM,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C;YAC9C,MAAM,IAAI,cAAc,CAAC,GAAG,SAAS,sCAAsC,CAAC,CAAA;QAC9E,CAAC;QACD,OAAO,MAAM,CAAC,KAAK,CAAC,CAAA;IACtB,CAAC;IAED,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QACzB,MAAM,IAAI,cAAc,CAAC,GAAG,SAAS,wCAAwC,CAAC,CAAA;IAChF,CAAC;IAED,OAAO,MAAM,CAAC,KAAK,CAAC,CAAA;AACtB,CAAC;AAED,SAAS,kBAAkB,CAAC,KAAkC;IAC5D,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACxB,OAAO,SAAS,CAAA;IAClB,CAAC;IAED,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;IAC5D,CAAC;IAED,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QAC3B,OAAO,MAAM,CAAC,KAAK,CAAC,CAAA;IACtB,CAAC;IAED,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAA;IAC5B,OAAO,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAA;AACtD,CAAC;AAED,SAAS,aAAa,CAAC,KAAa;IAClC,OAAO,MAAM,CAAC,KAAK,CAAC,GAAG,SAAS,CAAA;AAClC,CAAC"}
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { TraceStore } from './store';
|
|
2
|
+
export interface NextScopeServerOptions {
|
|
3
|
+
route: string;
|
|
4
|
+
maxTraces: number;
|
|
5
|
+
}
|
|
6
|
+
export interface NextScopeServer {
|
|
7
|
+
route: string;
|
|
8
|
+
url: string;
|
|
9
|
+
store: TraceStore;
|
|
10
|
+
close(): Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
export declare function startNextScopeServer(options: NextScopeServerOptions): Promise<NextScopeServer>;
|
package/dist/server.js
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.startNextScopeServer = startNextScopeServer;
|
|
4
|
+
const node_http_1 = require("node:http");
|
|
5
|
+
const forwarder_1 = require("./forwarder");
|
|
6
|
+
const otel_1 = require("./otel");
|
|
7
|
+
const suppression_1 = require("./suppression");
|
|
8
|
+
const store_1 = require("./store");
|
|
9
|
+
const ui_1 = require("./ui");
|
|
10
|
+
const OTLP_BODY_LIMIT_BYTES = 5 * 1024 * 1024;
|
|
11
|
+
async function startNextScopeServer(options) {
|
|
12
|
+
const store = new store_1.TraceStore(options.maxTraces);
|
|
13
|
+
const forwarder = new forwarder_1.TraceForwarder();
|
|
14
|
+
const sidecarStatus = new SidecarStatus(options.route);
|
|
15
|
+
let sidecarUrl = '';
|
|
16
|
+
const server = (0, node_http_1.createServer)(async (request, response) => {
|
|
17
|
+
try {
|
|
18
|
+
await handleRequest(request, response, store, forwarder, sidecarStatus, options.route, sidecarUrl);
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
if (error instanceof HttpError) {
|
|
22
|
+
if (error.status === 400) {
|
|
23
|
+
sidecarStatus.recordParseError(error.message);
|
|
24
|
+
}
|
|
25
|
+
sendJson(response, error.status, { error: error.message });
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
sendJson(response, 500, { error: formatError(error) });
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
await new Promise((resolve, reject) => {
|
|
32
|
+
server.once('error', reject);
|
|
33
|
+
server.listen(0, '127.0.0.1', () => {
|
|
34
|
+
server.off('error', reject);
|
|
35
|
+
resolve();
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
const address = server.address();
|
|
39
|
+
const url = `http://127.0.0.1:${address.port}`;
|
|
40
|
+
sidecarUrl = url;
|
|
41
|
+
return {
|
|
42
|
+
route: options.route,
|
|
43
|
+
url,
|
|
44
|
+
store,
|
|
45
|
+
close: () => new Promise((resolve, reject) => {
|
|
46
|
+
server.close((error) => (error ? reject(error) : resolve()));
|
|
47
|
+
}),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
async function handleRequest(request, response, store, forwarder, sidecarStatus, route, sidecarUrl) {
|
|
51
|
+
const url = new URL(request.url ?? '/', 'http://127.0.0.1');
|
|
52
|
+
if (request.method === 'POST' && url.pathname === '/v1/traces') {
|
|
53
|
+
const body = await readBody(request, OTLP_BODY_LIMIT_BYTES);
|
|
54
|
+
const batch = parseOtlpJson(body);
|
|
55
|
+
const normalized = normalizeOtlpBatch(batch);
|
|
56
|
+
const filtered = (0, suppression_1.filterIgnoredTraces)(batch, normalized, route, sidecarUrl);
|
|
57
|
+
store.ingest(filtered.spans);
|
|
58
|
+
sidecarStatus.recordIngest(filtered.ignoredTraceIds.size);
|
|
59
|
+
if (filtered.batch.resourceSpans?.length) {
|
|
60
|
+
void forwarder.forward(JSON.stringify(filtered.batch));
|
|
61
|
+
}
|
|
62
|
+
sendJson(response, 200, {});
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (request.method === 'GET' && url.pathname === '/api/traces') {
|
|
66
|
+
sendJson(response, 200, store.listTraceSummaries({ lean: true }));
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
if (request.method === 'GET' && url.pathname === '/api/status') {
|
|
70
|
+
sendJson(response, 200, sidecarStatus.snapshot(store, forwarder));
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (request.method === 'GET' && url.pathname.startsWith('/api/traces/')) {
|
|
74
|
+
const traceId = decodeURIComponent(url.pathname.slice('/api/traces/'.length));
|
|
75
|
+
const trace = store.getTrace(traceId);
|
|
76
|
+
if (!trace) {
|
|
77
|
+
sendJson(response, 404, { error: 'Trace not found' });
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
sendJson(response, 200, trace);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
if (request.method === 'GET' && (url.pathname === '/' || url.pathname === '/index.html')) {
|
|
84
|
+
sendText(response, 200, 'text/html; charset=utf-8', (0, ui_1.renderInspectorHtml)(route));
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
if (request.method === 'GET' && url.pathname === '/style.css') {
|
|
88
|
+
sendText(response, 200, 'text/css; charset=utf-8', ui_1.inspectorCss);
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
if (request.method === 'GET' && url.pathname === '/app.js') {
|
|
92
|
+
sendText(response, 200, 'application/javascript; charset=utf-8', ui_1.inspectorJs);
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
sendText(response, 404, 'text/plain; charset=utf-8', 'Not found');
|
|
96
|
+
}
|
|
97
|
+
function sendJson(response, status, value) {
|
|
98
|
+
sendText(response, status, 'application/json; charset=utf-8', JSON.stringify(value));
|
|
99
|
+
}
|
|
100
|
+
function sendText(response, status, contentType, body) {
|
|
101
|
+
response.writeHead(status, {
|
|
102
|
+
'content-type': contentType,
|
|
103
|
+
'cache-control': 'no-store',
|
|
104
|
+
});
|
|
105
|
+
response.end(body);
|
|
106
|
+
}
|
|
107
|
+
async function readBody(request, limitBytes) {
|
|
108
|
+
const chunks = [];
|
|
109
|
+
let totalBytes = 0;
|
|
110
|
+
for await (const chunk of request) {
|
|
111
|
+
const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
112
|
+
totalBytes += buffer.byteLength;
|
|
113
|
+
if (totalBytes > limitBytes) {
|
|
114
|
+
throw new HttpError(413, `OTLP request body exceeds ${limitBytes} bytes`);
|
|
115
|
+
}
|
|
116
|
+
chunks.push(buffer);
|
|
117
|
+
}
|
|
118
|
+
return Buffer.concat(chunks).toString('utf8');
|
|
119
|
+
}
|
|
120
|
+
function parseOtlpJson(body) {
|
|
121
|
+
try {
|
|
122
|
+
return JSON.parse(body);
|
|
123
|
+
}
|
|
124
|
+
catch {
|
|
125
|
+
throw new HttpError(400, 'Malformed OTLP JSON');
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
function normalizeOtlpBatch(batch) {
|
|
129
|
+
try {
|
|
130
|
+
return (0, otel_1.normalizeOtlpJsonBatch)(batch);
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
if (error instanceof otel_1.OtlpParseError) {
|
|
134
|
+
throw new HttpError(400, error.message);
|
|
135
|
+
}
|
|
136
|
+
throw error;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
function formatError(error) {
|
|
140
|
+
return error instanceof Error ? error.message : String(error);
|
|
141
|
+
}
|
|
142
|
+
class HttpError extends Error {
|
|
143
|
+
status;
|
|
144
|
+
constructor(status, message) {
|
|
145
|
+
super(message);
|
|
146
|
+
this.status = status;
|
|
147
|
+
this.name = 'HttpError';
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
class SidecarStatus {
|
|
151
|
+
route;
|
|
152
|
+
suppressedCount = 0;
|
|
153
|
+
lastParseError;
|
|
154
|
+
constructor(route) {
|
|
155
|
+
this.route = route;
|
|
156
|
+
}
|
|
157
|
+
recordIngest(suppressedCount) {
|
|
158
|
+
this.suppressedCount += suppressedCount;
|
|
159
|
+
this.lastParseError = undefined;
|
|
160
|
+
}
|
|
161
|
+
recordParseError(message) {
|
|
162
|
+
this.lastParseError = message;
|
|
163
|
+
}
|
|
164
|
+
snapshot(store, forwarder) {
|
|
165
|
+
const storeStats = store.getStats();
|
|
166
|
+
const forwarding = forwarder.getStatus();
|
|
167
|
+
return {
|
|
168
|
+
route: this.route,
|
|
169
|
+
traceCount: storeStats.traceCount,
|
|
170
|
+
lastIngestAt: storeStats.lastIngestAt,
|
|
171
|
+
suppressedCount: this.suppressedCount,
|
|
172
|
+
forwarding,
|
|
173
|
+
lastParseError: this.lastParseError,
|
|
174
|
+
lastForwardError: forwarding.lastError,
|
|
175
|
+
lastError: this.lastParseError ?? forwarding.lastError,
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":";;AAsBA,oDAmDC;AAzED,yCAAmF;AAEnF,2CAA4C;AAC5C,iCAAmF;AACnF,+CAAmD;AACnD,mCAAoC;AACpC,6BAAqE;AAErE,MAAM,qBAAqB,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAA;AActC,KAAK,UAAU,oBAAoB,CACxC,OAA+B;IAE/B,MAAM,KAAK,GAAG,IAAI,kBAAU,CAAC,OAAO,CAAC,SAAS,CAAC,CAAA;IAC/C,MAAM,SAAS,GAAG,IAAI,0BAAc,EAAE,CAAA;IACtC,MAAM,aAAa,GAAG,IAAI,aAAa,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;IACtD,IAAI,UAAU,GAAG,EAAE,CAAA;IACnB,MAAM,MAAM,GAAG,IAAA,wBAAY,EAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE;QACtD,IAAI,CAAC;YACH,MAAM,aAAa,CACjB,OAAO,EACP,QAAQ,EACR,KAAK,EACL,SAAS,EACT,aAAa,EACb,OAAO,CAAC,KAAK,EACb,UAAU,CACX,CAAA;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,KAAK,YAAY,SAAS,EAAE,CAAC;gBAC/B,IAAI,KAAK,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;oBACzB,aAAa,CAAC,gBAAgB,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;gBAC/C,CAAC;gBACD,QAAQ,CAAC,QAAQ,EAAE,KAAK,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,KAAK,CAA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S,CAAC,SAAS,EAAE,CAAA;QACxC,OAAO;YACL,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,UAAU,EAAE,UAAU,CAAC,UAAU;YACjC,YAAY,EAAE,UAAU,CAAC,YAAY;YACrC,eAAe,EAAE,IAAI,CAAC,eAAe;YACrC,UAAU;YACV,cAAc,EAAE,IAAI,CAAC,cAAc;YACnC,gBAAgB,EAAE,UAAU,CAAC,SAAS;YACtC,SAAS,EAAE,IAAI,CAAC,cAAc,IAAI,UAAU,CAAC,SAAS;SACvD,CAAA;IACH,CAAC;CACF"}
|
package/dist/store.d.ts
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import type { NormalizedSpan } from './otel';
|
|
2
|
+
export interface TraceSummary {
|
|
3
|
+
traceId: string;
|
|
4
|
+
requestSegmentId: string;
|
|
5
|
+
revision: number;
|
|
6
|
+
updatedAt: string;
|
|
7
|
+
spanCount: number;
|
|
8
|
+
traceSpanCount: number;
|
|
9
|
+
segmentCount: number;
|
|
10
|
+
rootSpan: RequestSpanSummary;
|
|
11
|
+
startTimeUnixNano: string;
|
|
12
|
+
timestamp: string;
|
|
13
|
+
durationMs: number;
|
|
14
|
+
statusBucket: StatusBucket;
|
|
15
|
+
requestKind: string;
|
|
16
|
+
hasRsc: boolean;
|
|
17
|
+
hasPrefetch: boolean;
|
|
18
|
+
routeLabel: string;
|
|
19
|
+
errorSpanCount: number;
|
|
20
|
+
serviceNames: string[];
|
|
21
|
+
durationRangeMs: {
|
|
22
|
+
start: number;
|
|
23
|
+
end: number;
|
|
24
|
+
};
|
|
25
|
+
requestSegments: RequestSegmentSummary[];
|
|
26
|
+
topSlowSpans: DiagnosticSpanSummary[];
|
|
27
|
+
firstError?: ErrorSummary;
|
|
28
|
+
exceptionSummary?: ExceptionSummary;
|
|
29
|
+
criticalPath: CriticalPathSummary;
|
|
30
|
+
}
|
|
31
|
+
export interface TraceDetail extends TraceSummary {
|
|
32
|
+
spans: TraceSpanNode[];
|
|
33
|
+
}
|
|
34
|
+
export interface RequestSegmentSummary {
|
|
35
|
+
requestSegmentId: string;
|
|
36
|
+
rootSpan: RequestSpanSummary;
|
|
37
|
+
routeLabel: string;
|
|
38
|
+
statusBucket: StatusBucket;
|
|
39
|
+
requestKind: string;
|
|
40
|
+
startOffsetMs: number;
|
|
41
|
+
endOffsetMs: number;
|
|
42
|
+
durationMs: number;
|
|
43
|
+
spanCount: number;
|
|
44
|
+
errorSpanCount: number;
|
|
45
|
+
topSlowSpans: DiagnosticSpanSummary[];
|
|
46
|
+
firstError?: ErrorSummary;
|
|
47
|
+
exceptionSummary?: ExceptionSummary;
|
|
48
|
+
criticalPath: CriticalPathSummary;
|
|
49
|
+
}
|
|
50
|
+
export interface DiagnosticSpanSummary {
|
|
51
|
+
spanId: string;
|
|
52
|
+
name: string;
|
|
53
|
+
durationMs: number;
|
|
54
|
+
offsetMs: number;
|
|
55
|
+
serviceName?: string;
|
|
56
|
+
hasError: boolean;
|
|
57
|
+
}
|
|
58
|
+
export interface ErrorSummary {
|
|
59
|
+
spanId: string;
|
|
60
|
+
name: string;
|
|
61
|
+
offsetMs: number;
|
|
62
|
+
statusCode?: number;
|
|
63
|
+
statusMessage?: string;
|
|
64
|
+
exceptionType?: string;
|
|
65
|
+
exceptionMessage?: string;
|
|
66
|
+
}
|
|
67
|
+
export interface ExceptionSummary {
|
|
68
|
+
count: number;
|
|
69
|
+
firstMessage?: string;
|
|
70
|
+
firstType?: string;
|
|
71
|
+
}
|
|
72
|
+
export interface CriticalPathSummary {
|
|
73
|
+
durationMs: number;
|
|
74
|
+
spanIds: string[];
|
|
75
|
+
names: string[];
|
|
76
|
+
}
|
|
77
|
+
export interface RequestSpanSummary {
|
|
78
|
+
spanId: string;
|
|
79
|
+
name: string;
|
|
80
|
+
route?: string;
|
|
81
|
+
target?: string;
|
|
82
|
+
method?: string;
|
|
83
|
+
statusCode?: number;
|
|
84
|
+
spanType?: string;
|
|
85
|
+
startTimeUnixNano: string;
|
|
86
|
+
durationMs: number;
|
|
87
|
+
attributes?: Record<string, unknown>;
|
|
88
|
+
}
|
|
89
|
+
export interface TraceSpanNode {
|
|
90
|
+
spanId: string;
|
|
91
|
+
parentSpanId?: string;
|
|
92
|
+
name: string;
|
|
93
|
+
kind?: string | number;
|
|
94
|
+
startTimeUnixNano: string;
|
|
95
|
+
endTimeUnixNano: string;
|
|
96
|
+
durationMs: number;
|
|
97
|
+
offsetMs: number;
|
|
98
|
+
endOffsetMs: number;
|
|
99
|
+
serviceName?: string;
|
|
100
|
+
statusCode?: number;
|
|
101
|
+
hasError: boolean;
|
|
102
|
+
attributes: Record<string, unknown>;
|
|
103
|
+
resourceAttributes: Record<string, unknown>;
|
|
104
|
+
spanType?: string;
|
|
105
|
+
status?: NormalizedSpan['status'];
|
|
106
|
+
events: TraceSpanEvent[];
|
|
107
|
+
links: TraceSpanLink[];
|
|
108
|
+
childCount: number;
|
|
109
|
+
errorChildCount: number;
|
|
110
|
+
children: TraceSpanNode[];
|
|
111
|
+
}
|
|
112
|
+
export interface TraceSpanEvent {
|
|
113
|
+
timeUnixNano: string;
|
|
114
|
+
offsetMs: number;
|
|
115
|
+
name: string;
|
|
116
|
+
attributes: Record<string, unknown>;
|
|
117
|
+
}
|
|
118
|
+
export interface TraceSpanLink {
|
|
119
|
+
traceId?: string;
|
|
120
|
+
spanId?: string;
|
|
121
|
+
traceState?: string;
|
|
122
|
+
attributes: Record<string, unknown>;
|
|
123
|
+
}
|
|
124
|
+
export type StatusBucket = 'ok' | 'redirect' | 'client-error' | 'server-error' | 'unknown';
|
|
125
|
+
interface TraceRecord {
|
|
126
|
+
traceId: string;
|
|
127
|
+
spans: Map<string, NormalizedSpan>;
|
|
128
|
+
revision: number;
|
|
129
|
+
updatedAt: number;
|
|
130
|
+
summaryCache?: {
|
|
131
|
+
revision: number;
|
|
132
|
+
summaries: TraceSummary[];
|
|
133
|
+
leanSummaries: TraceSummary[];
|
|
134
|
+
};
|
|
135
|
+
detailCache?: {
|
|
136
|
+
revision: number;
|
|
137
|
+
detail: TraceDetail;
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
export declare class TraceStore {
|
|
141
|
+
private readonly maxTraces;
|
|
142
|
+
private readonly traces;
|
|
143
|
+
private revision;
|
|
144
|
+
private lastIngestAt;
|
|
145
|
+
constructor(maxTraces?: number);
|
|
146
|
+
ingest(spans: NormalizedSpan[]): void;
|
|
147
|
+
listTraces(): TraceSummary[];
|
|
148
|
+
listTraceSummaries(options?: {
|
|
149
|
+
lean?: boolean;
|
|
150
|
+
}): TraceSummary[];
|
|
151
|
+
getTrace(traceId: string): TraceDetail | undefined;
|
|
152
|
+
clear(): void;
|
|
153
|
+
getStats(): {
|
|
154
|
+
traceCount: number;
|
|
155
|
+
lastIngestAt: string | undefined;
|
|
156
|
+
};
|
|
157
|
+
private enforceRetention;
|
|
158
|
+
}
|
|
159
|
+
export declare function summarizeTrace(trace: TraceRecord): TraceSummary[];
|
|
160
|
+
export declare function pickRequestRoot(spans: NormalizedSpan[]): NormalizedSpan;
|
|
161
|
+
export declare function isNoiseOnlyTrace(spans: NormalizedSpan[]): boolean;
|
|
162
|
+
export declare function statusBucket(statusCode?: number): StatusBucket;
|
|
163
|
+
export declare function routeLabel(summary: RequestSpanSummary): string;
|
|
164
|
+
export {};
|