@vestig/next 0.16.0 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/instrumentation/index.d.ts +24 -0
- package/dist/instrumentation/index.d.ts.map +1 -0
- package/dist/instrumentation/index.js +23 -0
- package/dist/instrumentation/index.js.map +1 -0
- package/dist/instrumentation/register.d.ts +79 -0
- package/dist/instrumentation/register.d.ts.map +1 -0
- package/dist/instrumentation/register.js +251 -0
- package/dist/instrumentation/register.js.map +1 -0
- package/dist/instrumentation/types.d.ts +112 -0
- package/dist/instrumentation/types.d.ts.map +1 -0
- package/dist/instrumentation/types.js +5 -0
- package/dist/instrumentation/types.js.map +1 -0
- package/package.json +10 -3
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Next.js Instrumentation for vestig
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```typescript
|
|
6
|
+
* // instrumentation.ts
|
|
7
|
+
* import { registerVestig } from '@vestig/next/instrumentation'
|
|
8
|
+
*
|
|
9
|
+
* export function register() {
|
|
10
|
+
* registerVestig({
|
|
11
|
+
* serviceName: 'my-app',
|
|
12
|
+
* otlp: {
|
|
13
|
+
* endpoint: process.env.OTEL_EXPORTER_OTLP_ENDPOINT,
|
|
14
|
+
* },
|
|
15
|
+
* autoInstrument: {
|
|
16
|
+
* fetch: true,
|
|
17
|
+
* },
|
|
18
|
+
* })
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export { registerVestig } from './register';
|
|
23
|
+
export type { RegisterVestigOptions, RegisterVestigResult, OTLPConfig, AutoInstrumentConfig, } from './types';
|
|
24
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/instrumentation/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAC3C,YAAY,EACX,qBAAqB,EACrB,oBAAoB,EACpB,UAAU,EACV,oBAAoB,GACpB,MAAM,SAAS,CAAA"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Next.js Instrumentation for vestig
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```typescript
|
|
6
|
+
* // instrumentation.ts
|
|
7
|
+
* import { registerVestig } from '@vestig/next/instrumentation'
|
|
8
|
+
*
|
|
9
|
+
* export function register() {
|
|
10
|
+
* registerVestig({
|
|
11
|
+
* serviceName: 'my-app',
|
|
12
|
+
* otlp: {
|
|
13
|
+
* endpoint: process.env.OTEL_EXPORTER_OTLP_ENDPOINT,
|
|
14
|
+
* },
|
|
15
|
+
* autoInstrument: {
|
|
16
|
+
* fetch: true,
|
|
17
|
+
* },
|
|
18
|
+
* })
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export { registerVestig } from './register';
|
|
23
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/instrumentation/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unified vestig setup for Next.js instrumentation
|
|
3
|
+
*
|
|
4
|
+
* Call in your instrumentation.ts file for complete auto-instrumentation.
|
|
5
|
+
*/
|
|
6
|
+
import type { RegisterVestigOptions, RegisterVestigResult } from './types';
|
|
7
|
+
/**
|
|
8
|
+
* Register vestig for Next.js instrumentation
|
|
9
|
+
*
|
|
10
|
+
* Call this in your `instrumentation.ts` file to enable:
|
|
11
|
+
* - OTLP trace export (Vercel, Honeycomb, Jaeger, etc.)
|
|
12
|
+
* - Automatic fetch() instrumentation
|
|
13
|
+
* - Console error capture (optional)
|
|
14
|
+
*
|
|
15
|
+
* @example Basic usage
|
|
16
|
+
* ```typescript
|
|
17
|
+
* // instrumentation.ts
|
|
18
|
+
* import { registerVestig } from '@vestig/next/instrumentation'
|
|
19
|
+
*
|
|
20
|
+
* export function register() {
|
|
21
|
+
* registerVestig({
|
|
22
|
+
* serviceName: 'my-app',
|
|
23
|
+
* })
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @example With OTLP export
|
|
28
|
+
* ```typescript
|
|
29
|
+
* // instrumentation.ts
|
|
30
|
+
* import { registerVestig } from '@vestig/next/instrumentation'
|
|
31
|
+
*
|
|
32
|
+
* export function register() {
|
|
33
|
+
* registerVestig({
|
|
34
|
+
* serviceName: 'my-app',
|
|
35
|
+
* otlp: {
|
|
36
|
+
* endpoint: process.env.OTEL_EXPORTER_OTLP_ENDPOINT,
|
|
37
|
+
* headers: {
|
|
38
|
+
* 'Authorization': `Bearer ${process.env.OTEL_AUTH_TOKEN}`,
|
|
39
|
+
* },
|
|
40
|
+
* },
|
|
41
|
+
* })
|
|
42
|
+
* }
|
|
43
|
+
* ```
|
|
44
|
+
*
|
|
45
|
+
* @example Full configuration
|
|
46
|
+
* ```typescript
|
|
47
|
+
* // instrumentation.ts
|
|
48
|
+
* import { registerVestig } from '@vestig/next/instrumentation'
|
|
49
|
+
*
|
|
50
|
+
* export function register() {
|
|
51
|
+
* registerVestig({
|
|
52
|
+
* serviceName: 'my-app',
|
|
53
|
+
* otlp: {
|
|
54
|
+
* endpoint: process.env.OTEL_EXPORTER_OTLP_ENDPOINT,
|
|
55
|
+
* serviceVersion: '1.0.0',
|
|
56
|
+
* environment: process.env.VERCEL_ENV,
|
|
57
|
+
* },
|
|
58
|
+
* autoInstrument: {
|
|
59
|
+
* fetch: {
|
|
60
|
+
* captureHeaders: ['content-type', 'x-request-id'],
|
|
61
|
+
* ignoreUrls: ['/health', /^\/_next/],
|
|
62
|
+
* },
|
|
63
|
+
* console: true,
|
|
64
|
+
* },
|
|
65
|
+
* debug: process.env.NODE_ENV === 'development',
|
|
66
|
+
* })
|
|
67
|
+
* }
|
|
68
|
+
* ```
|
|
69
|
+
*
|
|
70
|
+
* @example Environment variables
|
|
71
|
+
* ```bash
|
|
72
|
+
* # These are automatically read if not specified in config:
|
|
73
|
+
* OTEL_EXPORTER_OTLP_ENDPOINT=https://otel.vercel.com/v1/traces
|
|
74
|
+
* OTEL_EXPORTER_OTLP_HEADERS=Authorization=Bearer token
|
|
75
|
+
* VERCEL_ENV=production
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
export declare function registerVestig(options: RegisterVestigOptions): RegisterVestigResult;
|
|
79
|
+
//# sourceMappingURL=register.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../../src/instrumentation/register.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AASH,OAAO,KAAK,EAGX,qBAAqB,EACrB,oBAAoB,EACpB,MAAM,SAAS,CAAA;AAsKhB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsEG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,qBAAqB,GAAG,oBAAoB,CA4CnF"}
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unified vestig setup for Next.js instrumentation
|
|
3
|
+
*
|
|
4
|
+
* Call in your instrumentation.ts file for complete auto-instrumentation.
|
|
5
|
+
*/
|
|
6
|
+
import { instrumentFetch, registerSpanProcessor, shutdownSpanProcessors, } from 'vestig';
|
|
7
|
+
import { OTLPExporter } from 'vestig/otlp';
|
|
8
|
+
/**
|
|
9
|
+
* Parse OTEL headers from environment variable
|
|
10
|
+
* Format: key1=value1,key2=value2
|
|
11
|
+
*/
|
|
12
|
+
function parseOTLPHeaders(headersStr) {
|
|
13
|
+
if (!headersStr)
|
|
14
|
+
return {};
|
|
15
|
+
const headers = {};
|
|
16
|
+
const pairs = headersStr.split(',');
|
|
17
|
+
for (const pair of pairs) {
|
|
18
|
+
const [key, ...valueParts] = pair.split('=');
|
|
19
|
+
if (key && valueParts.length > 0) {
|
|
20
|
+
headers[key.trim()] = valueParts.join('=').trim();
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return headers;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Get environment from various sources
|
|
27
|
+
*/
|
|
28
|
+
function getEnvironment(config) {
|
|
29
|
+
return config?.environment ?? process.env.VERCEL_ENV ?? process.env.NODE_ENV ?? 'development';
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Setup OTLP export if configured
|
|
33
|
+
*/
|
|
34
|
+
function setupOTLP(serviceName, config, debug) {
|
|
35
|
+
// Get endpoint from config or environment
|
|
36
|
+
const endpoint = config?.endpoint ?? process.env.OTEL_EXPORTER_OTLP_ENDPOINT;
|
|
37
|
+
if (!endpoint) {
|
|
38
|
+
if (debug) {
|
|
39
|
+
console.log('[vestig] OTLP not configured: no endpoint provided');
|
|
40
|
+
}
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
// Ensure endpoint has /v1/traces suffix
|
|
44
|
+
const tracesEndpoint = endpoint.endsWith('/v1/traces')
|
|
45
|
+
? endpoint
|
|
46
|
+
: `${endpoint.replace(/\/$/, '')}/v1/traces`;
|
|
47
|
+
// Get headers from config or environment
|
|
48
|
+
const headers = {
|
|
49
|
+
...parseOTLPHeaders(process.env.OTEL_EXPORTER_OTLP_HEADERS),
|
|
50
|
+
...config?.headers,
|
|
51
|
+
};
|
|
52
|
+
// Create and register exporter
|
|
53
|
+
const exporter = new OTLPExporter({
|
|
54
|
+
endpoint: tracesEndpoint,
|
|
55
|
+
serviceName,
|
|
56
|
+
serviceVersion: config?.serviceVersion,
|
|
57
|
+
environment: getEnvironment(config),
|
|
58
|
+
headers: Object.keys(headers).length > 0 ? headers : undefined,
|
|
59
|
+
resourceAttributes: config?.resourceAttributes,
|
|
60
|
+
batchSize: config?.batchSize,
|
|
61
|
+
flushInterval: config?.flushInterval,
|
|
62
|
+
});
|
|
63
|
+
registerSpanProcessor(exporter);
|
|
64
|
+
if (debug) {
|
|
65
|
+
console.log(`[vestig] OTLP enabled: ${tracesEndpoint}`);
|
|
66
|
+
}
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Setup fetch instrumentation if configured
|
|
71
|
+
*/
|
|
72
|
+
function setupFetch(config, debug) {
|
|
73
|
+
// Default to enabled unless explicitly disabled
|
|
74
|
+
const fetchConfig = config?.fetch;
|
|
75
|
+
if (fetchConfig === false) {
|
|
76
|
+
if (debug) {
|
|
77
|
+
console.log('[vestig] Fetch instrumentation disabled');
|
|
78
|
+
}
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
// Determine options
|
|
82
|
+
const options = typeof fetchConfig === 'object'
|
|
83
|
+
? fetchConfig
|
|
84
|
+
: {
|
|
85
|
+
// Default options for Next.js
|
|
86
|
+
ignoreUrls: [
|
|
87
|
+
// Next.js internal routes
|
|
88
|
+
/^\/_next/,
|
|
89
|
+
// Health checks
|
|
90
|
+
'/health',
|
|
91
|
+
'/healthz',
|
|
92
|
+
'/ready',
|
|
93
|
+
// Metrics
|
|
94
|
+
'/metrics',
|
|
95
|
+
// Favicon
|
|
96
|
+
'/favicon.ico',
|
|
97
|
+
],
|
|
98
|
+
};
|
|
99
|
+
instrumentFetch(options);
|
|
100
|
+
if (debug) {
|
|
101
|
+
console.log('[vestig] Fetch instrumentation enabled');
|
|
102
|
+
}
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Setup console capture if configured
|
|
107
|
+
*/
|
|
108
|
+
function setupConsole(config, debug) {
|
|
109
|
+
if (!config?.console) {
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
// Store original console.error
|
|
113
|
+
const originalError = console.error;
|
|
114
|
+
// Wrap console.error to create spans
|
|
115
|
+
console.error = (...args) => {
|
|
116
|
+
// Call original first
|
|
117
|
+
originalError.apply(console, args);
|
|
118
|
+
// Create span for the error (non-blocking)
|
|
119
|
+
// This is a fire-and-forget operation
|
|
120
|
+
try {
|
|
121
|
+
const message = args
|
|
122
|
+
.map((arg) => (typeof arg === 'string' ? arg : JSON.stringify(arg)))
|
|
123
|
+
.join(' ');
|
|
124
|
+
// Import dynamically to avoid circular deps
|
|
125
|
+
import('vestig').then(({ spanSync }) => {
|
|
126
|
+
spanSync('console.error', (s) => {
|
|
127
|
+
s.setAttribute('message', message.slice(0, 1000));
|
|
128
|
+
s.setStatus('error', 'console.error');
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
catch {
|
|
133
|
+
// Ignore errors in instrumentation
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
if (debug) {
|
|
137
|
+
console.log('[vestig] Console capture enabled');
|
|
138
|
+
}
|
|
139
|
+
// Return restore function
|
|
140
|
+
return () => {
|
|
141
|
+
console.error = originalError;
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Register vestig for Next.js instrumentation
|
|
146
|
+
*
|
|
147
|
+
* Call this in your `instrumentation.ts` file to enable:
|
|
148
|
+
* - OTLP trace export (Vercel, Honeycomb, Jaeger, etc.)
|
|
149
|
+
* - Automatic fetch() instrumentation
|
|
150
|
+
* - Console error capture (optional)
|
|
151
|
+
*
|
|
152
|
+
* @example Basic usage
|
|
153
|
+
* ```typescript
|
|
154
|
+
* // instrumentation.ts
|
|
155
|
+
* import { registerVestig } from '@vestig/next/instrumentation'
|
|
156
|
+
*
|
|
157
|
+
* export function register() {
|
|
158
|
+
* registerVestig({
|
|
159
|
+
* serviceName: 'my-app',
|
|
160
|
+
* })
|
|
161
|
+
* }
|
|
162
|
+
* ```
|
|
163
|
+
*
|
|
164
|
+
* @example With OTLP export
|
|
165
|
+
* ```typescript
|
|
166
|
+
* // instrumentation.ts
|
|
167
|
+
* import { registerVestig } from '@vestig/next/instrumentation'
|
|
168
|
+
*
|
|
169
|
+
* export function register() {
|
|
170
|
+
* registerVestig({
|
|
171
|
+
* serviceName: 'my-app',
|
|
172
|
+
* otlp: {
|
|
173
|
+
* endpoint: process.env.OTEL_EXPORTER_OTLP_ENDPOINT,
|
|
174
|
+
* headers: {
|
|
175
|
+
* 'Authorization': `Bearer ${process.env.OTEL_AUTH_TOKEN}`,
|
|
176
|
+
* },
|
|
177
|
+
* },
|
|
178
|
+
* })
|
|
179
|
+
* }
|
|
180
|
+
* ```
|
|
181
|
+
*
|
|
182
|
+
* @example Full configuration
|
|
183
|
+
* ```typescript
|
|
184
|
+
* // instrumentation.ts
|
|
185
|
+
* import { registerVestig } from '@vestig/next/instrumentation'
|
|
186
|
+
*
|
|
187
|
+
* export function register() {
|
|
188
|
+
* registerVestig({
|
|
189
|
+
* serviceName: 'my-app',
|
|
190
|
+
* otlp: {
|
|
191
|
+
* endpoint: process.env.OTEL_EXPORTER_OTLP_ENDPOINT,
|
|
192
|
+
* serviceVersion: '1.0.0',
|
|
193
|
+
* environment: process.env.VERCEL_ENV,
|
|
194
|
+
* },
|
|
195
|
+
* autoInstrument: {
|
|
196
|
+
* fetch: {
|
|
197
|
+
* captureHeaders: ['content-type', 'x-request-id'],
|
|
198
|
+
* ignoreUrls: ['/health', /^\/_next/],
|
|
199
|
+
* },
|
|
200
|
+
* console: true,
|
|
201
|
+
* },
|
|
202
|
+
* debug: process.env.NODE_ENV === 'development',
|
|
203
|
+
* })
|
|
204
|
+
* }
|
|
205
|
+
* ```
|
|
206
|
+
*
|
|
207
|
+
* @example Environment variables
|
|
208
|
+
* ```bash
|
|
209
|
+
* # These are automatically read if not specified in config:
|
|
210
|
+
* OTEL_EXPORTER_OTLP_ENDPOINT=https://otel.vercel.com/v1/traces
|
|
211
|
+
* OTEL_EXPORTER_OTLP_HEADERS=Authorization=Bearer token
|
|
212
|
+
* VERCEL_ENV=production
|
|
213
|
+
* ```
|
|
214
|
+
*/
|
|
215
|
+
export function registerVestig(options) {
|
|
216
|
+
const { serviceName, otlp, autoInstrument, debug = false } = options;
|
|
217
|
+
if (debug) {
|
|
218
|
+
console.log(`[vestig] Initializing for ${serviceName}...`);
|
|
219
|
+
}
|
|
220
|
+
// Track what was enabled
|
|
221
|
+
let otlpEnabled = false;
|
|
222
|
+
let fetchInstrumented = false;
|
|
223
|
+
let consoleRestore = null;
|
|
224
|
+
// Setup OTLP export
|
|
225
|
+
otlpEnabled = setupOTLP(serviceName, otlp, debug);
|
|
226
|
+
// Setup fetch instrumentation
|
|
227
|
+
fetchInstrumented = setupFetch(autoInstrument, debug);
|
|
228
|
+
// Setup console capture
|
|
229
|
+
consoleRestore = setupConsole(autoInstrument, debug);
|
|
230
|
+
if (debug) {
|
|
231
|
+
console.log('[vestig] Initialization complete');
|
|
232
|
+
}
|
|
233
|
+
// Return result with shutdown function
|
|
234
|
+
return {
|
|
235
|
+
otlpEnabled,
|
|
236
|
+
fetchInstrumented,
|
|
237
|
+
consoleInstrumented: consoleRestore !== null,
|
|
238
|
+
shutdown: async () => {
|
|
239
|
+
// Restore console
|
|
240
|
+
if (consoleRestore) {
|
|
241
|
+
consoleRestore();
|
|
242
|
+
}
|
|
243
|
+
// Shutdown span processors (flushes pending spans)
|
|
244
|
+
await shutdownSpanProcessors();
|
|
245
|
+
if (debug) {
|
|
246
|
+
console.log('[vestig] Shutdown complete');
|
|
247
|
+
}
|
|
248
|
+
},
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
//# sourceMappingURL=register.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"register.js","sourceRoot":"","sources":["../../src/instrumentation/register.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACN,eAAe,EACf,qBAAqB,EACrB,sBAA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AAC;IAED,uCAAuC;IACvC,OAAO;QACN,WAAW;QACX,iBAAiB;QACjB,mBAAmB,EAAE,cAAc,KAAK,IAAI;QAC5C,QAAQ,EAAE,KAAK,IAAI,EAAE;YACpB,kBAAkB;YAClB,IAAI,cAAc,EAAE,CAAC;gBACpB,cAAc,EAAE,CAAA;YACjB,CAAC;YAED,mDAAmD;YACnD,MAAM,sBAAsB,EAAE,CAAA;YAE9B,IAAI,KAAK,EAAE,CAAC;gBACX,OAAO,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAA;YAC1C,CAAC;QACF,CAAC;KACD,CAAA;AACF,CAAC"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types for registerVestig
|
|
3
|
+
*/
|
|
4
|
+
import type { InstrumentFetchOptions, TailSamplingConfig } from 'vestig';
|
|
5
|
+
/**
|
|
6
|
+
* OTLP configuration options
|
|
7
|
+
*/
|
|
8
|
+
export interface OTLPConfig {
|
|
9
|
+
/**
|
|
10
|
+
* OTLP endpoint URL for traces
|
|
11
|
+
* Falls back to OTEL_EXPORTER_OTLP_ENDPOINT env var
|
|
12
|
+
* @example 'https://otel.vercel.com/v1/traces'
|
|
13
|
+
*/
|
|
14
|
+
endpoint?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Custom headers for authentication
|
|
17
|
+
* Falls back to OTEL_EXPORTER_OTLP_HEADERS env var (comma-separated key=value pairs)
|
|
18
|
+
* @example { 'Authorization': 'Bearer token' }
|
|
19
|
+
*/
|
|
20
|
+
headers?: Record<string, string>;
|
|
21
|
+
/**
|
|
22
|
+
* Service version (optional)
|
|
23
|
+
* @example '1.0.0'
|
|
24
|
+
*/
|
|
25
|
+
serviceVersion?: string;
|
|
26
|
+
/**
|
|
27
|
+
* Deployment environment
|
|
28
|
+
* Falls back to VERCEL_ENV, NODE_ENV
|
|
29
|
+
* @example 'production', 'development'
|
|
30
|
+
*/
|
|
31
|
+
environment?: string;
|
|
32
|
+
/**
|
|
33
|
+
* Additional resource attributes
|
|
34
|
+
* @example { 'cloud.region': 'us-east-1' }
|
|
35
|
+
*/
|
|
36
|
+
resourceAttributes?: Record<string, unknown>;
|
|
37
|
+
/**
|
|
38
|
+
* Batch size for span export
|
|
39
|
+
* @default 100
|
|
40
|
+
*/
|
|
41
|
+
batchSize?: number;
|
|
42
|
+
/**
|
|
43
|
+
* Flush interval in ms
|
|
44
|
+
* @default 5000
|
|
45
|
+
*/
|
|
46
|
+
flushInterval?: number;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Auto-instrumentation options
|
|
50
|
+
*/
|
|
51
|
+
export interface AutoInstrumentConfig {
|
|
52
|
+
/**
|
|
53
|
+
* Auto-instrument all fetch() calls
|
|
54
|
+
* @default true
|
|
55
|
+
*/
|
|
56
|
+
fetch?: boolean | InstrumentFetchOptions;
|
|
57
|
+
/**
|
|
58
|
+
* Capture console.error as spans
|
|
59
|
+
* @default false
|
|
60
|
+
*/
|
|
61
|
+
console?: boolean;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Options for registerVestig
|
|
65
|
+
*/
|
|
66
|
+
export interface RegisterVestigOptions {
|
|
67
|
+
/**
|
|
68
|
+
* Service name (required)
|
|
69
|
+
* Used in OTLP resource attributes
|
|
70
|
+
*/
|
|
71
|
+
serviceName: string;
|
|
72
|
+
/**
|
|
73
|
+
* OTLP configuration
|
|
74
|
+
* If provided, enables automatic span export
|
|
75
|
+
*/
|
|
76
|
+
otlp?: OTLPConfig;
|
|
77
|
+
/**
|
|
78
|
+
* Auto-instrumentation options
|
|
79
|
+
*/
|
|
80
|
+
autoInstrument?: AutoInstrumentConfig;
|
|
81
|
+
/**
|
|
82
|
+
* Tail sampling configuration for wide events
|
|
83
|
+
*/
|
|
84
|
+
tailSampling?: TailSamplingConfig;
|
|
85
|
+
/**
|
|
86
|
+
* Enable debug logging
|
|
87
|
+
* @default false
|
|
88
|
+
*/
|
|
89
|
+
debug?: boolean;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Result of registerVestig
|
|
93
|
+
*/
|
|
94
|
+
export interface RegisterVestigResult {
|
|
95
|
+
/**
|
|
96
|
+
* Whether OTLP export was enabled
|
|
97
|
+
*/
|
|
98
|
+
otlpEnabled: boolean;
|
|
99
|
+
/**
|
|
100
|
+
* Whether fetch was instrumented
|
|
101
|
+
*/
|
|
102
|
+
fetchInstrumented: boolean;
|
|
103
|
+
/**
|
|
104
|
+
* Whether console capture was enabled
|
|
105
|
+
*/
|
|
106
|
+
consoleInstrumented: boolean;
|
|
107
|
+
/**
|
|
108
|
+
* Shutdown function to cleanup resources
|
|
109
|
+
*/
|
|
110
|
+
shutdown: () => Promise<void>;
|
|
111
|
+
}
|
|
112
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/instrumentation/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,QAAQ,CAAA;AAExE;;GAEG;AACH,MAAM,WAAW,UAAU;IAC1B;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IAEjB;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAEhC;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAA;IAEvB;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;IAEpB;;;OAGG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAE5C;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAElB;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,CAAA;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACpC;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,GAAG,sBAAsB,CAAA;IAExC;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACrC;;;OAGG;IACH,WAAW,EAAE,MAAM,CAAA;IAEnB;;;OAGG;IACH,IAAI,CAAC,EAAE,UAAU,CAAA;IAEjB;;OAEG;IACH,cAAc,CAAC,EAAE,oBAAoB,CAAA;IAErC;;OAEG;IACH,YAAY,CAAC,EAAE,kBAAkB,CAAA;IAEjC;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,CAAA;CACf;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACpC;;OAEG;IACH,WAAW,EAAE,OAAO,CAAA;IAEpB;;OAEG;IACH,iBAAiB,EAAE,OAAO,CAAA;IAE1B;;OAEG;IACH,mBAAmB,EAAE,OAAO,CAAA;IAE5B;;OAEG;IACH,QAAQ,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CAC7B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/instrumentation/types.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vestig/next",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.0",
|
|
4
4
|
"description": "First-class Next.js 15+ integration for vestig logging library. Zero boilerplate, automatic request correlation, full type safety.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -49,6 +49,10 @@
|
|
|
49
49
|
"./wide-events": {
|
|
50
50
|
"types": "./dist/wide-events/index.d.ts",
|
|
51
51
|
"import": "./dist/wide-events/index.js"
|
|
52
|
+
},
|
|
53
|
+
"./instrumentation": {
|
|
54
|
+
"types": "./dist/instrumentation/index.d.ts",
|
|
55
|
+
"import": "./dist/instrumentation/index.js"
|
|
52
56
|
}
|
|
53
57
|
},
|
|
54
58
|
"files": [
|
|
@@ -79,7 +83,10 @@
|
|
|
79
83
|
"observability",
|
|
80
84
|
"wide-events",
|
|
81
85
|
"canonical-log-lines",
|
|
82
|
-
"tail-sampling"
|
|
86
|
+
"tail-sampling",
|
|
87
|
+
"auto-instrumentation",
|
|
88
|
+
"otlp",
|
|
89
|
+
"opentelemetry"
|
|
83
90
|
],
|
|
84
91
|
"author": "Arakiss",
|
|
85
92
|
"license": "MIT",
|
|
@@ -99,7 +106,7 @@
|
|
|
99
106
|
"vestig": ">=0.2.0"
|
|
100
107
|
},
|
|
101
108
|
"dependencies": {
|
|
102
|
-
"vestig": "0.
|
|
109
|
+
"vestig": "0.18.0",
|
|
103
110
|
"web-vitals": "^4.2.4"
|
|
104
111
|
},
|
|
105
112
|
"devDependencies": {
|