vestig 0.11.5 → 0.13.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 +95 -2
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +4 -0
- package/dist/config.js.map +1 -1
- package/dist/index.d.ts +9 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -1
- package/dist/index.js.map +1 -1
- package/dist/logger.d.ts +85 -0
- package/dist/logger.d.ts.map +1 -1
- package/dist/logger.js +209 -2
- package/dist/logger.js.map +1 -1
- package/dist/metrics/index.d.ts +2 -0
- package/dist/metrics/index.d.ts.map +1 -0
- package/dist/metrics/index.js +2 -0
- package/dist/metrics/index.js.map +1 -0
- package/dist/metrics/prometheus.d.ts +109 -0
- package/dist/metrics/prometheus.d.ts.map +1 -0
- package/dist/metrics/prometheus.js +162 -0
- package/dist/metrics/prometheus.js.map +1 -0
- package/dist/sampling/index.d.ts +2 -0
- package/dist/sampling/index.d.ts.map +1 -1
- package/dist/sampling/index.js +2 -0
- package/dist/sampling/index.js.map +1 -1
- package/dist/sampling/tail.d.ts +76 -0
- package/dist/sampling/tail.d.ts.map +1 -0
- package/dist/sampling/tail.js +138 -0
- package/dist/sampling/tail.js.map +1 -0
- package/dist/transports/batch.d.ts +2 -0
- package/dist/transports/batch.d.ts.map +1 -1
- package/dist/transports/batch.js +13 -3
- package/dist/transports/batch.js.map +1 -1
- package/dist/transports/file.d.ts +14 -1
- package/dist/transports/file.d.ts.map +1 -1
- package/dist/transports/file.js +59 -4
- package/dist/transports/file.js.map +1 -1
- package/dist/transports/http.d.ts +29 -1
- package/dist/transports/http.d.ts.map +1 -1
- package/dist/transports/http.js +63 -6
- package/dist/transports/http.js.map +1 -1
- package/dist/transports/sentry.d.ts +83 -0
- package/dist/transports/sentry.d.ts.map +1 -0
- package/dist/transports/sentry.js +283 -0
- package/dist/transports/sentry.js.map +1 -0
- package/dist/types.d.ts +149 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/buffer.d.ts +33 -1
- package/dist/utils/buffer.d.ts.map +1 -1
- package/dist/utils/buffer.js +40 -2
- package/dist/utils/buffer.js.map +1 -1
- package/dist/utils/dedupe.d.ts +80 -0
- package/dist/utils/dedupe.d.ts.map +1 -0
- package/dist/utils/dedupe.js +173 -0
- package/dist/utils/dedupe.js.map +1 -0
- package/dist/utils/sanitize.d.ts +23 -1
- package/dist/utils/sanitize.d.ts.map +1 -1
- package/dist/utils/sanitize.js +113 -8
- package/dist/utils/sanitize.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/wide-events/builder.d.ts +51 -0
- package/dist/wide-events/builder.d.ts.map +1 -0
- package/dist/wide-events/builder.js +177 -0
- package/dist/wide-events/builder.js.map +1 -0
- package/dist/wide-events/context.d.ts +57 -0
- package/dist/wide-events/context.d.ts.map +1 -0
- package/dist/wide-events/context.js +148 -0
- package/dist/wide-events/context.js.map +1 -0
- package/dist/wide-events/index.d.ts +6 -0
- package/dist/wide-events/index.d.ts.map +1 -0
- package/dist/wide-events/index.js +7 -0
- package/dist/wide-events/index.js.map +1 -0
- package/dist/wide-events/schemas/http.d.ts +179 -0
- package/dist/wide-events/schemas/http.d.ts.map +1 -0
- package/dist/wide-events/schemas/http.js +25 -0
- package/dist/wide-events/schemas/http.js.map +1 -0
- package/dist/wide-events/schemas/index.d.ts +5 -0
- package/dist/wide-events/schemas/index.d.ts.map +1 -0
- package/dist/wide-events/schemas/index.js +5 -0
- package/dist/wide-events/schemas/index.js.map +1 -0
- package/dist/wide-events/schemas/job.d.ts +130 -0
- package/dist/wide-events/schemas/job.d.ts.map +1 -0
- package/dist/wide-events/schemas/job.js +27 -0
- package/dist/wide-events/schemas/job.js.map +1 -0
- package/dist/wide-events/types.d.ts +216 -0
- package/dist/wide-events/types.d.ts.map +1 -0
- package/dist/wide-events/types.js +2 -0
- package/dist/wide-events/types.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { RUNTIME } from '../runtime';
|
|
2
|
+
import { serializeError } from '../utils/error';
|
|
3
|
+
/**
|
|
4
|
+
* Get high-resolution timestamp for duration measurement
|
|
5
|
+
*/
|
|
6
|
+
function now() {
|
|
7
|
+
if (typeof performance !== 'undefined' && typeof performance.now === 'function') {
|
|
8
|
+
return performance.now();
|
|
9
|
+
}
|
|
10
|
+
return Date.now();
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Implementation of WideEventBuilder.
|
|
14
|
+
*
|
|
15
|
+
* Accumulates context throughout a request lifecycle and
|
|
16
|
+
* produces a single comprehensive event at the end.
|
|
17
|
+
*/
|
|
18
|
+
export class WideEventBuilderImpl {
|
|
19
|
+
_type;
|
|
20
|
+
_startTime;
|
|
21
|
+
_startedAt;
|
|
22
|
+
_context;
|
|
23
|
+
_fields;
|
|
24
|
+
_ended = false;
|
|
25
|
+
constructor(config) {
|
|
26
|
+
this._type = config.type;
|
|
27
|
+
this._startTime = now();
|
|
28
|
+
this._startedAt = new Date();
|
|
29
|
+
this._context = { ...config.context };
|
|
30
|
+
this._fields = config.fields ? this._deepClone(config.fields) : {};
|
|
31
|
+
}
|
|
32
|
+
get type() {
|
|
33
|
+
return this._type;
|
|
34
|
+
}
|
|
35
|
+
get startTime() {
|
|
36
|
+
return this._startTime;
|
|
37
|
+
}
|
|
38
|
+
get ended() {
|
|
39
|
+
return this._ended;
|
|
40
|
+
}
|
|
41
|
+
set(category, key, value) {
|
|
42
|
+
this._assertNotEnded();
|
|
43
|
+
if (!this._fields[category]) {
|
|
44
|
+
this._fields[category] = {};
|
|
45
|
+
}
|
|
46
|
+
this._fields[category][key] = value;
|
|
47
|
+
return this;
|
|
48
|
+
}
|
|
49
|
+
get(category, key) {
|
|
50
|
+
return this._fields[category]?.[key];
|
|
51
|
+
}
|
|
52
|
+
merge(category, fields) {
|
|
53
|
+
this._assertNotEnded();
|
|
54
|
+
if (!this._fields[category]) {
|
|
55
|
+
this._fields[category] = {};
|
|
56
|
+
}
|
|
57
|
+
Object.assign(this._fields[category], fields);
|
|
58
|
+
return this;
|
|
59
|
+
}
|
|
60
|
+
mergeAll(fields) {
|
|
61
|
+
this._assertNotEnded();
|
|
62
|
+
for (const [category, categoryFields] of Object.entries(fields)) {
|
|
63
|
+
this.merge(category, categoryFields);
|
|
64
|
+
}
|
|
65
|
+
return this;
|
|
66
|
+
}
|
|
67
|
+
setContext(context) {
|
|
68
|
+
this._assertNotEnded();
|
|
69
|
+
Object.assign(this._context, context);
|
|
70
|
+
return this;
|
|
71
|
+
}
|
|
72
|
+
getContext() {
|
|
73
|
+
return { ...this._context };
|
|
74
|
+
}
|
|
75
|
+
getFields() {
|
|
76
|
+
return this._deepClone(this._fields);
|
|
77
|
+
}
|
|
78
|
+
end(options = {}) {
|
|
79
|
+
this._assertNotEnded();
|
|
80
|
+
const endedAt = new Date();
|
|
81
|
+
const durationMs = now() - this._startTime;
|
|
82
|
+
// Merge final fields if provided (before marking as ended)
|
|
83
|
+
if (options.fields) {
|
|
84
|
+
for (const [category, categoryFields] of Object.entries(options.fields)) {
|
|
85
|
+
if (!this._fields[category]) {
|
|
86
|
+
this._fields[category] = {};
|
|
87
|
+
}
|
|
88
|
+
Object.assign(this._fields[category], categoryFields);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
// Mark as ended after all modifications
|
|
92
|
+
this._ended = true;
|
|
93
|
+
// Determine status
|
|
94
|
+
let status = options.status ?? 'success';
|
|
95
|
+
let error;
|
|
96
|
+
if (options.error) {
|
|
97
|
+
status = options.status ?? 'error';
|
|
98
|
+
error =
|
|
99
|
+
'name' in options.error && 'message' in options.error
|
|
100
|
+
? options.error
|
|
101
|
+
: serializeError(options.error);
|
|
102
|
+
}
|
|
103
|
+
// Determine log level
|
|
104
|
+
const level = options.level ?? (status === 'error' ? 'error' : 'info');
|
|
105
|
+
return {
|
|
106
|
+
started_at: this._startedAt.toISOString(),
|
|
107
|
+
ended_at: endedAt.toISOString(),
|
|
108
|
+
duration_ms: Math.round(durationMs * 100) / 100, // 2 decimal places
|
|
109
|
+
event_type: this._type,
|
|
110
|
+
status,
|
|
111
|
+
context: this._context,
|
|
112
|
+
runtime: RUNTIME,
|
|
113
|
+
fields: this._fields,
|
|
114
|
+
error,
|
|
115
|
+
level,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
toMetadata() {
|
|
119
|
+
const metadata = {
|
|
120
|
+
event_type: this._type,
|
|
121
|
+
started_at: this._startedAt.toISOString(),
|
|
122
|
+
duration_ms: Math.round((now() - this._startTime) * 100) / 100,
|
|
123
|
+
};
|
|
124
|
+
// Flatten context
|
|
125
|
+
for (const [key, value] of Object.entries(this._context)) {
|
|
126
|
+
if (value !== undefined) {
|
|
127
|
+
metadata[`context.${key}`] = value;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
// Flatten fields with category prefix
|
|
131
|
+
for (const [category, categoryFields] of Object.entries(this._fields)) {
|
|
132
|
+
for (const [key, value] of Object.entries(categoryFields)) {
|
|
133
|
+
metadata[`${category}.${key}`] = value;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return metadata;
|
|
137
|
+
}
|
|
138
|
+
_assertNotEnded() {
|
|
139
|
+
if (this._ended) {
|
|
140
|
+
throw new Error('[vestig] Cannot modify wide event after end() has been called');
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
_deepClone(obj) {
|
|
144
|
+
const result = {};
|
|
145
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
146
|
+
if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
|
|
147
|
+
result[key] = this._deepClone(value);
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
result[key] = value;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return result;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Create a new wide event builder.
|
|
158
|
+
*
|
|
159
|
+
* @param config - Event configuration (type is required)
|
|
160
|
+
* @returns A new WideEventBuilder instance
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* ```typescript
|
|
164
|
+
* const event = createWideEvent({ type: 'http.request' });
|
|
165
|
+
*
|
|
166
|
+
* event.set('http', 'method', 'POST');
|
|
167
|
+
* event.set('http', 'path', '/api/checkout');
|
|
168
|
+
* event.set('user', 'id', userId);
|
|
169
|
+
*
|
|
170
|
+
* const wideEvent = event.end({ status: 'success' });
|
|
171
|
+
* logger.info('Request completed', wideEvent);
|
|
172
|
+
* ```
|
|
173
|
+
*/
|
|
174
|
+
export function createWideEvent(config) {
|
|
175
|
+
return new WideEventBuilderImpl(config);
|
|
176
|
+
}
|
|
177
|
+
//# sourceMappingURL=builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builder.js","sourceRoot":"","sources":["../../src/wide-events/builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAEpC,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAW/C;;GAEG;AACH,SAAS,GAAG;IACX,IAAI,OAAO,WAAW,KAAK,WAAW,IAAI,OAAO,WAAW,CAAC,GAAG,KAAK,UAAU,EAAE,CAAC;QACjF,OAAO,WAAW,CAAC,GAAG,EAAE,CAAA;IACzB,CAAC;IACD,OAAO,IAAI,CAAC,GAAG,EAAE,CAAA;AAClB,CAAC;AAED;;;;;GAKG;AACH,MAAM,OAAO,oBAAoB;IACf,KAAK,CAAQ;IACb,UAAU,CAAQ;IAClB,UAAU,CAAM;IACzB,QAAQ,CAAkB;IAC1B,OAAO,CAAiB;IACxB,MAAM,GAAG,KAAK,CAAA;IAEtB,YAAY,MAAuB;QAClC,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,IAAI,CAAA;QACxB,IAAI,CAAC,UAAU,GAAG,GAAG,EAAE,CAAA;QACvB,IAAI,CAAC,UAAU,GAAG,IAAI,IAAI,E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,CAAC;QACF,CAAC;QACD,OAAO,MAAW,CAAA;IACnB,CAAC;CACD;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,eAAe,CAAC,MAAuB;IACtD,OAAO,IAAI,oBAAoB,CAAC,MAAM,CAAC,CAAA;AACxC,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { WideEventBuilder } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Get the active wide event builder from the current async context.
|
|
4
|
+
*
|
|
5
|
+
* @returns The active WideEventBuilder or undefined if not in a wide event context
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* // In a route handler or middleware
|
|
10
|
+
* const event = getActiveWideEvent();
|
|
11
|
+
* if (event) {
|
|
12
|
+
* event.set('user', 'id', userId);
|
|
13
|
+
* }
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export declare function getActiveWideEvent(): WideEventBuilder | undefined;
|
|
17
|
+
/**
|
|
18
|
+
* Run a function with the given wide event in context.
|
|
19
|
+
*
|
|
20
|
+
* The event will be accessible via getActiveWideEvent() within
|
|
21
|
+
* the function and all async operations it spawns.
|
|
22
|
+
*
|
|
23
|
+
* @param event - The wide event builder to set as active
|
|
24
|
+
* @param fn - Function to execute with the event in context
|
|
25
|
+
* @returns The result of the function
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* const event = createWideEvent({ type: 'http.request' });
|
|
30
|
+
* withWideEvent(event, () => {
|
|
31
|
+
* // Event is accessible anywhere in this call stack
|
|
32
|
+
* handleRequest();
|
|
33
|
+
* });
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare function withWideEvent<T>(event: WideEventBuilder, fn: () => T): T;
|
|
37
|
+
/**
|
|
38
|
+
* Run an async function with the given wide event in context.
|
|
39
|
+
*
|
|
40
|
+
* The event will be accessible via getActiveWideEvent() within
|
|
41
|
+
* the async function and all operations it awaits.
|
|
42
|
+
*
|
|
43
|
+
* @param event - The wide event builder to set as active
|
|
44
|
+
* @param fn - Async function to execute with the event in context
|
|
45
|
+
* @returns Promise resolving to the function result
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* const event = createWideEvent({ type: 'http.request' });
|
|
50
|
+
* await withWideEventAsync(event, async () => {
|
|
51
|
+
* await fetchUser(); // Event accessible in fetchUser
|
|
52
|
+
* await processOrder(); // Event accessible in processOrder
|
|
53
|
+
* });
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
export declare function withWideEventAsync<T>(event: WideEventBuilder, fn: () => Promise<T>): Promise<T>;
|
|
57
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/wide-events/context.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAmH/C;;;;;;;;;;;;;GAaG;AACH,wBAAgB,kBAAkB,IAAI,gBAAgB,GAAG,SAAS,CAEjE;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,KAAK,EAAE,gBAAgB,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAExE;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,KAAK,EAAE,gBAAgB,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAE/F"}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { CAPABILITIES, IS_SERVER } from '../runtime';
|
|
2
|
+
/**
|
|
3
|
+
* Global context manager for environments without AsyncLocalStorage
|
|
4
|
+
*/
|
|
5
|
+
class GlobalWideEventContextManager {
|
|
6
|
+
static instance;
|
|
7
|
+
currentEvent;
|
|
8
|
+
eventStack = [];
|
|
9
|
+
constructor() { }
|
|
10
|
+
static getInstance() {
|
|
11
|
+
if (!GlobalWideEventContextManager.instance) {
|
|
12
|
+
GlobalWideEventContextManager.instance = new GlobalWideEventContextManager();
|
|
13
|
+
}
|
|
14
|
+
return GlobalWideEventContextManager.instance;
|
|
15
|
+
}
|
|
16
|
+
get() {
|
|
17
|
+
return this.currentEvent;
|
|
18
|
+
}
|
|
19
|
+
run(event, fn) {
|
|
20
|
+
const previousEvent = this.currentEvent;
|
|
21
|
+
this.currentEvent = event;
|
|
22
|
+
this.eventStack.push(event);
|
|
23
|
+
try {
|
|
24
|
+
return fn();
|
|
25
|
+
}
|
|
26
|
+
finally {
|
|
27
|
+
this.eventStack.pop();
|
|
28
|
+
this.currentEvent = previousEvent;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
runAsync(event, fn) {
|
|
32
|
+
const previousEvent = this.currentEvent;
|
|
33
|
+
this.currentEvent = event;
|
|
34
|
+
this.eventStack.push(event);
|
|
35
|
+
return fn().finally(() => {
|
|
36
|
+
this.eventStack.pop();
|
|
37
|
+
this.currentEvent = previousEvent;
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* AsyncLocalStorage context manager for Node.js/Bun/Deno
|
|
43
|
+
*/
|
|
44
|
+
class AsyncLocalStorageWideEventContextManager {
|
|
45
|
+
storage = null;
|
|
46
|
+
constructor() {
|
|
47
|
+
if (IS_SERVER && CAPABILITIES.hasAsyncLocalStorage) {
|
|
48
|
+
try {
|
|
49
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
50
|
+
const asyncHooks = require('node:async_hooks');
|
|
51
|
+
this.storage = new asyncHooks.AsyncLocalStorage();
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
// Fallback handled by get()
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
get() {
|
|
59
|
+
return this.storage?.getStore();
|
|
60
|
+
}
|
|
61
|
+
run(event, fn) {
|
|
62
|
+
if (!this.storage) {
|
|
63
|
+
return GlobalWideEventContextManager.getInstance().run(event, fn);
|
|
64
|
+
}
|
|
65
|
+
return this.storage.run(event, fn);
|
|
66
|
+
}
|
|
67
|
+
runAsync(event, fn) {
|
|
68
|
+
if (!this.storage) {
|
|
69
|
+
return GlobalWideEventContextManager.getInstance().runAsync(event, fn);
|
|
70
|
+
}
|
|
71
|
+
return this.storage.run(event, fn);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Create the appropriate context manager for the current runtime
|
|
76
|
+
*/
|
|
77
|
+
function createWideEventContextManager() {
|
|
78
|
+
if (IS_SERVER && CAPABILITIES.hasAsyncLocalStorage) {
|
|
79
|
+
return new AsyncLocalStorageWideEventContextManager();
|
|
80
|
+
}
|
|
81
|
+
return GlobalWideEventContextManager.getInstance();
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Global wide event context manager instance
|
|
85
|
+
*/
|
|
86
|
+
const wideEventContextManager = createWideEventContextManager();
|
|
87
|
+
/**
|
|
88
|
+
* Get the active wide event builder from the current async context.
|
|
89
|
+
*
|
|
90
|
+
* @returns The active WideEventBuilder or undefined if not in a wide event context
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```typescript
|
|
94
|
+
* // In a route handler or middleware
|
|
95
|
+
* const event = getActiveWideEvent();
|
|
96
|
+
* if (event) {
|
|
97
|
+
* event.set('user', 'id', userId);
|
|
98
|
+
* }
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
export function getActiveWideEvent() {
|
|
102
|
+
return wideEventContextManager.get();
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Run a function with the given wide event in context.
|
|
106
|
+
*
|
|
107
|
+
* The event will be accessible via getActiveWideEvent() within
|
|
108
|
+
* the function and all async operations it spawns.
|
|
109
|
+
*
|
|
110
|
+
* @param event - The wide event builder to set as active
|
|
111
|
+
* @param fn - Function to execute with the event in context
|
|
112
|
+
* @returns The result of the function
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* ```typescript
|
|
116
|
+
* const event = createWideEvent({ type: 'http.request' });
|
|
117
|
+
* withWideEvent(event, () => {
|
|
118
|
+
* // Event is accessible anywhere in this call stack
|
|
119
|
+
* handleRequest();
|
|
120
|
+
* });
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
export function withWideEvent(event, fn) {
|
|
124
|
+
return wideEventContextManager.run(event, fn);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Run an async function with the given wide event in context.
|
|
128
|
+
*
|
|
129
|
+
* The event will be accessible via getActiveWideEvent() within
|
|
130
|
+
* the async function and all operations it awaits.
|
|
131
|
+
*
|
|
132
|
+
* @param event - The wide event builder to set as active
|
|
133
|
+
* @param fn - Async function to execute with the event in context
|
|
134
|
+
* @returns Promise resolving to the function result
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```typescript
|
|
138
|
+
* const event = createWideEvent({ type: 'http.request' });
|
|
139
|
+
* await withWideEventAsync(event, async () => {
|
|
140
|
+
* await fetchUser(); // Event accessible in fetchUser
|
|
141
|
+
* await processOrder(); // Event accessible in processOrder
|
|
142
|
+
* });
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
export function withWideEventAsync(event, fn) {
|
|
146
|
+
return wideEventContextManager.runAsync(event, fn);
|
|
147
|
+
}
|
|
148
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/wide-events/context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAYpD;;GAEG;AACH,MAAM,6BAA6B;IAC1B,MAAM,CAAC,QAAQ,CAA+B;IAC9C,YAAY,CAA8B;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AAU,aAAa,CAAI,KAAuB,EAAE,EAAW;IACpE,OAAO,uBAAuB,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,CAAC,CAAA;AAC9C,CAAC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,kBAAkB,CAAI,KAAuB,EAAE,EAAoB;IAClF,OAAO,uBAAuB,CAAC,QAAQ,CAAC,KAAK,EAAE,EAAE,CAAC,CAAA;AACnD,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { createWideEvent, WideEventBuilderImpl } from './builder';
|
|
2
|
+
export { getActiveWideEvent, withWideEvent, withWideEventAsync } from './context';
|
|
3
|
+
export type { TailSamplingConfig, WideEvent, WideEventBuilder, WideEventConfig, WideEventContext, WideEventEndOptions, WideEventFields, WideEventStatus, } from './types';
|
|
4
|
+
export { httpFields, HTTP_EVENT_TYPES, jobFields, JOB_EVENT_TYPES, } from './schemas';
|
|
5
|
+
export type { HttpFields, UserFields, PerformanceFields, ErrorFields, ServiceFields, FeatureFlagFields, HttpRequestEventFields, JobFields, JobDataFields, JobPerformanceFields, JobErrorFields, BackgroundJobEventFields, } from './schemas';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/wide-events/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAA;AAGjE,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAA;AAGjF,YAAY,EACX,kBAAkB,EAClB,SAAS,EACT,gBAAgB,EAChB,eAAe,EACf,gBAAgB,EAChB,mBAAmB,EACnB,eAAe,EACf,eAAe,GACf,MAAM,SAAS,CAAA;AAGhB,OAAO,EACN,UAAU,EACV,gBAAgB,EAChB,SAAS,EACT,eAAe,GACf,MAAM,WAAW,CAAA;AAClB,YAAY,EACX,UAAU,EACV,UAAU,EACV,iBAAiB,EACjB,WAAW,EACX,aAAa,EACb,iBAAiB,EACjB,sBAAsB,EACtB,SAAS,EACT,aAAa,EACb,oBAAoB,EACpB,cAAc,EACd,wBAAwB,GACxB,MAAM,WAAW,CAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// Builder
|
|
2
|
+
export { createWideEvent, WideEventBuilderImpl } from './builder';
|
|
3
|
+
// Context
|
|
4
|
+
export { getActiveWideEvent, withWideEvent, withWideEventAsync } from './context';
|
|
5
|
+
// Schemas
|
|
6
|
+
export { httpFields, HTTP_EVENT_TYPES, jobFields, JOB_EVENT_TYPES, } from './schemas';
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/wide-events/index.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAA;AAEjE,UAAU;AACV,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAA;AAcjF,UAAU;AACV,OAAO,EACN,UAAU,EACV,gBAAgB,EAChB,SAAS,EACT,eAAe,GACf,MAAM,WAAW,CAAA"}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP request fields for wide events.
|
|
3
|
+
*
|
|
4
|
+
* These fields capture standard HTTP request/response information
|
|
5
|
+
* that is commonly needed for debugging and observability.
|
|
6
|
+
*/
|
|
7
|
+
export interface HttpFields {
|
|
8
|
+
/** HTTP method (GET, POST, PUT, DELETE, etc.) */
|
|
9
|
+
method?: string;
|
|
10
|
+
/** Request path (e.g., /api/v1/users) */
|
|
11
|
+
path?: string;
|
|
12
|
+
/** Full URL if needed */
|
|
13
|
+
url?: string;
|
|
14
|
+
/** HTTP status code */
|
|
15
|
+
status_code?: number;
|
|
16
|
+
/** Request protocol (http, https) */
|
|
17
|
+
protocol?: string;
|
|
18
|
+
/** HTTP version (1.1, 2, 3) */
|
|
19
|
+
http_version?: string;
|
|
20
|
+
/** Request body size in bytes */
|
|
21
|
+
request_size_bytes?: number;
|
|
22
|
+
/** Response body size in bytes */
|
|
23
|
+
response_size_bytes?: number;
|
|
24
|
+
/** Content-Type of the request */
|
|
25
|
+
request_content_type?: string;
|
|
26
|
+
/** Content-Type of the response */
|
|
27
|
+
response_content_type?: string;
|
|
28
|
+
/** Query string (without leading ?) */
|
|
29
|
+
query_string?: string;
|
|
30
|
+
/** Route pattern (e.g., /api/users/:id) */
|
|
31
|
+
route?: string;
|
|
32
|
+
/** User-Agent header */
|
|
33
|
+
user_agent?: string;
|
|
34
|
+
/** Referer header */
|
|
35
|
+
referer?: string;
|
|
36
|
+
/** Client IP address */
|
|
37
|
+
client_ip?: string;
|
|
38
|
+
/** Forwarded-For header (if behind proxy) */
|
|
39
|
+
forwarded_for?: string;
|
|
40
|
+
/** Host header */
|
|
41
|
+
host?: string;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* User context fields for wide events.
|
|
45
|
+
*/
|
|
46
|
+
export interface UserFields {
|
|
47
|
+
/** User identifier */
|
|
48
|
+
id?: string;
|
|
49
|
+
/** User email (consider sanitization) */
|
|
50
|
+
email?: string;
|
|
51
|
+
/** Username or display name */
|
|
52
|
+
name?: string;
|
|
53
|
+
/** Subscription tier (free, pro, enterprise, etc.) */
|
|
54
|
+
subscription?: string;
|
|
55
|
+
/** Account age in days */
|
|
56
|
+
account_age_days?: number;
|
|
57
|
+
/** Lifetime value in cents */
|
|
58
|
+
lifetime_value_cents?: number;
|
|
59
|
+
/** Organization/team ID */
|
|
60
|
+
organization_id?: string;
|
|
61
|
+
/** User role */
|
|
62
|
+
role?: string;
|
|
63
|
+
/** Session identifier */
|
|
64
|
+
session_id?: string;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Performance metrics fields for wide events.
|
|
68
|
+
*/
|
|
69
|
+
export interface PerformanceFields {
|
|
70
|
+
/** Total request duration in ms */
|
|
71
|
+
duration_ms?: number;
|
|
72
|
+
/** Number of database queries executed */
|
|
73
|
+
db_query_count?: number;
|
|
74
|
+
/** Total database query time in ms */
|
|
75
|
+
db_query_time_ms?: number;
|
|
76
|
+
/** Number of cache hits */
|
|
77
|
+
cache_hits?: number;
|
|
78
|
+
/** Number of cache misses */
|
|
79
|
+
cache_misses?: number;
|
|
80
|
+
/** Number of external API calls */
|
|
81
|
+
external_call_count?: number;
|
|
82
|
+
/** Total external API call time in ms */
|
|
83
|
+
external_call_time_ms?: number;
|
|
84
|
+
/** Memory used in bytes */
|
|
85
|
+
memory_used_bytes?: number;
|
|
86
|
+
/** CPU time in ms */
|
|
87
|
+
cpu_time_ms?: number;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Error fields for wide events.
|
|
91
|
+
*/
|
|
92
|
+
export interface ErrorFields {
|
|
93
|
+
/** Error type/class name */
|
|
94
|
+
type?: string;
|
|
95
|
+
/** Error code */
|
|
96
|
+
code?: string | number;
|
|
97
|
+
/** Error message */
|
|
98
|
+
message?: string;
|
|
99
|
+
/** Whether the error is retryable */
|
|
100
|
+
retriable?: boolean;
|
|
101
|
+
/** Provider-specific error code (e.g., Stripe decline code) */
|
|
102
|
+
provider_code?: string;
|
|
103
|
+
/** Number of retry attempts */
|
|
104
|
+
retry_count?: number;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Service/infrastructure fields for wide events.
|
|
108
|
+
*/
|
|
109
|
+
export interface ServiceFields {
|
|
110
|
+
/** Service name */
|
|
111
|
+
name?: string;
|
|
112
|
+
/** Service version */
|
|
113
|
+
version?: string;
|
|
114
|
+
/** Deployment/release identifier */
|
|
115
|
+
deployment_id?: string;
|
|
116
|
+
/** Git commit SHA */
|
|
117
|
+
git_sha?: string;
|
|
118
|
+
/** Cloud region */
|
|
119
|
+
region?: string;
|
|
120
|
+
/** Availability zone */
|
|
121
|
+
availability_zone?: string;
|
|
122
|
+
/** Host/container name */
|
|
123
|
+
host?: string;
|
|
124
|
+
/** Kubernetes namespace */
|
|
125
|
+
k8s_namespace?: string;
|
|
126
|
+
/** Kubernetes pod name */
|
|
127
|
+
k8s_pod?: string;
|
|
128
|
+
/** Environment (production, staging, development) */
|
|
129
|
+
environment?: string;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Feature flag fields for wide events.
|
|
133
|
+
*/
|
|
134
|
+
export interface FeatureFlagFields {
|
|
135
|
+
/** Map of feature flag name to enabled status */
|
|
136
|
+
[flagName: string]: boolean | string | number | undefined;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Complete HTTP request event fields structure.
|
|
140
|
+
*
|
|
141
|
+
* This interface represents all the categories of fields
|
|
142
|
+
* typically captured for an HTTP request wide event.
|
|
143
|
+
*
|
|
144
|
+
* Note: Fields are typed as Record<string, unknown> for compatibility
|
|
145
|
+
* with WideEventFields, but the individual field interfaces above
|
|
146
|
+
* provide documentation for expected field names and types.
|
|
147
|
+
*/
|
|
148
|
+
export interface HttpRequestEventFields {
|
|
149
|
+
http?: Record<string, unknown>;
|
|
150
|
+
user?: Record<string, unknown>;
|
|
151
|
+
performance?: Record<string, unknown>;
|
|
152
|
+
error?: Record<string, unknown>;
|
|
153
|
+
service?: Record<string, unknown>;
|
|
154
|
+
feature_flags?: Record<string, unknown>;
|
|
155
|
+
[category: string]: Record<string, unknown> | undefined;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Helper to create typed HTTP request fields.
|
|
159
|
+
*
|
|
160
|
+
* @example
|
|
161
|
+
* ```typescript
|
|
162
|
+
* const event = createWideEvent({ type: 'http.request' });
|
|
163
|
+
* event.mergeAll(httpFields({
|
|
164
|
+
* http: { method: 'POST', path: '/api/checkout', status_code: 200 },
|
|
165
|
+
* user: { id: 'user-123', subscription: 'premium' },
|
|
166
|
+
* performance: { db_query_count: 3, cache_hits: 2 }
|
|
167
|
+
* }));
|
|
168
|
+
* ```
|
|
169
|
+
*/
|
|
170
|
+
export declare function httpFields(fields: Partial<HttpRequestEventFields>): HttpRequestEventFields;
|
|
171
|
+
/**
|
|
172
|
+
* Common HTTP event type constants.
|
|
173
|
+
*/
|
|
174
|
+
export declare const HTTP_EVENT_TYPES: {
|
|
175
|
+
readonly REQUEST: "http.request";
|
|
176
|
+
readonly RESPONSE: "http.response";
|
|
177
|
+
readonly ERROR: "http.error";
|
|
178
|
+
};
|
|
179
|
+
//# sourceMappingURL=http.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../src/wide-events/schemas/http.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,WAAW,UAAU;IAC1B,iDAAiD;IACjD,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,yCAAyC;IACzC,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,yBAAyB;IACzB,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,uBAAuB;IACvB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,qCAAqC;IACrC,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,+BAA+B;IAC/B,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,iCAAiC;IACjC,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,kCAAkC;IAClC,mBAAmB,CAAC,EAAE,MAAM,CAAA;IAC5B,kCAAkC;IAClC,oBAAoB,CAAC,EAAE,MAAM,CAAA;IAC7B,mCAAmC;IACnC,qBAAqB,CAAC,EAAE,MAAM,CAAA;IAC9B,uCAAuC;IACvC,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,2CAA2C;IAC3C,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,wBAAwB;IACxB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,qBAAqB;IACrB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,w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AAA;IACrC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC/B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACjC,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACvC,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAA;CACvD;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,OAAO,CAAC,sBAAsB,CAAC,GAAG,sBAAsB,CAE1F;AAED;;GAEG;AACH,eAAO,MAAM,gBAAgB;;;;CAInB,CAAA"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helper to create typed HTTP request fields.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```typescript
|
|
6
|
+
* const event = createWideEvent({ type: 'http.request' });
|
|
7
|
+
* event.mergeAll(httpFields({
|
|
8
|
+
* http: { method: 'POST', path: '/api/checkout', status_code: 200 },
|
|
9
|
+
* user: { id: 'user-123', subscription: 'premium' },
|
|
10
|
+
* performance: { db_query_count: 3, cache_hits: 2 }
|
|
11
|
+
* }));
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export function httpFields(fields) {
|
|
15
|
+
return fields;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Common HTTP event type constants.
|
|
19
|
+
*/
|
|
20
|
+
export const HTTP_EVENT_TYPES = {
|
|
21
|
+
REQUEST: 'http.request',
|
|
22
|
+
RESPONSE: 'http.response',
|
|
23
|
+
ERROR: 'http.error',
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=http.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../../src/wide-events/schemas/http.ts"],"names":[],"mappings":"AAmKA;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,UAAU,CAAC,MAAuC;IACjE,OAAO,MAAgC,CAAA;AACxC,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC/B,OAAO,EAAE,cAAc;IACvB,QAAQ,EAAE,eAAe;IACzB,KAAK,EAAE,YAAY;CACV,CAAA"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { httpFields, HTTP_EVENT_TYPES, } from './http';
|
|
2
|
+
export type { HttpFields, UserFields, PerformanceFields, ErrorFields, ServiceFields, FeatureFlagFields, HttpRequestEventFields, } from './http';
|
|
3
|
+
export { jobFields, JOB_EVENT_TYPES, } from './job';
|
|
4
|
+
export type { JobFields, JobDataFields, JobPerformanceFields, JobErrorFields, BackgroundJobEventFields, } from './job';
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/wide-events/schemas/index.ts"],"names":[],"mappings":"AACA,OAAO,EACN,UAAU,EACV,gBAAgB,GAChB,MAAM,QAAQ,CAAA;AACf,YAAY,EACX,UAAU,EACV,UAAU,EACV,iBAAiB,EACjB,WAAW,EACX,aAAa,EACb,iBAAiB,EACjB,sBAAsB,GACtB,MAAM,QAAQ,CAAA;AAGf,OAAO,EACN,SAAS,EACT,eAAe,GACf,MAAM,OAAO,CAAA;AACd,YAAY,EACX,SAAS,EACT,aAAa,EACb,oBAAoB,EACpB,cAAc,EACd,wBAAwB,GACxB,MAAM,OAAO,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/wide-events/schemas/index.ts"],"names":[],"mappings":"AAAA,4BAA4B;AAC5B,OAAO,EACN,UAAU,EACV,gBAAgB,GAChB,MAAM,QAAQ,CAAA;AAWf,8BAA8B;AAC9B,OAAO,EACN,SAAS,EACT,eAAe,GACf,MAAM,OAAO,CAAA"}
|