@logbrew/sdk 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/README.md +225 -0
- package/examples/index.mjs +123 -0
- package/examples/package.json +14 -0
- package/examples/readme-example.cjs +59 -0
- package/examples/readme-example.mjs +51 -0
- package/examples/real-user-smoke.cjs +59 -0
- package/examples/real-user-smoke.mjs +51 -0
- package/index.cjs +1099 -0
- package/index.d.cts +307 -0
- package/index.d.ts +307 -0
- package/index.js +20 -0
- package/package.json +49 -0
package/index.d.cts
ADDED
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
/** Metadata values that can be attached to public LogBrew event payloads. */
|
|
2
|
+
export type MetadataValue = string | number | boolean | null;
|
|
3
|
+
/** Structured metadata map shared by public LogBrew event attribute types. */
|
|
4
|
+
export type Metadata = Record<string, MetadataValue>;
|
|
5
|
+
|
|
6
|
+
/** Parsed W3C trace context from a traceparent value. */
|
|
7
|
+
export type TraceparentContext = {
|
|
8
|
+
version: string;
|
|
9
|
+
traceId: string;
|
|
10
|
+
parentSpanId: string;
|
|
11
|
+
traceFlags: string;
|
|
12
|
+
sampled: boolean;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/** Inputs for creating a W3C traceparent value from known trace/span ids. */
|
|
16
|
+
export type TraceparentInput = {
|
|
17
|
+
traceId: string;
|
|
18
|
+
spanId: string;
|
|
19
|
+
traceFlags?: string;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/** Span fields supplied when deriving LogBrew span attributes from traceparent. */
|
|
23
|
+
export type TraceparentSpanInput = {
|
|
24
|
+
name: string;
|
|
25
|
+
spanId: string;
|
|
26
|
+
status: "ok" | "error";
|
|
27
|
+
durationMs?: number;
|
|
28
|
+
metadata?: Metadata;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/** Public release event attributes. */
|
|
32
|
+
export type ReleaseAttributes = {
|
|
33
|
+
version: string;
|
|
34
|
+
commit?: string;
|
|
35
|
+
notes?: string;
|
|
36
|
+
metadata?: Metadata;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/** Public environment event attributes. */
|
|
40
|
+
export type EnvironmentAttributes = {
|
|
41
|
+
name: string;
|
|
42
|
+
region?: string;
|
|
43
|
+
metadata?: Metadata;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/** Public issue event attributes. */
|
|
47
|
+
export type IssueAttributes = {
|
|
48
|
+
title: string;
|
|
49
|
+
level: "info" | "warning" | "error" | "critical";
|
|
50
|
+
message?: string;
|
|
51
|
+
metadata?: Metadata;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
/** Public log event attributes. */
|
|
55
|
+
export type LogAttributes = {
|
|
56
|
+
message: string;
|
|
57
|
+
level: "debug" | "info" | "warning" | "error";
|
|
58
|
+
logger?: string;
|
|
59
|
+
metadata?: Metadata;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
/** Console method names supported by the opt-in console capture helper. */
|
|
63
|
+
export type ConsoleMethodName = "debug" | "info" | "log" | "warn" | "error";
|
|
64
|
+
|
|
65
|
+
/** Minimal console-like target accepted by the opt-in console capture helper. */
|
|
66
|
+
export type ConsoleLike = Partial<Record<ConsoleMethodName, (...args: unknown[]) => void>>;
|
|
67
|
+
|
|
68
|
+
/** Configuration for opt-in console capture. */
|
|
69
|
+
export type ConsoleCaptureConfig = {
|
|
70
|
+
client: LogBrewClient;
|
|
71
|
+
console?: ConsoleLike;
|
|
72
|
+
levels?: ConsoleMethodName[];
|
|
73
|
+
logger?: string;
|
|
74
|
+
metadata?: Metadata;
|
|
75
|
+
transport?: Transport;
|
|
76
|
+
flushOnCapture?: boolean;
|
|
77
|
+
includeErrorStack?: boolean;
|
|
78
|
+
timestamp?: () => string;
|
|
79
|
+
eventIdPrefix?: string;
|
|
80
|
+
onError?: (error: unknown) => void;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
/** Handle returned by opt-in console capture installation. */
|
|
84
|
+
export type ConsoleCaptureHandle = {
|
|
85
|
+
flush(): Promise<TransportResponse | null>;
|
|
86
|
+
uninstall(): void;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
/** Pino JSON log record shape accepted by the optional Pino destination helper. */
|
|
90
|
+
export type PinoLogRecord = Record<string, unknown> & {
|
|
91
|
+
level?: string | number;
|
|
92
|
+
time?: string | number;
|
|
93
|
+
timestamp?: string | number;
|
|
94
|
+
msg?: unknown;
|
|
95
|
+
message?: unknown;
|
|
96
|
+
err?: unknown;
|
|
97
|
+
error?: unknown;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
/** Configuration for the dependency-free Pino destination adapter. */
|
|
101
|
+
export type PinoDestinationConfig = {
|
|
102
|
+
client: LogBrewClient;
|
|
103
|
+
logger?: string;
|
|
104
|
+
metadata?: Metadata;
|
|
105
|
+
transport?: Transport;
|
|
106
|
+
flushOnWrite?: boolean;
|
|
107
|
+
includeErrorStack?: boolean;
|
|
108
|
+
timestamp?: () => string;
|
|
109
|
+
eventIdPrefix?: string;
|
|
110
|
+
onError?: (error: unknown) => void;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
/** Stream-like destination returned for use as Pino's output destination. */
|
|
114
|
+
export type PinoDestinationHandle = {
|
|
115
|
+
write(chunk: unknown): boolean;
|
|
116
|
+
flush(): Promise<TransportResponse | null>;
|
|
117
|
+
end(): Promise<TransportResponse | null>;
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
/** Winston info object shape accepted by the optional Winston transport helper. */
|
|
121
|
+
export type WinstonLogInfo = Record<string, unknown> & {
|
|
122
|
+
level?: string;
|
|
123
|
+
message?: unknown;
|
|
124
|
+
timestamp?: string | number | Date;
|
|
125
|
+
time?: string | number | Date;
|
|
126
|
+
err?: unknown;
|
|
127
|
+
error?: unknown;
|
|
128
|
+
stack?: unknown;
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
/** Configuration for the dependency-free Winston transport adapter. */
|
|
132
|
+
export type WinstonTransportConfig = {
|
|
133
|
+
client: LogBrewClient;
|
|
134
|
+
logger?: string;
|
|
135
|
+
metadata?: Metadata;
|
|
136
|
+
transport?: Transport;
|
|
137
|
+
flushOnWrite?: boolean;
|
|
138
|
+
includeErrorStack?: boolean;
|
|
139
|
+
timestamp?: () => string;
|
|
140
|
+
eventIdPrefix?: string;
|
|
141
|
+
level?: string;
|
|
142
|
+
name?: string;
|
|
143
|
+
silent?: boolean;
|
|
144
|
+
handleExceptions?: boolean;
|
|
145
|
+
handleRejections?: boolean;
|
|
146
|
+
onError?: (error: unknown) => void;
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
/** Object-mode transport returned for use in a Winston logger's transports array. */
|
|
150
|
+
export type WinstonTransportHandle = {
|
|
151
|
+
level?: string;
|
|
152
|
+
name?: string;
|
|
153
|
+
silent?: boolean;
|
|
154
|
+
handleExceptions?: boolean;
|
|
155
|
+
handleRejections?: boolean;
|
|
156
|
+
log(info: WinstonLogInfo, callback?: () => void): void;
|
|
157
|
+
write(info: WinstonLogInfo): boolean;
|
|
158
|
+
flush(): Promise<TransportResponse | null>;
|
|
159
|
+
end(callback?: () => void): unknown;
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
/** Public span event attributes. */
|
|
163
|
+
export type SpanAttributes = {
|
|
164
|
+
name: string;
|
|
165
|
+
traceId: string;
|
|
166
|
+
spanId: string;
|
|
167
|
+
parentSpanId?: string;
|
|
168
|
+
status: "ok" | "error";
|
|
169
|
+
durationMs?: number;
|
|
170
|
+
metadata?: Metadata;
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
/** Public action event attributes. */
|
|
174
|
+
export type ActionAttributes = {
|
|
175
|
+
name: string;
|
|
176
|
+
status: "queued" | "running" | "success" | "failure";
|
|
177
|
+
metadata?: Metadata;
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
/** Public event union used in preview and transport payloads. */
|
|
181
|
+
export type Event =
|
|
182
|
+
| { type: "release"; id: string; timestamp: string; attributes: ReleaseAttributes }
|
|
183
|
+
| { type: "environment"; id: string; timestamp: string; attributes: EnvironmentAttributes }
|
|
184
|
+
| { type: "issue"; id: string; timestamp: string; attributes: IssueAttributes }
|
|
185
|
+
| { type: "log"; id: string; timestamp: string; attributes: LogAttributes }
|
|
186
|
+
| { type: "span"; id: string; timestamp: string; attributes: SpanAttributes }
|
|
187
|
+
| { type: "action"; id: string; timestamp: string; attributes: ActionAttributes };
|
|
188
|
+
|
|
189
|
+
/** Stable transport response returned from flush and shutdown operations. */
|
|
190
|
+
export type TransportResponse = {
|
|
191
|
+
/** Final HTTP-like status returned by the transport. */
|
|
192
|
+
statusCode: number;
|
|
193
|
+
/** Number of transport attempts used for the flush. */
|
|
194
|
+
attempts: number;
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
/** Minimal transport interface accepted by flush and shutdown operations. */
|
|
198
|
+
export type Transport = {
|
|
199
|
+
send(apiKey: string, body: string): TransportResponse | Promise<TransportResponse>;
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
/** Stable public SDK error with parseable code and message fields. */
|
|
203
|
+
export declare class SdkError extends Error {
|
|
204
|
+
code: string;
|
|
205
|
+
constructor(code: string, message: string);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/** Transport error that can optionally be marked retryable by the caller. */
|
|
209
|
+
export declare class TransportError extends Error {
|
|
210
|
+
code: string;
|
|
211
|
+
retryable: boolean;
|
|
212
|
+
constructor(code: string, message: string, retryable?: boolean);
|
|
213
|
+
/** Create a retryable network failure that preserves queued events. */
|
|
214
|
+
static network(message: string): TransportError;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/** Scripted transport for previewing, accepting, or failing queued event flushes. */
|
|
218
|
+
export declare class RecordingTransport {
|
|
219
|
+
constructor(scriptedResponses?: Array<{ statusCode: number } | Error>);
|
|
220
|
+
/** Every request body sent through this transport instance. */
|
|
221
|
+
sentBodies: string[];
|
|
222
|
+
/** Create a transport that accepts queued flushes with a 202 response. */
|
|
223
|
+
static alwaysAccept(): RecordingTransport;
|
|
224
|
+
/** Return the most recent request body sent through this transport. */
|
|
225
|
+
lastBody(): string | null;
|
|
226
|
+
send(apiKey: string, body: string): Promise<TransportResponse>;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/** Buffered public client for validating, previewing, and flushing LogBrew events. */
|
|
230
|
+
export declare class LogBrewClient {
|
|
231
|
+
/** Create a client from public SDK identity, retry, and API key settings. */
|
|
232
|
+
static create(config: {
|
|
233
|
+
apiKey: string;
|
|
234
|
+
sdkName: string;
|
|
235
|
+
sdkVersion: string;
|
|
236
|
+
maxRetries?: number;
|
|
237
|
+
}): LogBrewClient;
|
|
238
|
+
/** Return the queued event count currently buffered in memory. */
|
|
239
|
+
pendingEvents(): number;
|
|
240
|
+
/** Return the queued event batch as stable, pretty-printed JSON. */
|
|
241
|
+
previewJson(): string;
|
|
242
|
+
release(id: string, timestamp: string, attributes: ReleaseAttributes): void;
|
|
243
|
+
environment(id: string, timestamp: string, attributes: EnvironmentAttributes): void;
|
|
244
|
+
issue(id: string, timestamp: string, attributes: IssueAttributes): void;
|
|
245
|
+
log(id: string, timestamp: string, attributes: LogAttributes): void;
|
|
246
|
+
span(id: string, timestamp: string, attributes: SpanAttributes): void;
|
|
247
|
+
action(id: string, timestamp: string, attributes: ActionAttributes): void;
|
|
248
|
+
/** Flush queued events through a transport while preserving retry semantics. */
|
|
249
|
+
flush(transport: Transport): Promise<TransportResponse>;
|
|
250
|
+
/** Flush queued events, then mark the client closed so later writes fail. */
|
|
251
|
+
shutdown(transport: Transport): Promise<TransportResponse>;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/** Install explicit console capture while preserving the target console's normal output behavior. */
|
|
255
|
+
export declare function installLogBrewConsoleCapture(config: ConsoleCaptureConfig): ConsoleCaptureHandle;
|
|
256
|
+
|
|
257
|
+
/** Convert console arguments into safe LogBrew log attributes without installing capture. */
|
|
258
|
+
export declare function logAttributesFromConsoleArgs(
|
|
259
|
+
method: ConsoleMethodName,
|
|
260
|
+
args: readonly unknown[],
|
|
261
|
+
options?: {
|
|
262
|
+
logger?: string;
|
|
263
|
+
metadata?: Metadata;
|
|
264
|
+
includeErrorStack?: boolean;
|
|
265
|
+
}
|
|
266
|
+
): LogAttributes;
|
|
267
|
+
|
|
268
|
+
/** Map a console method name to the corresponding LogBrew log level. */
|
|
269
|
+
export declare function logbrewLevelFromConsoleMethod(method: ConsoleMethodName): LogAttributes["level"];
|
|
270
|
+
|
|
271
|
+
/** Parse a W3C traceparent value into normalized trace/span context. */
|
|
272
|
+
export declare function parseTraceparent(traceparent: string): TraceparentContext;
|
|
273
|
+
|
|
274
|
+
/** Create a W3C traceparent value from explicit trace/span ids. */
|
|
275
|
+
export declare function createTraceparent(input: TraceparentInput): string;
|
|
276
|
+
|
|
277
|
+
/** Build LogBrew span attributes that continue an incoming W3C traceparent value. */
|
|
278
|
+
export declare function spanAttributesFromTraceparent(
|
|
279
|
+
traceparent: string,
|
|
280
|
+
attributes: TraceparentSpanInput
|
|
281
|
+
): SpanAttributes;
|
|
282
|
+
|
|
283
|
+
/** Create a dependency-free Pino destination that turns JSON log lines into queued LogBrew log events. */
|
|
284
|
+
export declare function createLogBrewPinoDestination(config: PinoDestinationConfig): PinoDestinationHandle;
|
|
285
|
+
|
|
286
|
+
/** Convert a parsed Pino JSON log record into safe LogBrew log attributes without installing a destination. */
|
|
287
|
+
export declare function logAttributesFromPinoRecord(
|
|
288
|
+
record: PinoLogRecord,
|
|
289
|
+
options?: {
|
|
290
|
+
logger?: string;
|
|
291
|
+
metadata?: Metadata;
|
|
292
|
+
includeErrorStack?: boolean;
|
|
293
|
+
}
|
|
294
|
+
): LogAttributes;
|
|
295
|
+
|
|
296
|
+
/** Create a dependency-free Winston object-mode transport that queues LogBrew log events. */
|
|
297
|
+
export declare function createLogBrewWinstonTransport(config: WinstonTransportConfig): WinstonTransportHandle;
|
|
298
|
+
|
|
299
|
+
/** Convert a Winston info object into safe LogBrew log attributes without installing a transport. */
|
|
300
|
+
export declare function logAttributesFromWinstonInfo(
|
|
301
|
+
info: WinstonLogInfo,
|
|
302
|
+
options?: {
|
|
303
|
+
logger?: string;
|
|
304
|
+
metadata?: Metadata;
|
|
305
|
+
includeErrorStack?: boolean;
|
|
306
|
+
}
|
|
307
|
+
): LogAttributes;
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
/** Metadata values that can be attached to public LogBrew event payloads. */
|
|
2
|
+
export type MetadataValue = string | number | boolean | null;
|
|
3
|
+
/** Structured metadata map shared by public LogBrew event attribute types. */
|
|
4
|
+
export type Metadata = Record<string, MetadataValue>;
|
|
5
|
+
|
|
6
|
+
/** Parsed W3C trace context from a traceparent value. */
|
|
7
|
+
export type TraceparentContext = {
|
|
8
|
+
version: string;
|
|
9
|
+
traceId: string;
|
|
10
|
+
parentSpanId: string;
|
|
11
|
+
traceFlags: string;
|
|
12
|
+
sampled: boolean;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/** Inputs for creating a W3C traceparent value from known trace/span ids. */
|
|
16
|
+
export type TraceparentInput = {
|
|
17
|
+
traceId: string;
|
|
18
|
+
spanId: string;
|
|
19
|
+
traceFlags?: string;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/** Span fields supplied when deriving LogBrew span attributes from traceparent. */
|
|
23
|
+
export type TraceparentSpanInput = {
|
|
24
|
+
name: string;
|
|
25
|
+
spanId: string;
|
|
26
|
+
status: "ok" | "error";
|
|
27
|
+
durationMs?: number;
|
|
28
|
+
metadata?: Metadata;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/** Public release event attributes. */
|
|
32
|
+
export type ReleaseAttributes = {
|
|
33
|
+
version: string;
|
|
34
|
+
commit?: string;
|
|
35
|
+
notes?: string;
|
|
36
|
+
metadata?: Metadata;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/** Public environment event attributes. */
|
|
40
|
+
export type EnvironmentAttributes = {
|
|
41
|
+
name: string;
|
|
42
|
+
region?: string;
|
|
43
|
+
metadata?: Metadata;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/** Public issue event attributes. */
|
|
47
|
+
export type IssueAttributes = {
|
|
48
|
+
title: string;
|
|
49
|
+
level: "info" | "warning" | "error" | "critical";
|
|
50
|
+
message?: string;
|
|
51
|
+
metadata?: Metadata;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
/** Public log event attributes. */
|
|
55
|
+
export type LogAttributes = {
|
|
56
|
+
message: string;
|
|
57
|
+
level: "debug" | "info" | "warning" | "error";
|
|
58
|
+
logger?: string;
|
|
59
|
+
metadata?: Metadata;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
/** Console method names supported by the opt-in console capture helper. */
|
|
63
|
+
export type ConsoleMethodName = "debug" | "info" | "log" | "warn" | "error";
|
|
64
|
+
|
|
65
|
+
/** Minimal console-like target accepted by the opt-in console capture helper. */
|
|
66
|
+
export type ConsoleLike = Partial<Record<ConsoleMethodName, (...args: unknown[]) => void>>;
|
|
67
|
+
|
|
68
|
+
/** Configuration for opt-in console capture. */
|
|
69
|
+
export type ConsoleCaptureConfig = {
|
|
70
|
+
client: LogBrewClient;
|
|
71
|
+
console?: ConsoleLike;
|
|
72
|
+
levels?: ConsoleMethodName[];
|
|
73
|
+
logger?: string;
|
|
74
|
+
metadata?: Metadata;
|
|
75
|
+
transport?: Transport;
|
|
76
|
+
flushOnCapture?: boolean;
|
|
77
|
+
includeErrorStack?: boolean;
|
|
78
|
+
timestamp?: () => string;
|
|
79
|
+
eventIdPrefix?: string;
|
|
80
|
+
onError?: (error: unknown) => void;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
/** Handle returned by opt-in console capture installation. */
|
|
84
|
+
export type ConsoleCaptureHandle = {
|
|
85
|
+
flush(): Promise<TransportResponse | null>;
|
|
86
|
+
uninstall(): void;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
/** Pino JSON log record shape accepted by the optional Pino destination helper. */
|
|
90
|
+
export type PinoLogRecord = Record<string, unknown> & {
|
|
91
|
+
level?: string | number;
|
|
92
|
+
time?: string | number;
|
|
93
|
+
timestamp?: string | number;
|
|
94
|
+
msg?: unknown;
|
|
95
|
+
message?: unknown;
|
|
96
|
+
err?: unknown;
|
|
97
|
+
error?: unknown;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
/** Configuration for the dependency-free Pino destination adapter. */
|
|
101
|
+
export type PinoDestinationConfig = {
|
|
102
|
+
client: LogBrewClient;
|
|
103
|
+
logger?: string;
|
|
104
|
+
metadata?: Metadata;
|
|
105
|
+
transport?: Transport;
|
|
106
|
+
flushOnWrite?: boolean;
|
|
107
|
+
includeErrorStack?: boolean;
|
|
108
|
+
timestamp?: () => string;
|
|
109
|
+
eventIdPrefix?: string;
|
|
110
|
+
onError?: (error: unknown) => void;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
/** Stream-like destination returned for use as Pino's output destination. */
|
|
114
|
+
export type PinoDestinationHandle = {
|
|
115
|
+
write(chunk: unknown): boolean;
|
|
116
|
+
flush(): Promise<TransportResponse | null>;
|
|
117
|
+
end(): Promise<TransportResponse | null>;
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
/** Winston info object shape accepted by the optional Winston transport helper. */
|
|
121
|
+
export type WinstonLogInfo = Record<string, unknown> & {
|
|
122
|
+
level?: string;
|
|
123
|
+
message?: unknown;
|
|
124
|
+
timestamp?: string | number | Date;
|
|
125
|
+
time?: string | number | Date;
|
|
126
|
+
err?: unknown;
|
|
127
|
+
error?: unknown;
|
|
128
|
+
stack?: unknown;
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
/** Configuration for the dependency-free Winston transport adapter. */
|
|
132
|
+
export type WinstonTransportConfig = {
|
|
133
|
+
client: LogBrewClient;
|
|
134
|
+
logger?: string;
|
|
135
|
+
metadata?: Metadata;
|
|
136
|
+
transport?: Transport;
|
|
137
|
+
flushOnWrite?: boolean;
|
|
138
|
+
includeErrorStack?: boolean;
|
|
139
|
+
timestamp?: () => string;
|
|
140
|
+
eventIdPrefix?: string;
|
|
141
|
+
level?: string;
|
|
142
|
+
name?: string;
|
|
143
|
+
silent?: boolean;
|
|
144
|
+
handleExceptions?: boolean;
|
|
145
|
+
handleRejections?: boolean;
|
|
146
|
+
onError?: (error: unknown) => void;
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
/** Object-mode transport returned for use in a Winston logger's transports array. */
|
|
150
|
+
export type WinstonTransportHandle = {
|
|
151
|
+
level?: string;
|
|
152
|
+
name?: string;
|
|
153
|
+
silent?: boolean;
|
|
154
|
+
handleExceptions?: boolean;
|
|
155
|
+
handleRejections?: boolean;
|
|
156
|
+
log(info: WinstonLogInfo, callback?: () => void): void;
|
|
157
|
+
write(info: WinstonLogInfo): boolean;
|
|
158
|
+
flush(): Promise<TransportResponse | null>;
|
|
159
|
+
end(callback?: () => void): unknown;
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
/** Public span event attributes. */
|
|
163
|
+
export type SpanAttributes = {
|
|
164
|
+
name: string;
|
|
165
|
+
traceId: string;
|
|
166
|
+
spanId: string;
|
|
167
|
+
parentSpanId?: string;
|
|
168
|
+
status: "ok" | "error";
|
|
169
|
+
durationMs?: number;
|
|
170
|
+
metadata?: Metadata;
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
/** Public action event attributes. */
|
|
174
|
+
export type ActionAttributes = {
|
|
175
|
+
name: string;
|
|
176
|
+
status: "queued" | "running" | "success" | "failure";
|
|
177
|
+
metadata?: Metadata;
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
/** Public event union used in preview and transport payloads. */
|
|
181
|
+
export type Event =
|
|
182
|
+
| { type: "release"; id: string; timestamp: string; attributes: ReleaseAttributes }
|
|
183
|
+
| { type: "environment"; id: string; timestamp: string; attributes: EnvironmentAttributes }
|
|
184
|
+
| { type: "issue"; id: string; timestamp: string; attributes: IssueAttributes }
|
|
185
|
+
| { type: "log"; id: string; timestamp: string; attributes: LogAttributes }
|
|
186
|
+
| { type: "span"; id: string; timestamp: string; attributes: SpanAttributes }
|
|
187
|
+
| { type: "action"; id: string; timestamp: string; attributes: ActionAttributes };
|
|
188
|
+
|
|
189
|
+
/** Stable transport response returned from flush and shutdown operations. */
|
|
190
|
+
export type TransportResponse = {
|
|
191
|
+
/** Final HTTP-like status returned by the transport. */
|
|
192
|
+
statusCode: number;
|
|
193
|
+
/** Number of transport attempts used for the flush. */
|
|
194
|
+
attempts: number;
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
/** Minimal transport interface accepted by flush and shutdown operations. */
|
|
198
|
+
export type Transport = {
|
|
199
|
+
send(apiKey: string, body: string): TransportResponse | Promise<TransportResponse>;
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
/** Stable public SDK error with parseable code and message fields. */
|
|
203
|
+
export declare class SdkError extends Error {
|
|
204
|
+
code: string;
|
|
205
|
+
constructor(code: string, message: string);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/** Transport error that can optionally be marked retryable by the caller. */
|
|
209
|
+
export declare class TransportError extends Error {
|
|
210
|
+
code: string;
|
|
211
|
+
retryable: boolean;
|
|
212
|
+
constructor(code: string, message: string, retryable?: boolean);
|
|
213
|
+
/** Create a retryable network failure that preserves queued events. */
|
|
214
|
+
static network(message: string): TransportError;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/** Scripted transport for previewing, accepting, or failing queued event flushes. */
|
|
218
|
+
export declare class RecordingTransport {
|
|
219
|
+
constructor(scriptedResponses?: Array<{ statusCode: number } | Error>);
|
|
220
|
+
/** Every request body sent through this transport instance. */
|
|
221
|
+
sentBodies: string[];
|
|
222
|
+
/** Create a transport that accepts queued flushes with a 202 response. */
|
|
223
|
+
static alwaysAccept(): RecordingTransport;
|
|
224
|
+
/** Return the most recent request body sent through this transport. */
|
|
225
|
+
lastBody(): string | null;
|
|
226
|
+
send(apiKey: string, body: string): Promise<TransportResponse>;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/** Buffered public client for validating, previewing, and flushing LogBrew events. */
|
|
230
|
+
export declare class LogBrewClient {
|
|
231
|
+
/** Create a client from public SDK identity, retry, and API key settings. */
|
|
232
|
+
static create(config: {
|
|
233
|
+
apiKey: string;
|
|
234
|
+
sdkName: string;
|
|
235
|
+
sdkVersion: string;
|
|
236
|
+
maxRetries?: number;
|
|
237
|
+
}): LogBrewClient;
|
|
238
|
+
/** Return the queued event count currently buffered in memory. */
|
|
239
|
+
pendingEvents(): number;
|
|
240
|
+
/** Return the queued event batch as stable, pretty-printed JSON. */
|
|
241
|
+
previewJson(): string;
|
|
242
|
+
release(id: string, timestamp: string, attributes: ReleaseAttributes): void;
|
|
243
|
+
environment(id: string, timestamp: string, attributes: EnvironmentAttributes): void;
|
|
244
|
+
issue(id: string, timestamp: string, attributes: IssueAttributes): void;
|
|
245
|
+
log(id: string, timestamp: string, attributes: LogAttributes): void;
|
|
246
|
+
span(id: string, timestamp: string, attributes: SpanAttributes): void;
|
|
247
|
+
action(id: string, timestamp: string, attributes: ActionAttributes): void;
|
|
248
|
+
/** Flush queued events through a transport while preserving retry semantics. */
|
|
249
|
+
flush(transport: Transport): Promise<TransportResponse>;
|
|
250
|
+
/** Flush queued events, then mark the client closed so later writes fail. */
|
|
251
|
+
shutdown(transport: Transport): Promise<TransportResponse>;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/** Install explicit console capture while preserving the target console's normal output behavior. */
|
|
255
|
+
export declare function installLogBrewConsoleCapture(config: ConsoleCaptureConfig): ConsoleCaptureHandle;
|
|
256
|
+
|
|
257
|
+
/** Convert console arguments into safe LogBrew log attributes without installing capture. */
|
|
258
|
+
export declare function logAttributesFromConsoleArgs(
|
|
259
|
+
method: ConsoleMethodName,
|
|
260
|
+
args: readonly unknown[],
|
|
261
|
+
options?: {
|
|
262
|
+
logger?: string;
|
|
263
|
+
metadata?: Metadata;
|
|
264
|
+
includeErrorStack?: boolean;
|
|
265
|
+
}
|
|
266
|
+
): LogAttributes;
|
|
267
|
+
|
|
268
|
+
/** Map a console method name to the corresponding LogBrew log level. */
|
|
269
|
+
export declare function logbrewLevelFromConsoleMethod(method: ConsoleMethodName): LogAttributes["level"];
|
|
270
|
+
|
|
271
|
+
/** Parse a W3C traceparent value into normalized trace/span context. */
|
|
272
|
+
export declare function parseTraceparent(traceparent: string): TraceparentContext;
|
|
273
|
+
|
|
274
|
+
/** Create a W3C traceparent value from explicit trace/span ids. */
|
|
275
|
+
export declare function createTraceparent(input: TraceparentInput): string;
|
|
276
|
+
|
|
277
|
+
/** Build LogBrew span attributes that continue an incoming W3C traceparent value. */
|
|
278
|
+
export declare function spanAttributesFromTraceparent(
|
|
279
|
+
traceparent: string,
|
|
280
|
+
attributes: TraceparentSpanInput
|
|
281
|
+
): SpanAttributes;
|
|
282
|
+
|
|
283
|
+
/** Create a dependency-free Pino destination that turns JSON log lines into queued LogBrew log events. */
|
|
284
|
+
export declare function createLogBrewPinoDestination(config: PinoDestinationConfig): PinoDestinationHandle;
|
|
285
|
+
|
|
286
|
+
/** Convert a parsed Pino JSON log record into safe LogBrew log attributes without installing a destination. */
|
|
287
|
+
export declare function logAttributesFromPinoRecord(
|
|
288
|
+
record: PinoLogRecord,
|
|
289
|
+
options?: {
|
|
290
|
+
logger?: string;
|
|
291
|
+
metadata?: Metadata;
|
|
292
|
+
includeErrorStack?: boolean;
|
|
293
|
+
}
|
|
294
|
+
): LogAttributes;
|
|
295
|
+
|
|
296
|
+
/** Create a dependency-free Winston object-mode transport that queues LogBrew log events. */
|
|
297
|
+
export declare function createLogBrewWinstonTransport(config: WinstonTransportConfig): WinstonTransportHandle;
|
|
298
|
+
|
|
299
|
+
/** Convert a Winston info object into safe LogBrew log attributes without installing a transport. */
|
|
300
|
+
export declare function logAttributesFromWinstonInfo(
|
|
301
|
+
info: WinstonLogInfo,
|
|
302
|
+
options?: {
|
|
303
|
+
logger?: string;
|
|
304
|
+
metadata?: Metadata;
|
|
305
|
+
includeErrorStack?: boolean;
|
|
306
|
+
}
|
|
307
|
+
): LogAttributes;
|
package/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import sdk from "./index.cjs";
|
|
2
|
+
|
|
3
|
+
export const {
|
|
4
|
+
createTraceparent,
|
|
5
|
+
createLogBrewPinoDestination,
|
|
6
|
+
createLogBrewWinstonTransport,
|
|
7
|
+
installLogBrewConsoleCapture,
|
|
8
|
+
LogBrewClient,
|
|
9
|
+
logAttributesFromConsoleArgs,
|
|
10
|
+
logAttributesFromPinoRecord,
|
|
11
|
+
logAttributesFromWinstonInfo,
|
|
12
|
+
logbrewLevelFromConsoleMethod,
|
|
13
|
+
parseTraceparent,
|
|
14
|
+
RecordingTransport,
|
|
15
|
+
SdkError,
|
|
16
|
+
spanAttributesFromTraceparent,
|
|
17
|
+
TransportError
|
|
18
|
+
} = sdk;
|
|
19
|
+
|
|
20
|
+
export default sdk;
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@logbrew/sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Public LogBrew JavaScript SDK for building, validating, and flushing event batches.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./index.cjs",
|
|
7
|
+
"types": "./index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": {
|
|
11
|
+
"types": "./index.d.ts",
|
|
12
|
+
"default": "./index.js"
|
|
13
|
+
},
|
|
14
|
+
"require": {
|
|
15
|
+
"types": "./index.d.cts",
|
|
16
|
+
"default": "./index.cjs"
|
|
17
|
+
},
|
|
18
|
+
"default": "./index.js"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"index.cjs",
|
|
23
|
+
"index.js",
|
|
24
|
+
"index.d.ts",
|
|
25
|
+
"index.d.cts",
|
|
26
|
+
"README.md",
|
|
27
|
+
"examples"
|
|
28
|
+
],
|
|
29
|
+
"keywords": [
|
|
30
|
+
"logbrew",
|
|
31
|
+
"observability",
|
|
32
|
+
"logs",
|
|
33
|
+
"traces",
|
|
34
|
+
"events"
|
|
35
|
+
],
|
|
36
|
+
"sideEffects": false,
|
|
37
|
+
"engines": {
|
|
38
|
+
"node": ">=18"
|
|
39
|
+
},
|
|
40
|
+
"license": "MIT",
|
|
41
|
+
"repository": {
|
|
42
|
+
"type": "git",
|
|
43
|
+
"url": "git+https://github.com/LogBrewCo/sdk.git"
|
|
44
|
+
},
|
|
45
|
+
"scripts": {
|
|
46
|
+
"test": "node --test",
|
|
47
|
+
"smoke": "node ./smoke.js"
|
|
48
|
+
}
|
|
49
|
+
}
|