@runtimescope/server-sdk 0.6.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/index.d.ts +186 -0
- package/dist/index.js +1586 -0
- package/dist/index.js.map +1 -0
- package/package.json +48 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
type DatabaseOperation = 'SELECT' | 'INSERT' | 'UPDATE' | 'DELETE' | 'OTHER';
|
|
2
|
+
type DatabaseSource = 'prisma' | 'drizzle' | 'knex' | 'pg' | 'mysql2' | 'better-sqlite3' | 'generic';
|
|
3
|
+
interface DatabaseEvent {
|
|
4
|
+
eventId: string;
|
|
5
|
+
sessionId: string;
|
|
6
|
+
timestamp: number;
|
|
7
|
+
eventType: 'database';
|
|
8
|
+
query: string;
|
|
9
|
+
normalizedQuery: string;
|
|
10
|
+
duration: number;
|
|
11
|
+
rowsReturned?: number;
|
|
12
|
+
rowsAffected?: number;
|
|
13
|
+
tablesAccessed: string[];
|
|
14
|
+
operation: DatabaseOperation;
|
|
15
|
+
source: DatabaseSource;
|
|
16
|
+
stackTrace?: string;
|
|
17
|
+
label?: string;
|
|
18
|
+
error?: string;
|
|
19
|
+
params?: string;
|
|
20
|
+
}
|
|
21
|
+
type ConsoleLevel = 'log' | 'warn' | 'error' | 'info' | 'debug' | 'trace';
|
|
22
|
+
interface ConsoleEvent {
|
|
23
|
+
eventId: string;
|
|
24
|
+
sessionId: string;
|
|
25
|
+
timestamp: number;
|
|
26
|
+
eventType: 'console';
|
|
27
|
+
level: ConsoleLevel;
|
|
28
|
+
message: string;
|
|
29
|
+
args: unknown[];
|
|
30
|
+
stackTrace?: string;
|
|
31
|
+
sourceFile?: string;
|
|
32
|
+
}
|
|
33
|
+
interface GraphQLOperation {
|
|
34
|
+
type: 'query' | 'mutation' | 'subscription';
|
|
35
|
+
name: string;
|
|
36
|
+
}
|
|
37
|
+
interface NetworkEvent {
|
|
38
|
+
eventId: string;
|
|
39
|
+
sessionId: string;
|
|
40
|
+
timestamp: number;
|
|
41
|
+
eventType: 'network';
|
|
42
|
+
url: string;
|
|
43
|
+
method: string;
|
|
44
|
+
status: number;
|
|
45
|
+
requestHeaders: Record<string, string>;
|
|
46
|
+
responseHeaders: Record<string, string>;
|
|
47
|
+
requestBodySize: number;
|
|
48
|
+
responseBodySize: number;
|
|
49
|
+
duration: number;
|
|
50
|
+
ttfb: number;
|
|
51
|
+
graphqlOperation?: GraphQLOperation;
|
|
52
|
+
requestBody?: string;
|
|
53
|
+
responseBody?: string;
|
|
54
|
+
errorPhase?: 'error' | 'abort' | 'timeout';
|
|
55
|
+
errorMessage?: string;
|
|
56
|
+
source?: 'fetch' | 'xhr' | 'node-http' | 'node-https';
|
|
57
|
+
}
|
|
58
|
+
type ServerMetricName = 'memory.rss' | 'memory.heapUsed' | 'memory.heapTotal' | 'memory.external' | 'eventloop.lag.mean' | 'eventloop.lag.p99' | 'eventloop.lag.max' | 'gc.pause.major' | 'gc.pause.minor' | 'cpu.user' | 'cpu.system' | 'handles.active' | 'requests.active';
|
|
59
|
+
type MetricUnit = 'bytes' | 'ms' | 'percent' | 'count';
|
|
60
|
+
interface PerformanceEvent {
|
|
61
|
+
eventId: string;
|
|
62
|
+
sessionId: string;
|
|
63
|
+
timestamp: number;
|
|
64
|
+
eventType: 'performance';
|
|
65
|
+
metricName: ServerMetricName;
|
|
66
|
+
value: number;
|
|
67
|
+
unit: MetricUnit;
|
|
68
|
+
}
|
|
69
|
+
type ServerRuntimeEvent = DatabaseEvent | ConsoleEvent | NetworkEvent | PerformanceEvent;
|
|
70
|
+
interface ServerSdkConfig {
|
|
71
|
+
serverUrl?: string;
|
|
72
|
+
appName?: string;
|
|
73
|
+
sessionId?: string;
|
|
74
|
+
/** API key for authenticated connections to the collector */
|
|
75
|
+
authToken?: string;
|
|
76
|
+
captureStackTraces?: boolean;
|
|
77
|
+
redactParams?: boolean;
|
|
78
|
+
maxQueryLength?: number;
|
|
79
|
+
captureConsole?: boolean;
|
|
80
|
+
captureErrors?: boolean;
|
|
81
|
+
captureHttp?: boolean;
|
|
82
|
+
captureBody?: boolean;
|
|
83
|
+
maxBodySize?: number;
|
|
84
|
+
redactHeaders?: string[];
|
|
85
|
+
beforeSend?: (event: ServerRuntimeEvent) => ServerRuntimeEvent | null;
|
|
86
|
+
capturePerformance?: boolean;
|
|
87
|
+
performanceInterval?: number;
|
|
88
|
+
performanceMetrics?: ServerMetricName[];
|
|
89
|
+
sampleRate?: number;
|
|
90
|
+
maxEventsPerSecond?: number;
|
|
91
|
+
maxQueueSize?: number;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
type EmitFn = (event: NetworkEvent) => void;
|
|
95
|
+
interface MiddlewareOptions {
|
|
96
|
+
captureBody?: boolean;
|
|
97
|
+
maxBodySize?: number;
|
|
98
|
+
redactHeaders?: string[];
|
|
99
|
+
ignoreRoutes?: (string | RegExp)[];
|
|
100
|
+
beforeSend?: (event: ServerRuntimeEvent) => ServerRuntimeEvent | null;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Express/Connect-compatible middleware that captures incoming HTTP requests.
|
|
104
|
+
* Complements the HTTP interceptor (which captures outgoing requests).
|
|
105
|
+
*
|
|
106
|
+
* Usage:
|
|
107
|
+
* app.use(RuntimeScope.middleware());
|
|
108
|
+
*/
|
|
109
|
+
declare function runtimeScopeMiddleware(emit: EmitFn, sessionId: string, options?: MiddlewareOptions): (req: any, res: any, next: any) => void;
|
|
110
|
+
|
|
111
|
+
declare const _log: {
|
|
112
|
+
log: (...data: any[]) => void;
|
|
113
|
+
warn: (...data: any[]) => void;
|
|
114
|
+
error: (...data: any[]) => void;
|
|
115
|
+
debug: (...data: any[]) => void;
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
declare function generateId(): string;
|
|
119
|
+
declare function generateSessionId(): string;
|
|
120
|
+
|
|
121
|
+
declare function parseOperation(query: string): DatabaseOperation;
|
|
122
|
+
declare function parseTablesAccessed(query: string): string[];
|
|
123
|
+
declare function normalizeQuery(query: string): string;
|
|
124
|
+
declare function redactParams(params: unknown[]): string;
|
|
125
|
+
|
|
126
|
+
interface RequestContext {
|
|
127
|
+
sessionId: string;
|
|
128
|
+
requestId?: string;
|
|
129
|
+
metadata?: Record<string, unknown>;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Run a function within a request context.
|
|
133
|
+
* All async operations within `fn` will inherit this context.
|
|
134
|
+
*/
|
|
135
|
+
declare function runWithContext<T>(ctx: RequestContext, fn: () => T): T;
|
|
136
|
+
/**
|
|
137
|
+
* Get the current request context, if any.
|
|
138
|
+
*/
|
|
139
|
+
declare function getRequestContext(): RequestContext | undefined;
|
|
140
|
+
/**
|
|
141
|
+
* Get the sessionId from the current request context,
|
|
142
|
+
* falling back to the global sessionId.
|
|
143
|
+
*/
|
|
144
|
+
declare function getSessionId(fallback: string): string;
|
|
145
|
+
|
|
146
|
+
interface SamplerConfig {
|
|
147
|
+
/** Probabilistic sample rate: 0.0–1.0 (default: 1.0 = keep all) */
|
|
148
|
+
sampleRate?: number;
|
|
149
|
+
/** Max events per second before dropping (default: unlimited) */
|
|
150
|
+
maxEventsPerSecond?: number;
|
|
151
|
+
}
|
|
152
|
+
declare class Sampler {
|
|
153
|
+
private config;
|
|
154
|
+
private windowCount;
|
|
155
|
+
private windowStart;
|
|
156
|
+
private _droppedCount;
|
|
157
|
+
constructor(config: SamplerConfig);
|
|
158
|
+
get droppedCount(): number;
|
|
159
|
+
shouldSample(_event: ServerRuntimeEvent): boolean;
|
|
160
|
+
reset(): void;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
declare class RuntimeScopeServer {
|
|
164
|
+
private transport;
|
|
165
|
+
private sessionId;
|
|
166
|
+
private config;
|
|
167
|
+
private sampler;
|
|
168
|
+
private restoreFunctions;
|
|
169
|
+
connect(config?: ServerSdkConfig): void;
|
|
170
|
+
disconnect(): void;
|
|
171
|
+
get currentSessionId(): string;
|
|
172
|
+
private emitEvent;
|
|
173
|
+
middleware(options?: MiddlewareOptions): (req: any, res: any, next: any) => void;
|
|
174
|
+
instrumentPrisma(client: unknown): typeof client;
|
|
175
|
+
instrumentPg(pool: unknown): typeof pool;
|
|
176
|
+
instrumentKnex(knex: unknown): typeof knex;
|
|
177
|
+
instrumentDrizzle(db: unknown): typeof db;
|
|
178
|
+
instrumentMysql2(pool: unknown): typeof pool;
|
|
179
|
+
instrumentBetterSqlite3(db: unknown): typeof db;
|
|
180
|
+
captureQuery<T>(fn: () => Promise<T>, options?: {
|
|
181
|
+
label?: string;
|
|
182
|
+
}): Promise<T>;
|
|
183
|
+
}
|
|
184
|
+
declare const RuntimeScope: RuntimeScopeServer;
|
|
185
|
+
|
|
186
|
+
export { type ConsoleEvent, type DatabaseEvent, type MetricUnit, type NetworkEvent, type PerformanceEvent, RuntimeScope, Sampler, type ServerMetricName, type ServerRuntimeEvent, type ServerSdkConfig, _log, generateId, generateSessionId, getRequestContext, getSessionId, normalizeQuery, parseOperation, parseTablesAccessed, redactParams, runWithContext, runtimeScopeMiddleware };
|