forked from elastic/apm-agent-nodejs
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.d.ts
388 lines (342 loc) · 11 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
/// <reference types="node" />
import { IncomingMessage, ServerResponse } from 'http';
export = agent;
declare const agent: Agent;
declare class Agent implements Taggable, StartSpanFn {
// Configuration
start (options?: AgentConfigOptions): Agent;
isStarted (): boolean;
setFramework (options: {
name?: string;
version?: string;
overwrite?: boolean;
}): void;
addPatch (modules: string | Array<string>, handler: string | PatchHandler): void;
removePatch (modules: string | Array<string>, handler: string | PatchHandler): void;
clearPatches (modules: string | Array<string>): void;
// Data collection hooks
middleware: { connect (): Connect.ErrorHandleFunction };
lambda (handler: AwsLambda.Handler): AwsLambda.Handler;
lambda (type: string, handler: AwsLambda.Handler): AwsLambda.Handler;
handleUncaughtExceptions (
fn?: (err: Error) => void
): void;
// Errors
captureError (
err: Error | string | ParameterizedMessageObject,
callback?: CaptureErrorCallback
): void;
captureError (
err: Error | string | ParameterizedMessageObject,
options?: CaptureErrorOptions,
callback?: CaptureErrorCallback
): void;
// Distributed Tracing
currentTraceparent: string | null;
// Transactions
startTransaction(
name?: string | null,
options?: TransactionOptions
): Transaction | null;
startTransaction(
name: string | null,
type: string | null,
options?: TransactionOptions
): Transaction | null;
startTransaction(
name: string | null,
type: string | null,
subtype: string | null,
options?: TransactionOptions
): Transaction | null;
startTransaction(
name: string | null,
type: string | null,
subtype: string | null,
action: string | null,
options?: TransactionOptions
): Transaction | null;
setTransactionName (name: string): void;
endTransaction (result?: string | number, endTime?: number): void;
currentTransaction: Transaction | null;
// Spans
startSpan(
name?: string | null,
options?: SpanOptions
): Span | null;
startSpan(
name: string | null,
type: string | null,
options?: SpanOptions
): Span | null;
startSpan(
name: string | null,
type: string | null,
subtype: string | null,
options?: SpanOptions
): Span | null;
startSpan(
name: string | null,
type: string | null,
subtype: string | null,
action: string | null,
options?: SpanOptions
): Span | null;
currentSpan: Span | null;
// Context
setLabel (name: string, value: LabelValue): boolean;
addLabels (labels: Labels): boolean;
setUserContext (user: UserObject): void;
setCustomContext (custom: object): void;
// Transport
addFilter (fn: FilterFn): void;
addErrorFilter (fn: FilterFn): void;
addSpanFilter (fn: FilterFn): void;
addTransactionFilter (fn: FilterFn): void;
flush (callback?: Function): void;
destroy (): void;
// Utils
logger: Logger;
}
declare class GenericSpan implements Taggable {
// The following properties and methods are currently not documented as their API isn't considered official:
// timestamp, ended, id, traceId, parentId, sampled, duration()
type: string | null;
subtype: string | null;
action: string | null;
traceparent: string;
setType (type?: string | null, subtype?: string | null, action?: string | null): void;
setLabel (name: string, value: LabelValue): boolean;
addLabels (labels: Labels): boolean;
}
declare class Transaction extends GenericSpan implements StartSpanFn {
// The following properties and methods are currently not documented as their API isn't considered official:
// setUserContext(), setCustomContext(), toJSON(), setDefaultName(), setDefaultNameFromRequest()
name: string;
result: string | number;
startSpan(
name?: string | null,
options?: SpanOptions
): Span | null;
startSpan(
name: string | null,
type: string | null,
options?: SpanOptions
): Span | null;
startSpan(
name: string | null,
type: string | null,
subtype: string | null,
options?: SpanOptions
): Span | null;
startSpan(
name: string | null,
type: string | null,
subtype: string | null,
action: string | null,
options?: SpanOptions
): Span | null;
ensureParentId (): string;
end (result?: string | number | null, endTime?: number): void;
}
declare class Span extends GenericSpan {
// The following properties and methods are currently not documented as their API isn't considered official:
// customStackTrace(), setDbContext()
transaction: Transaction;
name: string;
end (endTime?: number): void;
}
interface AgentConfigOptions {
abortedErrorThreshold?: string; // Also support `number`, but as we're removing this functionality soon, there's no need to advertise it
active?: boolean;
addPatch?: KeyValueConfig;
apiRequestSize?: string; // Also support `number`, but as we're removing this functionality soon, there's no need to advertise it
apiRequestTime?: string; // Also support `number`, but as we're removing this functionality soon, there's no need to advertise it
asyncHooks?: boolean;
captureBody?: CaptureBody;
captureErrorLogStackTraces?: CaptureErrorLogStackTraces;
captureExceptions?: boolean;
captureHeaders?: boolean;
captureSpanStackTraces?: boolean;
containerId?: string;
disableInstrumentations?: string | string[];
environment?: string;
errorMessageMaxLength?: string; // Also support `number`, but as we're removing this functionality soon, there's no need to advertise it
errorOnAbortedRequests?: boolean;
filterHttpHeaders?: boolean;
frameworkName?: string;
frameworkVersion?: string;
globalLabels?: KeyValueConfig;
hostname?: string;
ignoreUrls?: Array<string | RegExp>;
ignoreUserAgents?: Array<string | RegExp>;
instrument?: boolean;
instrumentIncomingHTTPRequests?: boolean;
kubernetesNamespace?: string;
kubernetesNodeName?: string;
kubernetesPodName?: string;
kubernetesPodUID?: string;
logLevel?: LogLevel;
logger?: Logger;
metricsInterval?: string; // Also support `number`, but as we're removing this functionality soon, there's no need to advertise it
payloadLogFile?: string;
centralConfig?: boolean;
secretToken?: string;
serverTimeout?: string; // Also support `number`, but as we're removing this functionality soon, there's no need to advertise it
serverUrl?: string;
serviceName?: string;
serviceVersion?: string;
sourceLinesErrorAppFrames?: number;
sourceLinesErrorLibraryFrames?: number;
sourceLinesSpanAppFrames?: number;
sourceLinesSpanLibraryFrames?: number;
stackTraceLimit?: number;
transactionMaxSpans?: number;
transactionSampleRate?: number;
usePathAsTransactionName?: boolean;
verifyServerCert?: boolean;
}
interface CaptureErrorOptions {
request?: IncomingMessage;
response?: ServerResponse;
timestamp?: number;
handled?: boolean;
user?: UserObject;
labels?: Labels;
tags?: Labels;
custom?: object;
message?: string;
}
interface Labels {
[key: string]: LabelValue;
}
interface UserObject {
id?: string | number;
username?: string;
email?: string;
}
interface ParameterizedMessageObject {
message: string;
params: Array<any>;
}
interface Logger {
fatal (msg: string, ...args: any[]): void;
fatal (obj: {}, msg?: string, ...args: any[]): void;
error (msg: string, ...args: any[]): void;
error (obj: {}, msg?: string, ...args: any[]): void;
warn (msg: string, ...args: any[]): void;
warn (obj: {}, msg?: string, ...args: any[]): void;
info (msg: string, ...args: any[]): void;
info (obj: {}, msg?: string, ...args: any[]): void;
debug (msg: string, ...args: any[]): void;
debug (obj: {}, msg?: string, ...args: any[]): void;
trace (msg: string, ...args: any[]): void;
trace (obj: {}, msg?: string, ...args: any[]): void;
[propName: string]: any;
}
interface TransactionOptions {
startTime?: number;
childOf?: Transaction | Span | string;
}
interface SpanOptions {
childOf?: Transaction | Span | string;
}
type CaptureBody = 'off' | 'errors' | 'transactions' | 'all';
type CaptureErrorLogStackTraces = 'never' | 'messages' | 'always';
type LogLevel = 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'fatal';
type CaptureErrorCallback = (err: Error | null, id: string) => void;
type FilterFn = (payload: Payload) => Payload | boolean | void;
type LabelValue = string | number | boolean | null | undefined;
type KeyValueConfig = string | Labels | Array<Array<LabelValue>>
type Payload = { [propName: string]: any }
type PatchHandler = (exports: any, agent: Agent, options: PatchOptions) => any;
interface PatchOptions {
version: string | undefined,
enabled: boolean
}
interface Taggable {
setLabel (name: string, value: LabelValue): boolean;
addLabels (labels: Labels): boolean;
}
interface StartSpanFn {
startSpan(
name?: string | null,
options?: SpanOptions
): Span | null;
startSpan(
name: string | null,
type: string | null,
options?: SpanOptions
): Span | null;
startSpan(
name: string | null,
type: string | null,
subtype: string | null,
options?: SpanOptions
): Span | null;
startSpan(
name: string | null,
type: string | null,
subtype: string | null,
action: string | null,
options?: SpanOptions
): Span | null;
}
// Inlined from @types/aws-lambda - start
declare namespace AwsLambda {
interface CognitoIdentity {
cognitoIdentityId: string;
cognitoIdentityPoolId: string;
}
interface ClientContext {
client: ClientContextClient;
custom?: any;
env: ClientContextEnv;
}
interface ClientContextClient {
installationId: string;
appTitle: string;
appVersionName: string;
appVersionCode: string;
appPackageName: string;
}
interface ClientContextEnv {
platformVersion: string;
platform: string;
make: string;
model: string;
locale: string;
}
type Callback<TResult = any> = (error?: Error | null | string, result?: TResult) => void;
interface Context {
// Properties
callbackWaitsForEmptyEventLoop: boolean;
functionName: string;
functionVersion: string;
invokedFunctionArn: string;
memoryLimitInMB: number;
awsRequestId: string;
logGroupName: string;
logStreamName: string;
identity?: CognitoIdentity;
clientContext?: ClientContext;
// Functions
getRemainingTimeInMillis(): number;
// Functions for compatibility with earlier Node.js Runtime v0.10.42
// For more details see http://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-using-old-runtime.html#nodejs-prog-model-oldruntime-context-methods
done(error?: Error, result?: any): void;
fail(error: Error | string): void;
succeed(messageOrObject: any): void;
succeed(message: string, object: any): void;
}
type Handler<TEvent = any, TResult = any> = (
event: TEvent,
context: Context,
callback: Callback<TResult>,
) => void | Promise<TResult>;
}
// Inlined from @types/connect - start
declare namespace Connect {
type NextFunction = (err?: any) => void;
type ErrorHandleFunction = (err: any, req: IncomingMessage, res: ServerResponse, next: NextFunction) => void;
}