midline-agent 0.1.9 → 0.3.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/README.md +313 -249
- package/dist/agent.d.ts +118 -6
- package/dist/agent.js +746 -99
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +63 -0
- package/dist/config.d.ts +64 -0
- package/dist/config.js +231 -0
- package/dist/console.d.ts +46 -0
- package/dist/console.js +167 -0
- package/dist/context.d.ts +13 -0
- package/dist/context.js +38 -0
- package/dist/errorHandler.d.ts +11 -2
- package/dist/errorHandler.js +32 -12
- package/dist/index.d.ts +9 -2
- package/dist/index.js +9 -1
- package/dist/middleware.d.ts +19 -2
- package/dist/middleware.js +92 -41
- package/dist/proxy.d.ts +70 -0
- package/dist/proxy.js +383 -0
- package/dist/redact.d.ts +35 -0
- package/dist/redact.js +223 -0
- package/dist/tap.d.ts +18 -0
- package/dist/tap.js +62 -0
- package/dist/transport.d.ts +35 -0
- package/dist/transport.js +133 -0
- package/dist/types.d.ts +114 -5
- package/package.json +13 -8
- package/src/agent.ts +825 -97
- package/src/cli.ts +69 -0
- package/src/config.ts +234 -0
- package/src/console.ts +182 -0
- package/src/context.ts +48 -0
- package/src/errorHandler.ts +36 -13
- package/src/index.ts +19 -2
- package/src/middleware.ts +118 -43
- package/src/proxy.ts +435 -0
- package/src/redact.ts +231 -0
- package/src/tap.ts +55 -0
- package/src/transport.ts +125 -0
- package/src/types.ts +151 -31
- package/test/agent.test.js +353 -0
- package/test/console.test.js +182 -0
- package/test/helpers.js +151 -0
- package/test/middleware.test.js +178 -0
- package/test/proxy.test.js +274 -0
- package/test/redact.test.js +105 -0
package/dist/agent.d.ts
CHANGED
|
@@ -1,10 +1,122 @@
|
|
|
1
|
+
import { ResolvedCapture } from "./config";
|
|
2
|
+
import type { RequestContext } from "./context";
|
|
1
3
|
import { MidlineConfig, MidlineEvent } from "./types";
|
|
4
|
+
export declare const SDK_VERSION: string;
|
|
5
|
+
/** Raw material for a request event, handed over by the middleware or the proxy. */
|
|
6
|
+
export interface HttpExchange {
|
|
7
|
+
integration: NonNullable<MidlineEvent["integration"]>;
|
|
8
|
+
context: RequestContext;
|
|
9
|
+
method?: string;
|
|
10
|
+
/** Path plus query string, as received. */
|
|
11
|
+
url: string;
|
|
12
|
+
statusCode?: number;
|
|
13
|
+
durationMs: number;
|
|
14
|
+
ip?: string;
|
|
15
|
+
userAgent?: string;
|
|
16
|
+
routeTemplate?: string;
|
|
17
|
+
request?: ExchangeMessage;
|
|
18
|
+
response?: ExchangeMessage;
|
|
19
|
+
destination?: {
|
|
20
|
+
url: string;
|
|
21
|
+
};
|
|
22
|
+
errorCode?: string;
|
|
23
|
+
errorMessage?: string;
|
|
24
|
+
aborted?: boolean;
|
|
25
|
+
capture?: ResolvedCapture;
|
|
26
|
+
}
|
|
27
|
+
export interface ExchangeMessage {
|
|
28
|
+
headers?: Record<string, unknown>;
|
|
29
|
+
contentType?: string;
|
|
30
|
+
/** Only present when body capture is on. Parsed object or raw bytes. */
|
|
31
|
+
body?: unknown;
|
|
32
|
+
bodyBytes?: number;
|
|
33
|
+
/** The tap stopped reading before the end of the body. */
|
|
34
|
+
truncated?: boolean;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Ships request, error and console events to the Midline server.
|
|
38
|
+
*
|
|
39
|
+
* The contract with the host application is that the agent is never allowed to
|
|
40
|
+
* affect it: an unreachable, untrusted, slow or misconfigured Midline server costs a
|
|
41
|
+
* single explanatory log line and bounded buffered memory — never a crash, never a
|
|
42
|
+
* stalled request, never a disabled certificate check.
|
|
43
|
+
*/
|
|
2
44
|
export declare class MidlineAgent {
|
|
3
|
-
private static
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
static
|
|
45
|
+
private static defaultAgent;
|
|
46
|
+
/** Creates the process-wide agent used by `midlineMiddleware()` and the static helpers. */
|
|
47
|
+
static init(config?: MidlineConfig): MidlineAgent;
|
|
48
|
+
static get current(): MidlineAgent | null;
|
|
7
49
|
static addEvent(event: MidlineEvent): void;
|
|
8
|
-
|
|
9
|
-
|
|
50
|
+
static flush(): Promise<void>;
|
|
51
|
+
static shutdown(timeoutMs?: number): Promise<void>;
|
|
52
|
+
private readonly config;
|
|
53
|
+
private readonly redactor;
|
|
54
|
+
private readonly transport;
|
|
55
|
+
private readonly onErrorHook?;
|
|
56
|
+
private readonly debugLogs;
|
|
57
|
+
private queue;
|
|
58
|
+
private queueBytes;
|
|
59
|
+
private timer;
|
|
60
|
+
private drainPromise;
|
|
61
|
+
private failures;
|
|
62
|
+
private retryAfter;
|
|
63
|
+
private stopped;
|
|
64
|
+
private lastNotice;
|
|
65
|
+
private dropped;
|
|
66
|
+
private maxRequestBytes;
|
|
67
|
+
private batchLimit;
|
|
68
|
+
private consoleCapture;
|
|
69
|
+
private consoleTokens;
|
|
70
|
+
private consoleRefilledAt;
|
|
71
|
+
/** The server refused a console event: it predates them, so no more are sent. */
|
|
72
|
+
private consoleUnsupported;
|
|
73
|
+
constructor(config?: MidlineConfig);
|
|
74
|
+
/** False when the agent is off: no key, bad config, disabled, rejected key, or closed. */
|
|
75
|
+
get active(): boolean;
|
|
76
|
+
get capture(): ResolvedCapture | null;
|
|
77
|
+
get queued(): number;
|
|
78
|
+
addEvent(event: MidlineEvent): void;
|
|
79
|
+
/** Records one HTTP exchange. Captured parts are redacted here, before queueing. */
|
|
80
|
+
recordHttp(exchange: HttpExchange): void;
|
|
81
|
+
private recordConsole;
|
|
82
|
+
private takeConsoleToken;
|
|
83
|
+
/** Sends whatever is buffered now, ignoring backoff, and keeps the process alive until done. */
|
|
84
|
+
flush(): Promise<void>;
|
|
85
|
+
/** Flushes with a deadline, then closes. For graceful shutdown. */
|
|
86
|
+
shutdown(timeoutMs?: number): Promise<void>;
|
|
87
|
+
/** Stops the timer, drops the buffer and releases sockets. Safe to call more than once. */
|
|
88
|
+
close(): void;
|
|
89
|
+
private captureMessage;
|
|
90
|
+
private redactManualMessage;
|
|
91
|
+
/**
|
|
92
|
+
* Maps an event onto the ingest schema. Everything beyond the long-standing
|
|
93
|
+
* top-level fields travels in `metadata` and `payload`, which every Midline
|
|
94
|
+
* server version accepts — so upgrading the agent never gets events rejected by a
|
|
95
|
+
* server that hasn't been upgraded yet.
|
|
96
|
+
*/
|
|
97
|
+
private toWire;
|
|
98
|
+
private enqueue;
|
|
99
|
+
/** Oldest events go first — during an outage the most recent minute is worth more than the first. */
|
|
100
|
+
private trimQueue;
|
|
101
|
+
private requeue;
|
|
102
|
+
private takeBatch;
|
|
103
|
+
private drain;
|
|
104
|
+
private runDrain;
|
|
105
|
+
/** Returns false if delivery should stop for this drain. */
|
|
106
|
+
private sendIndividually;
|
|
107
|
+
private send;
|
|
108
|
+
/**
|
|
109
|
+
* True when a rejected event is a console line the server has no event type for,
|
|
110
|
+
* i.e. the server predates console capture. Capture switches itself off rather
|
|
111
|
+
* than paying a refused request for every line printed from then on.
|
|
112
|
+
*/
|
|
113
|
+
private refusedConsole;
|
|
114
|
+
/** One line per distinct fault, not one per failed event. */
|
|
115
|
+
private report;
|
|
116
|
+
private describe;
|
|
117
|
+
private onSuccess;
|
|
118
|
+
private onFailure;
|
|
119
|
+
/** Unrecoverable configuration problem: go quiet instead of looping forever. */
|
|
120
|
+
private disable;
|
|
121
|
+
private log;
|
|
10
122
|
}
|