sloplog 0.0.3
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 +204 -0
- package/dist/codegen.d.ts +43 -0
- package/dist/codegen.js +500 -0
- package/dist/collectors/betterstack.d.ts +47 -0
- package/dist/collectors/betterstack.js +74 -0
- package/dist/collectors/composite.d.ts +1 -0
- package/dist/collectors/composite.js +1 -0
- package/dist/collectors/file.d.ts +1 -0
- package/dist/collectors/file.js +1 -0
- package/dist/collectors/filtered.d.ts +1 -0
- package/dist/collectors/filtered.js +1 -0
- package/dist/collectors/index.d.ts +102 -0
- package/dist/collectors/index.js +127 -0
- package/dist/collectors/sentry.d.ts +46 -0
- package/dist/collectors/sentry.js +45 -0
- package/dist/collectors/stdio.d.ts +1 -0
- package/dist/collectors/stdio.js +1 -0
- package/dist/generated/partials.d.ts +40 -0
- package/dist/generated/partials.js +3 -0
- package/dist/index.d.ts +199 -0
- package/dist/index.js +354 -0
- package/dist/originator/index.d.ts +150 -0
- package/dist/originator/index.js +217 -0
- package/dist/partials.d.ts +154 -0
- package/dist/partials.js +52 -0
- package/dist/registry.d.ts +89 -0
- package/dist/registry.js +44 -0
- package/dist/wevt-0.0.1-py3-none-any.whl +0 -0
- package/dist/wevt-0.0.1.tar.gz +0 -0
- package/dist/wevt-0.0.2-py3-none-any.whl +0 -0
- package/dist/wevt-0.0.2.tar.gz +0 -0
- package/package.json +101 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import type { WideEventBase, EventPartial } from '../index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Options passed to collectors when flushing an event
|
|
4
|
+
*/
|
|
5
|
+
export interface FlushOptions {
|
|
6
|
+
/**
|
|
7
|
+
* If true, the event should always be sampled/collected regardless of sampling rules.
|
|
8
|
+
* This is set when any partial with alwaysSample=true is attached to the event.
|
|
9
|
+
*/
|
|
10
|
+
alwaysSample: boolean;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Collectors
|
|
14
|
+
* Adapts the log to some format and flushes to an external service.
|
|
15
|
+
* Partials may be singular objects or arrays for repeatable partials.
|
|
16
|
+
*/
|
|
17
|
+
export interface LogCollectorClient {
|
|
18
|
+
flush(event: WideEventBase, partials: Map<string, EventPartial<string> | EventPartial<string>[]>, options: FlushOptions): Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
/** Type alias for partial values (singular or array) */
|
|
21
|
+
type PartialValue = EventPartial<string> | EventPartial<string>[];
|
|
22
|
+
/**
|
|
23
|
+
* Simple collector to log the event to stdout/console
|
|
24
|
+
*/
|
|
25
|
+
export declare class StdioCollector implements LogCollectorClient {
|
|
26
|
+
flush(eventBase: WideEventBase, partials: Map<string, PartialValue>, _options: FlushOptions): Promise<void>;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Create a collector that logs events to stdout/console.
|
|
30
|
+
*/
|
|
31
|
+
export declare function stdioCollector(): StdioCollector;
|
|
32
|
+
/**
|
|
33
|
+
* Composes multiple collectors together, flushing to all of them in parallel
|
|
34
|
+
*/
|
|
35
|
+
export declare class CompositeCollector implements LogCollectorClient {
|
|
36
|
+
private collectors;
|
|
37
|
+
constructor(collectors: LogCollectorClient[]);
|
|
38
|
+
flush(event: WideEventBase, partials: Map<string, PartialValue>, options: FlushOptions): Promise<void>;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Create a collector that flushes to multiple collectors in parallel.
|
|
42
|
+
*/
|
|
43
|
+
export declare function compositeCollector(collectors: LogCollectorClient[]): CompositeCollector;
|
|
44
|
+
/**
|
|
45
|
+
* Filter function type for FilteredCollector
|
|
46
|
+
*/
|
|
47
|
+
export type EventFilter = (event: WideEventBase, partials: Map<string, PartialValue>, options: FlushOptions) => boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Wraps a collector and only flushes events that pass the filter function.
|
|
50
|
+
* Note: Events with alwaysSample=true bypass the filter by default.
|
|
51
|
+
*/
|
|
52
|
+
export declare class FilteredCollector implements LogCollectorClient {
|
|
53
|
+
private collector;
|
|
54
|
+
private filter;
|
|
55
|
+
constructor(collector: LogCollectorClient, filter: EventFilter);
|
|
56
|
+
flush(event: WideEventBase, partials: Map<string, PartialValue>, options: FlushOptions): Promise<void>;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Create a collector that filters events before flushing.
|
|
60
|
+
*/
|
|
61
|
+
export declare function filteredCollector(collector: LogCollectorClient, filter: EventFilter): FilteredCollector;
|
|
62
|
+
/**
|
|
63
|
+
* Options for FileCollector
|
|
64
|
+
*/
|
|
65
|
+
export interface FileCollectorOptions {
|
|
66
|
+
/** Number of events to buffer before flushing to disk (default: 10) */
|
|
67
|
+
bufferSize?: number;
|
|
68
|
+
/** Maximum time in ms to wait before flushing buffer (default: 5000) */
|
|
69
|
+
flushIntervalMs?: number;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Filesystem interface for FileCollector (allows injection for testing)
|
|
73
|
+
*/
|
|
74
|
+
export interface FileSystem {
|
|
75
|
+
appendFile(path: string, data: string): Promise<void>;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Collector that writes events to a file with buffering
|
|
79
|
+
*/
|
|
80
|
+
export declare class FileCollector implements LogCollectorClient {
|
|
81
|
+
private filePath;
|
|
82
|
+
private fs;
|
|
83
|
+
private buffer;
|
|
84
|
+
private bufferSize;
|
|
85
|
+
private flushIntervalMs;
|
|
86
|
+
private flushTimer;
|
|
87
|
+
constructor(filePath: string, fs: FileSystem, options?: FileCollectorOptions);
|
|
88
|
+
flush(event: WideEventBase, partials: Map<string, PartialValue>, _options: FlushOptions): Promise<void>;
|
|
89
|
+
/**
|
|
90
|
+
* Flush the buffer to disk
|
|
91
|
+
*/
|
|
92
|
+
flushBuffer(): Promise<void>;
|
|
93
|
+
/**
|
|
94
|
+
* Force flush any remaining buffered events (call on shutdown)
|
|
95
|
+
*/
|
|
96
|
+
close(): Promise<void>;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Create a collector that writes events to a file with buffering.
|
|
100
|
+
*/
|
|
101
|
+
export declare function fileCollector(filePath: string, fs: FileSystem, options?: FileCollectorOptions): FileCollector;
|
|
102
|
+
export {};
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Simple collector to log the event to stdout/console
|
|
3
|
+
*/
|
|
4
|
+
export class StdioCollector {
|
|
5
|
+
async flush(eventBase, partials, _options) {
|
|
6
|
+
const partialsObj = {};
|
|
7
|
+
for (const [key, value] of partials) {
|
|
8
|
+
partialsObj[key] = value;
|
|
9
|
+
}
|
|
10
|
+
// eslint-disable-next-line no-console
|
|
11
|
+
console.log(JSON.stringify({
|
|
12
|
+
...eventBase,
|
|
13
|
+
...partialsObj,
|
|
14
|
+
}));
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Create a collector that logs events to stdout/console.
|
|
19
|
+
*/
|
|
20
|
+
export function stdioCollector() {
|
|
21
|
+
return new StdioCollector();
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Composes multiple collectors together, flushing to all of them in parallel
|
|
25
|
+
*/
|
|
26
|
+
export class CompositeCollector {
|
|
27
|
+
collectors;
|
|
28
|
+
constructor(collectors) {
|
|
29
|
+
this.collectors = collectors;
|
|
30
|
+
}
|
|
31
|
+
async flush(event, partials, options) {
|
|
32
|
+
await Promise.all(this.collectors.map((c) => c.flush(event, partials, options)));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Create a collector that flushes to multiple collectors in parallel.
|
|
37
|
+
*/
|
|
38
|
+
export function compositeCollector(collectors) {
|
|
39
|
+
return new CompositeCollector(collectors);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Wraps a collector and only flushes events that pass the filter function.
|
|
43
|
+
* Note: Events with alwaysSample=true bypass the filter by default.
|
|
44
|
+
*/
|
|
45
|
+
export class FilteredCollector {
|
|
46
|
+
collector;
|
|
47
|
+
filter;
|
|
48
|
+
constructor(collector, filter) {
|
|
49
|
+
this.collector = collector;
|
|
50
|
+
this.filter = filter;
|
|
51
|
+
}
|
|
52
|
+
async flush(event, partials, options) {
|
|
53
|
+
// Always-sample events bypass the filter
|
|
54
|
+
if (options.alwaysSample || this.filter(event, partials, options)) {
|
|
55
|
+
await this.collector.flush(event, partials, options);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Create a collector that filters events before flushing.
|
|
61
|
+
*/
|
|
62
|
+
export function filteredCollector(collector, filter) {
|
|
63
|
+
return new FilteredCollector(collector, filter);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Collector that writes events to a file with buffering
|
|
67
|
+
*/
|
|
68
|
+
export class FileCollector {
|
|
69
|
+
filePath;
|
|
70
|
+
fs;
|
|
71
|
+
buffer = [];
|
|
72
|
+
bufferSize;
|
|
73
|
+
flushIntervalMs;
|
|
74
|
+
flushTimer = null;
|
|
75
|
+
constructor(filePath, fs, options = {}) {
|
|
76
|
+
this.filePath = filePath;
|
|
77
|
+
this.fs = fs;
|
|
78
|
+
this.bufferSize = options.bufferSize ?? 10;
|
|
79
|
+
this.flushIntervalMs = options.flushIntervalMs ?? 5000;
|
|
80
|
+
}
|
|
81
|
+
async flush(event, partials, _options) {
|
|
82
|
+
const partialsObj = {};
|
|
83
|
+
for (const [key, value] of partials) {
|
|
84
|
+
partialsObj[key] = value;
|
|
85
|
+
}
|
|
86
|
+
const line = JSON.stringify({
|
|
87
|
+
...event,
|
|
88
|
+
...partialsObj,
|
|
89
|
+
}) + '\n';
|
|
90
|
+
this.buffer.push(line);
|
|
91
|
+
// Start flush timer if not already running
|
|
92
|
+
if (!this.flushTimer) {
|
|
93
|
+
this.flushTimer = setTimeout(() => this.flushBuffer(), this.flushIntervalMs);
|
|
94
|
+
}
|
|
95
|
+
// Flush immediately if buffer is full
|
|
96
|
+
if (this.buffer.length >= this.bufferSize) {
|
|
97
|
+
await this.flushBuffer();
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Flush the buffer to disk
|
|
102
|
+
*/
|
|
103
|
+
async flushBuffer() {
|
|
104
|
+
if (this.flushTimer) {
|
|
105
|
+
clearTimeout(this.flushTimer);
|
|
106
|
+
this.flushTimer = null;
|
|
107
|
+
}
|
|
108
|
+
if (this.buffer.length === 0) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const data = this.buffer.join('');
|
|
112
|
+
this.buffer = [];
|
|
113
|
+
await this.fs.appendFile(this.filePath, data);
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Force flush any remaining buffered events (call on shutdown)
|
|
117
|
+
*/
|
|
118
|
+
async close() {
|
|
119
|
+
await this.flushBuffer();
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Create a collector that writes events to a file with buffering.
|
|
124
|
+
*/
|
|
125
|
+
export function fileCollector(filePath, fs, options = {}) {
|
|
126
|
+
return new FileCollector(filePath, fs, options);
|
|
127
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { WideEventBase, EventPartial } from '../index.js';
|
|
2
|
+
import type { LogCollectorClient, FlushOptions } from './index.js';
|
|
3
|
+
/** Type alias for partial values (singular or array) */
|
|
4
|
+
type PartialValue = EventPartial<string> | EventPartial<string>[];
|
|
5
|
+
export type SentryLogLevel = 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'fatal';
|
|
6
|
+
export interface SentryLogger {
|
|
7
|
+
log?: (level: SentryLogLevel, message: string, attributes?: Record<string, unknown>) => void;
|
|
8
|
+
trace?: (message: string, attributes?: Record<string, unknown>) => void;
|
|
9
|
+
debug?: (message: string, attributes?: Record<string, unknown>) => void;
|
|
10
|
+
info?: (message: string, attributes?: Record<string, unknown>) => void;
|
|
11
|
+
warn?: (message: string, attributes?: Record<string, unknown>) => void;
|
|
12
|
+
error?: (message: string, attributes?: Record<string, unknown>) => void;
|
|
13
|
+
fatal?: (message: string, attributes?: Record<string, unknown>) => void;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Options for SentryCollector
|
|
17
|
+
*/
|
|
18
|
+
export interface SentryCollectorOptions {
|
|
19
|
+
/**
|
|
20
|
+
* Sentry logger instance (e.g. Sentry.logger). Requires the Sentry logger
|
|
21
|
+
* integration to be configured during Sentry.init().
|
|
22
|
+
*/
|
|
23
|
+
logger: SentryLogger;
|
|
24
|
+
/** Default log level for events (default: "info") */
|
|
25
|
+
level?: SentryLogLevel;
|
|
26
|
+
/** Optional function to derive log level per event */
|
|
27
|
+
levelSelector?: (event: WideEventBase, partials: Map<string, PartialValue>, options: FlushOptions) => SentryLogLevel;
|
|
28
|
+
/** Log message to use (default: "wide-event") */
|
|
29
|
+
message?: string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Collector that sends events to Sentry Logs via the Sentry logger API
|
|
33
|
+
*/
|
|
34
|
+
export declare class SentryCollector implements LogCollectorClient {
|
|
35
|
+
private logger;
|
|
36
|
+
private defaultLevel;
|
|
37
|
+
private levelSelector?;
|
|
38
|
+
private message;
|
|
39
|
+
constructor(options: SentryCollectorOptions);
|
|
40
|
+
flush(event: WideEventBase, partials: Map<string, PartialValue>, options: FlushOptions): Promise<void>;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Create a collector that sends events via the Sentry logger.
|
|
44
|
+
*/
|
|
45
|
+
export declare function sentryCollector(options: SentryCollectorOptions): SentryCollector;
|
|
46
|
+
export {};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Collector that sends events to Sentry Logs via the Sentry logger API
|
|
3
|
+
*/
|
|
4
|
+
export class SentryCollector {
|
|
5
|
+
logger;
|
|
6
|
+
defaultLevel;
|
|
7
|
+
levelSelector;
|
|
8
|
+
message;
|
|
9
|
+
constructor(options) {
|
|
10
|
+
this.logger = options.logger;
|
|
11
|
+
this.defaultLevel = options.level ?? 'info';
|
|
12
|
+
this.levelSelector = options.levelSelector;
|
|
13
|
+
this.message = options.message ?? 'wide-event';
|
|
14
|
+
}
|
|
15
|
+
async flush(event, partials, options) {
|
|
16
|
+
const partialsObj = {};
|
|
17
|
+
for (const [key, value] of partials) {
|
|
18
|
+
partialsObj[key] = value;
|
|
19
|
+
}
|
|
20
|
+
const attributes = {
|
|
21
|
+
...event,
|
|
22
|
+
...partialsObj,
|
|
23
|
+
};
|
|
24
|
+
const level = this.levelSelector
|
|
25
|
+
? this.levelSelector(event, partials, options)
|
|
26
|
+
: this.defaultLevel;
|
|
27
|
+
const loggerMethod = (level === 'trace' && this.logger.trace) ||
|
|
28
|
+
(level === 'debug' && this.logger.debug) ||
|
|
29
|
+
(level === 'info' && this.logger.info) ||
|
|
30
|
+
(level === 'warn' && this.logger.warn) ||
|
|
31
|
+
(level === 'error' && this.logger.error) ||
|
|
32
|
+
(level === 'fatal' && this.logger.fatal);
|
|
33
|
+
if (loggerMethod) {
|
|
34
|
+
loggerMethod(this.message, attributes);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
this.logger.log?.(level, this.message, attributes);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Create a collector that sends events via the Sentry logger.
|
|
42
|
+
*/
|
|
43
|
+
export function sentryCollector(options) {
|
|
44
|
+
return new SentryCollector(options);
|
|
45
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { StdioCollector, stdioCollector } from './index.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { StdioCollector, stdioCollector } from './index.js';
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { EventPartial } from '../index';
|
|
2
|
+
export interface UserPartial extends EventPartial<'user'> {
|
|
3
|
+
type: 'user';
|
|
4
|
+
userId: string;
|
|
5
|
+
subscriptionLevel: string;
|
|
6
|
+
dateJoined: number;
|
|
7
|
+
}
|
|
8
|
+
export interface SessionPartial extends EventPartial<'session'> {
|
|
9
|
+
type: 'session';
|
|
10
|
+
sessionId: string;
|
|
11
|
+
messages: number;
|
|
12
|
+
startedAt: number;
|
|
13
|
+
}
|
|
14
|
+
export interface ErrorPartial extends EventPartial<'error'> {
|
|
15
|
+
type: 'error';
|
|
16
|
+
message: string;
|
|
17
|
+
stack?: string;
|
|
18
|
+
code?: number;
|
|
19
|
+
}
|
|
20
|
+
export interface ResponsePartial extends EventPartial<'response'> {
|
|
21
|
+
type: 'response';
|
|
22
|
+
statusCode: number;
|
|
23
|
+
durationMs: number;
|
|
24
|
+
contentLength?: number;
|
|
25
|
+
}
|
|
26
|
+
export interface DbQueryPartial extends EventPartial<'db_query'> {
|
|
27
|
+
type: 'db_query';
|
|
28
|
+
query: string;
|
|
29
|
+
durationMs: number;
|
|
30
|
+
rowCount?: number;
|
|
31
|
+
error?: string;
|
|
32
|
+
}
|
|
33
|
+
export type GeneratedRegistry = {
|
|
34
|
+
user: UserPartial;
|
|
35
|
+
session: SessionPartial;
|
|
36
|
+
error: ErrorPartial;
|
|
37
|
+
response: ResponsePartial;
|
|
38
|
+
db_query: DbQueryPartial;
|
|
39
|
+
};
|
|
40
|
+
export type PartialName = 'user' | 'session' | 'error' | 'response' | 'db_query';
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import type { ZodRawShape } from 'zod';
|
|
2
|
+
import type { LogCollectorClient } from './collectors/index.js';
|
|
3
|
+
import type { PartialMetadata, PartialDefinition, PartialOptions, Registry, RegistryType } from './registry.js';
|
|
4
|
+
/** Current sloplog library version (propagated onto Service). */
|
|
5
|
+
export declare const SLOPLOG_VERSION = "0.0.2";
|
|
6
|
+
/**
|
|
7
|
+
* TYPES
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* An event partial is a structured bit of data added to a wide event.
|
|
11
|
+
* Each partial has a type discriminator and arbitrary additional fields.
|
|
12
|
+
*/
|
|
13
|
+
export type EventPartial<K extends string = string> = {
|
|
14
|
+
type: K;
|
|
15
|
+
} & Record<string, unknown>;
|
|
16
|
+
type RegistryEntry<K extends string> = {
|
|
17
|
+
type: K;
|
|
18
|
+
} & Record<string, unknown>;
|
|
19
|
+
type RegistryShape = Record<string, EventPartial<string> | EventPartial<string>[]>;
|
|
20
|
+
/**
|
|
21
|
+
* Validates that a registry maps keys to objects with matching type discriminators
|
|
22
|
+
*/
|
|
23
|
+
export type ValidRegistry<T> = {
|
|
24
|
+
[K in keyof T]: K extends string ? T[K] extends RegistryEntry<K> | RegistryEntry<K>[] ? T[K] : never : never;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* A registry of event partials - defines the shape of all partials that can be logged
|
|
28
|
+
*/
|
|
29
|
+
export type EventPartialRegistry<T extends ValidRegistry<T>> = {
|
|
30
|
+
[K in keyof T]: T[K];
|
|
31
|
+
};
|
|
32
|
+
type RegistryEntryValue<T> = T extends (infer U)[] ? U : T;
|
|
33
|
+
type RegistryEntries<R> = {
|
|
34
|
+
[K in keyof R]: RegistryEntryValue<R[K]>;
|
|
35
|
+
}[keyof R];
|
|
36
|
+
type AnyRegistry = Registry<PartialDefinition<string, ZodRawShape, PartialOptions>[]>;
|
|
37
|
+
type OriginatorInput = import('./originator/index.js').Originator | import('./originator/index.js').OriginatorFromRequestResult;
|
|
38
|
+
/**
|
|
39
|
+
* Service information - where an event is emitted from
|
|
40
|
+
*/
|
|
41
|
+
export interface Service {
|
|
42
|
+
/** Service name (required) */
|
|
43
|
+
name: string;
|
|
44
|
+
/** Service version, if available */
|
|
45
|
+
version?: string;
|
|
46
|
+
/** sloplog library version (auto-populated if omitted) */
|
|
47
|
+
sloplogVersion?: string;
|
|
48
|
+
/** sloplog language marker (auto-populated if omitted) */
|
|
49
|
+
sloplogLanguage?: string;
|
|
50
|
+
[key: string]: unknown;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Create a Service payload with sloplog defaults applied.
|
|
54
|
+
*/
|
|
55
|
+
export declare function service(details: Service): Service;
|
|
56
|
+
/**
|
|
57
|
+
* The base structure of a wide event
|
|
58
|
+
*/
|
|
59
|
+
export interface WideEventBase {
|
|
60
|
+
/** Unique event identifier */
|
|
61
|
+
eventId: string;
|
|
62
|
+
/** Trace ID that stays constant across the entire distributed trace */
|
|
63
|
+
traceId: string;
|
|
64
|
+
/** Service metadata for the emitting service */
|
|
65
|
+
service: Service;
|
|
66
|
+
/** Originator metadata for the event */
|
|
67
|
+
originator: import('./originator/index.js').Originator;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The full wide event log structure including partials
|
|
71
|
+
*/
|
|
72
|
+
export type WideEventLog<R extends RegistryShape> = WideEventBase & Partial<R>;
|
|
73
|
+
/**
|
|
74
|
+
* Allowed log levels for log_message partials and log() calls
|
|
75
|
+
*/
|
|
76
|
+
export type LogMessageLevel = 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'fatal';
|
|
77
|
+
export { type Originator, type HttpOriginator, type HttpMethod, type WebSocketOriginator, type CronOriginator, type TracingContext, type HttpOriginatorOptions, type OriginatorFromRequestResult, type NodeIncomingMessage, type CronOriginatorOptions, ORIGINATOR_HEADER, TRACE_ID_HEADER, httpOriginator, nodeHttpOriginator, cronOriginator, tracingHeaders, extractTracingContext, } from './originator/index.js';
|
|
78
|
+
export type { LogCollectorClient, FlushOptions } from './collectors/index.js';
|
|
79
|
+
export { builtInPartials, builtInRegistry, builtInPartialMetadata } from './partials.js';
|
|
80
|
+
export type { BuiltInRegistry, BuiltInPartialName, ErrorPartial, LogMessagePartial, SpanPartial, SloplogUsageErrorPartial, } from './partials.js';
|
|
81
|
+
/**
|
|
82
|
+
* Options for creating a WideEvent
|
|
83
|
+
*/
|
|
84
|
+
export interface WideEventOptions {
|
|
85
|
+
/** Trace ID to use (for continuing an existing trace). If not provided, a new one is generated. */
|
|
86
|
+
traceId?: string;
|
|
87
|
+
/**
|
|
88
|
+
* Runtime metadata about partials. Required for proper handling of repeatable partials
|
|
89
|
+
* and alwaysSample behavior. Defaults to metadata derived from the registry.
|
|
90
|
+
*/
|
|
91
|
+
partialMetadata?: Map<string, PartialMetadata>;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Zod-based DSL for defining wide event partials
|
|
95
|
+
* Restricted to only allow specific primitive types for cross-language compatibility
|
|
96
|
+
*/
|
|
97
|
+
export { z, partial, registry, extractPartialMetadata } from './registry.js';
|
|
98
|
+
export type { PartialOptions, PartialDefinition, Registry, PartialMetadata, PartialFactory, InferPartial, RegistryType, } from './registry.js';
|
|
99
|
+
export { generateTypeScript, generatePython, generateJsonSchema } from './codegen.js';
|
|
100
|
+
export { config } from './codegen.js';
|
|
101
|
+
export type { CodegenConfig, CodegenOutputs, CodegenOutputKind, CodegenResult } from './codegen.js';
|
|
102
|
+
/**
|
|
103
|
+
* Core WideEvent class.
|
|
104
|
+
* Create one WideEvent per request or unit of work and add partials as you go.
|
|
105
|
+
* Use log() for structured partials or for lightweight log_message entries.
|
|
106
|
+
* @param R pass in a valid Registry type, which defines the wide event partials you may pass in
|
|
107
|
+
*/
|
|
108
|
+
export declare class WideEvent<R extends RegistryShape> {
|
|
109
|
+
readonly eventId: string;
|
|
110
|
+
readonly traceId: string;
|
|
111
|
+
private collector;
|
|
112
|
+
/** All partials - singular as objects, repeatable as arrays */
|
|
113
|
+
private partials;
|
|
114
|
+
private service;
|
|
115
|
+
private originator;
|
|
116
|
+
private openSpans;
|
|
117
|
+
/** Metadata about partials (repeatable, alwaysSample) */
|
|
118
|
+
private partialMetadata;
|
|
119
|
+
/** Whether this event should always be sampled */
|
|
120
|
+
private _alwaysSample;
|
|
121
|
+
/**
|
|
122
|
+
* Create a wide event
|
|
123
|
+
*
|
|
124
|
+
* @param service Service that the wide event is being emitted on
|
|
125
|
+
* @param originator Originator (i.e. request, schedule, etc) of the wide event
|
|
126
|
+
* @param collector Location to collect/flush logs to
|
|
127
|
+
* @param options Optional configuration including traceId and partialMetadata
|
|
128
|
+
*/
|
|
129
|
+
constructor(service: Service, originator: import('./originator/index.js').Originator, collector: LogCollectorClient, options?: WideEventOptions);
|
|
130
|
+
/**
|
|
131
|
+
* Check if this event should always be sampled
|
|
132
|
+
*/
|
|
133
|
+
get alwaysSample(): boolean;
|
|
134
|
+
/**
|
|
135
|
+
* Manually mark this event to always be sampled
|
|
136
|
+
*/
|
|
137
|
+
markAlwaysSample(): void;
|
|
138
|
+
/**
|
|
139
|
+
* Add a partial to a wide event.
|
|
140
|
+
* For singular partials, this overwrites any existing partial of the same type.
|
|
141
|
+
* For repeatable partials, this appends to the array.
|
|
142
|
+
* If the partial has alwaysSample=true, the event will be marked to always be sampled.
|
|
143
|
+
* Overwriting a singular partial records a sloplog_usage_error.
|
|
144
|
+
*
|
|
145
|
+
* @param partial wide event partial to add
|
|
146
|
+
*/
|
|
147
|
+
partial(partial: RegistryEntries<R>): void;
|
|
148
|
+
/**
|
|
149
|
+
* Add a partial or log message to a wide event.
|
|
150
|
+
* log(partial) is an alias for partial(partial).
|
|
151
|
+
* log(message, data, level) creates a log_message partial.
|
|
152
|
+
* Partials are always preferred over log_message for structured data.
|
|
153
|
+
* If data is provided, it is JSON stringified (string data is passed through).
|
|
154
|
+
* If level is omitted, it defaults to "info".
|
|
155
|
+
*/
|
|
156
|
+
log(partial: RegistryEntries<R>): void;
|
|
157
|
+
log(message: string, data?: unknown, level?: LogMessageLevel): void;
|
|
158
|
+
/**
|
|
159
|
+
* Add an error partial from an Error or message.
|
|
160
|
+
*/
|
|
161
|
+
error(error: unknown, code?: number): void;
|
|
162
|
+
private formatErrorMessage;
|
|
163
|
+
/**
|
|
164
|
+
* Time a span around a callback and emit a span partial.
|
|
165
|
+
* Unended spans are recorded as sloplog_usage_error on flush.
|
|
166
|
+
*/
|
|
167
|
+
span<T>(name: string, fn: () => T | Promise<T>): Promise<T>;
|
|
168
|
+
/**
|
|
169
|
+
* Start a span by name
|
|
170
|
+
*/
|
|
171
|
+
spanStart(name: string): void;
|
|
172
|
+
/**
|
|
173
|
+
* End a span by name
|
|
174
|
+
* Ending a span that was never started records a sloplog_usage_error.
|
|
175
|
+
*/
|
|
176
|
+
spanEnd(name: string): void;
|
|
177
|
+
/**
|
|
178
|
+
* Get the current state of the wide event as a log object
|
|
179
|
+
*/
|
|
180
|
+
toLog(): WideEventLog<R>;
|
|
181
|
+
/**
|
|
182
|
+
* Emit the full wide log to the collector.
|
|
183
|
+
* Any usage errors (e.g. unended spans, partial overwrites) are emitted
|
|
184
|
+
* as sloplog_usage_error partials before flushing.
|
|
185
|
+
*/
|
|
186
|
+
flush(): Promise<void>;
|
|
187
|
+
private addPartialInternal;
|
|
188
|
+
private appendRepeatablePartial;
|
|
189
|
+
private isRepeatableFallback;
|
|
190
|
+
private isAlwaysSampleFallback;
|
|
191
|
+
private addUsageError;
|
|
192
|
+
private recordOpenSpans;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Create a WideEvent instance. Prefer this factory over class construction.
|
|
196
|
+
* Provide the registry first to infer partial types and repeatable metadata.
|
|
197
|
+
* originator can be a raw Originator or the { originator, traceId } result from httpOriginator().
|
|
198
|
+
*/
|
|
199
|
+
export declare function wideEvent<T extends AnyRegistry>(registry: T, service: Service, originator: OriginatorInput, collector: LogCollectorClient, options?: WideEventOptions): WideEvent<RegistryType<T>>;
|