@glasstrace/sdk 1.3.8 → 1.4.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 +68 -0
- package/dist/capture-error-BmQz7xF6.d.cts +455 -0
- package/dist/capture-error-CTgSYxek.d.ts +455 -0
- package/dist/{chunk-XS5W3SPL.js → chunk-4WI7B5FQ.js} +91 -5
- package/dist/chunk-4WI7B5FQ.js.map +1 -0
- package/dist/{chunk-NKRD3MKG.js → chunk-JZ475QRH.js} +2 -1
- package/dist/chunk-JZ475QRH.js.map +1 -0
- package/dist/{chunk-GYTCZSAV.js → chunk-MFYOQOD7.js} +2 -2
- package/dist/{chunk-4WUHMLMM.js → chunk-MMKFFF2L.js} +2 -2
- package/dist/{chunk-FKBCEOJ5.js → chunk-Q42BY5BA.js} +2 -2
- package/dist/{chunk-DBKG6SRI.js → chunk-QU26IKIJ.js} +2 -2
- package/dist/{chunk-ADUD4PEK.js → chunk-TANUWTFO.js} +3 -3
- package/dist/{chunk-LJMZXJ45.js → chunk-VJQIFY33.js} +3 -3
- package/dist/{chunk-E23HN24Z.js → chunk-VQDYXXVS.js} +9 -9
- package/dist/cli/init.cjs +14 -2
- package/dist/cli/init.cjs.map +1 -1
- package/dist/cli/init.js +7 -7
- package/dist/cli/mcp-add.cjs +13 -1
- package/dist/cli/mcp-add.cjs.map +1 -1
- package/dist/cli/mcp-add.js +3 -3
- package/dist/cli/uninit.js +3 -3
- package/dist/cli/validate.cjs +12 -1
- package/dist/cli/validate.cjs.map +1 -1
- package/dist/cli/validate.js +2 -2
- package/dist/{edge-entry-BSKA1l_0.d.ts → edge-entry-AWO70gje.d.ts} +1 -1
- package/dist/{edge-entry-DyMWa6JK.d.cts → edge-entry-DaeG7D7S.d.cts} +1 -1
- package/dist/edge-entry.cjs +43 -2
- package/dist/edge-entry.cjs.map +1 -1
- package/dist/edge-entry.d.cts +2 -2
- package/dist/edge-entry.d.ts +2 -2
- package/dist/edge-entry.js +2 -2
- package/dist/index.cjs +369 -8
- package/dist/index.cjs.map +1 -1
- package/dist/{index.d-Bo_Rxund.d.cts → index.d-Dq33YwFT.d.cts} +91 -1
- package/dist/{index.d-Bo_Rxund.d.ts → index.d-Dq33YwFT.d.ts} +91 -1
- package/dist/index.d.cts +91 -431
- package/dist/index.d.ts +91 -431
- package/dist/index.js +290 -6
- package/dist/index.js.map +1 -1
- package/dist/node-entry.cjs +49 -7
- package/dist/node-entry.cjs.map +1 -1
- package/dist/node-entry.d.cts +3 -3
- package/dist/node-entry.d.ts +3 -3
- package/dist/node-entry.js +7 -7
- package/dist/node-subpath.cjs +12 -1
- package/dist/node-subpath.cjs.map +1 -1
- package/dist/node-subpath.d.cts +1 -1
- package/dist/node-subpath.d.ts +1 -1
- package/dist/node-subpath.js +3 -3
- package/dist/{source-map-uploader-FSTHCYDR.js → source-map-uploader-PB3M4PPP.js} +3 -3
- package/package.json +1 -1
- package/dist/chunk-NKRD3MKG.js.map +0 -1
- package/dist/chunk-XS5W3SPL.js.map +0 -1
- /package/dist/{chunk-GYTCZSAV.js.map → chunk-MFYOQOD7.js.map} +0 -0
- /package/dist/{chunk-4WUHMLMM.js.map → chunk-MMKFFF2L.js.map} +0 -0
- /package/dist/{chunk-FKBCEOJ5.js.map → chunk-Q42BY5BA.js.map} +0 -0
- /package/dist/{chunk-DBKG6SRI.js.map → chunk-QU26IKIJ.js.map} +0 -0
- /package/dist/{chunk-ADUD4PEK.js.map → chunk-TANUWTFO.js.map} +0 -0
- /package/dist/{chunk-LJMZXJ45.js.map → chunk-VJQIFY33.js.map} +0 -0
- /package/dist/{chunk-E23HN24Z.js.map → chunk-VQDYXXVS.js.map} +0 -0
- /package/dist/{source-map-uploader-FSTHCYDR.js.map → source-map-uploader-PB3M4PPP.js.map} +0 -0
|
@@ -0,0 +1,455 @@
|
|
|
1
|
+
import { G as GlasstraceEnvVars, f as GlasstraceOptions, A as AnonApiKey, g as SdkInitResponse, C as CaptureConfig, h as SdkHealthReport, I as ImportGraphPayload, i as SdkDiagnosticCode } from './index.d-Dq33YwFT.js';
|
|
2
|
+
import { ReadableSpan } from './export/ReadableSpan';
|
|
3
|
+
import { SpanExporter } from './export/SpanExporter';
|
|
4
|
+
import { ExportResult } from './ExportResult';
|
|
5
|
+
import { a as SessionManager } from './edge-entry-AWO70gje.js';
|
|
6
|
+
import { SpanProcessor } from './SpanProcessor';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Resolved configuration after merging explicit options with environment variables.
|
|
10
|
+
*/
|
|
11
|
+
interface ResolvedConfig {
|
|
12
|
+
apiKey: string | undefined;
|
|
13
|
+
endpoint: string;
|
|
14
|
+
forceEnable: boolean;
|
|
15
|
+
verbose: boolean;
|
|
16
|
+
environment: string | undefined;
|
|
17
|
+
coverageMapEnabled: boolean;
|
|
18
|
+
nodeEnv: string | undefined;
|
|
19
|
+
vercelEnv: string | undefined;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Reads all recognized Glasstrace environment variables from process.env.
|
|
23
|
+
* Returns undefined for any variable not set. Never throws.
|
|
24
|
+
*/
|
|
25
|
+
declare function readEnvVars(): GlasstraceEnvVars;
|
|
26
|
+
/**
|
|
27
|
+
* Merges explicit GlasstraceOptions with environment variables.
|
|
28
|
+
* Explicit options take precedence over environment variables.
|
|
29
|
+
*/
|
|
30
|
+
declare function resolveConfig(options?: GlasstraceOptions): ResolvedConfig;
|
|
31
|
+
/**
|
|
32
|
+
* Returns true when the SDK should be inactive (production detected without force-enable).
|
|
33
|
+
* Logic order:
|
|
34
|
+
* 1. forceEnable === true → return false (override)
|
|
35
|
+
* 2. NODE_ENV === 'production' → return true
|
|
36
|
+
* 3. VERCEL_ENV === 'production' → return true
|
|
37
|
+
* 4. Otherwise → return false
|
|
38
|
+
*/
|
|
39
|
+
declare function isProductionDisabled(config: ResolvedConfig): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Returns true when no API key is configured (anonymous mode).
|
|
42
|
+
* Treats undefined, empty string, whitespace-only, and gt_anon_* keys as anonymous.
|
|
43
|
+
*/
|
|
44
|
+
declare function isAnonymousMode(config: ResolvedConfig): boolean;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* The set of recognized fetch target categories.
|
|
48
|
+
*/
|
|
49
|
+
type FetchTarget = "supabase" | "stripe" | "internal" | "unknown";
|
|
50
|
+
/**
|
|
51
|
+
* Classifies an outbound fetch target URL into a known category.
|
|
52
|
+
* Classification is case-insensitive and based on the URL hostname.
|
|
53
|
+
* Uses dot-boundary matching to avoid false positives (e.g. evilstripe.com).
|
|
54
|
+
*
|
|
55
|
+
* Returns one of: 'supabase', 'stripe', 'internal', or 'unknown'.
|
|
56
|
+
*/
|
|
57
|
+
declare function classifyFetchTarget(url: string): FetchTarget;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Reads an existing anonymous key from the filesystem.
|
|
61
|
+
* Returns the key if valid, or null if:
|
|
62
|
+
* - The file does not exist
|
|
63
|
+
* - The file content is invalid
|
|
64
|
+
* - An I/O error occurs
|
|
65
|
+
* - `node:fs` is unavailable (non-Node environment)
|
|
66
|
+
*/
|
|
67
|
+
declare function readAnonKey(projectRoot?: string): Promise<AnonApiKey | null>;
|
|
68
|
+
/**
|
|
69
|
+
* Gets an existing anonymous key from the filesystem, or creates a new one.
|
|
70
|
+
*
|
|
71
|
+
* - If file exists and contains a valid key, returns it
|
|
72
|
+
* - If file does not exist or content is invalid, generates a new key via createAnonApiKey()
|
|
73
|
+
* - Writes the new key to `.glasstrace/anon_key`, creating the directory if needed
|
|
74
|
+
* - On file write failure: logs a warning, caches an ephemeral in-memory key so
|
|
75
|
+
* repeated calls in the same process return the same key
|
|
76
|
+
* - In non-Node environments: returns an ephemeral in-memory key
|
|
77
|
+
*/
|
|
78
|
+
declare function getOrCreateAnonKey(projectRoot?: string): Promise<AnonApiKey>;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Reads and validates a cached config file from `.glasstrace/config`.
|
|
82
|
+
* Returns the parsed `SdkInitResponse` or `null` on any failure,
|
|
83
|
+
* including when `node:fs` is unavailable (non-Node environments).
|
|
84
|
+
*/
|
|
85
|
+
declare function loadCachedConfig(projectRoot?: string): SdkInitResponse | null;
|
|
86
|
+
/**
|
|
87
|
+
* Persists the init response to `.glasstrace/config` using the SDK 2.0
|
|
88
|
+
* atomic-write protocol (`tmp + fsync(tmp) + rename + fsync(parent)`).
|
|
89
|
+
* Silently skipped when `node:fs` is unavailable (non-Node environments).
|
|
90
|
+
* On I/O failure, logs a warning.
|
|
91
|
+
*
|
|
92
|
+
* Atomicity: the payload is written to `.glasstrace/config.tmp`, fsynced
|
|
93
|
+
* to durable storage, then renamed into place; the parent directory is
|
|
94
|
+
* fsynced last so the rename survives an immediate crash. `rename` is
|
|
95
|
+
* atomic on POSIX filesystems, so readers either see the previous valid
|
|
96
|
+
* config or the new valid config — never a truncated or partially-written
|
|
97
|
+
* file (DISC-1247 Scenario 5). If any step fails, the temp file is
|
|
98
|
+
* cleaned up on a best-effort basis.
|
|
99
|
+
*/
|
|
100
|
+
declare function saveCachedConfig(response: SdkInitResponse, projectRoot?: string): Promise<void>;
|
|
101
|
+
/**
|
|
102
|
+
* Sends a POST request to `/v1/sdk/init`.
|
|
103
|
+
* Validates the response against `SdkInitResponseSchema`.
|
|
104
|
+
*
|
|
105
|
+
* Uses `node:https` via {@link httpsPostJson} rather than the global
|
|
106
|
+
* `fetch` because Next.js 16 patches `fetch` for caching/revalidation
|
|
107
|
+
* and can cause the init request to silently hang (DISC-493 Issue 3).
|
|
108
|
+
* Retries transport-level failures (DNS, TCP, TLS) twice with 500ms +
|
|
109
|
+
* 1500ms backoff, capped at a 20-second total deadline. Server responses
|
|
110
|
+
* (HTTP 4xx/5xx) are never retried and are surfaced immediately.
|
|
111
|
+
*/
|
|
112
|
+
declare function sendInitRequest(config: ResolvedConfig, anonKey: AnonApiKey | null, sdkVersion: string, importGraph?: ImportGraphPayload, healthReport?: SdkHealthReport, diagnostics?: Array<{
|
|
113
|
+
code: SdkDiagnosticCode;
|
|
114
|
+
message: string;
|
|
115
|
+
timestamp: number;
|
|
116
|
+
}>, signal?: AbortSignal): Promise<SdkInitResponse>;
|
|
117
|
+
/**
|
|
118
|
+
* Result returned by {@link performInit} when the backend reports an
|
|
119
|
+
* account claim transition. `null` means no claim was present.
|
|
120
|
+
*/
|
|
121
|
+
interface InitClaimResult {
|
|
122
|
+
claimResult: NonNullable<SdkInitResponse["claimResult"]>;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Orchestrates the full init flow: send request, update config, cache result.
|
|
126
|
+
* This function MUST NOT throw.
|
|
127
|
+
*
|
|
128
|
+
* Returns the claim result when the backend reports an account claim
|
|
129
|
+
* transition, or `null` when no claim result is available (including
|
|
130
|
+
* when init is skipped due to rate-limit backoff, missing API key,
|
|
131
|
+
* or request failure). Callers that do not need claim information
|
|
132
|
+
* can safely ignore the return value.
|
|
133
|
+
*/
|
|
134
|
+
declare function performInit(config: ResolvedConfig, anonKey: AnonApiKey | null, sdkVersion: string, healthReport?: SdkHealthReport | null): Promise<InitClaimResult | null>;
|
|
135
|
+
/**
|
|
136
|
+
* Returns the current capture config from the three-tier fallback chain:
|
|
137
|
+
* 1. In-memory config from latest init response
|
|
138
|
+
* 2. File cache (read at most once per process lifetime)
|
|
139
|
+
* 3. DEFAULT_CAPTURE_CONFIG
|
|
140
|
+
*
|
|
141
|
+
* The disk read is cached via `configCacheChecked` to avoid repeated
|
|
142
|
+
* synchronous I/O on the hot path (called by GlasstraceExporter on
|
|
143
|
+
* every span export batch).
|
|
144
|
+
*/
|
|
145
|
+
declare function getActiveConfig(): CaptureConfig;
|
|
146
|
+
/**
|
|
147
|
+
* Returns the `linkedAccountId` from the current in-memory init response,
|
|
148
|
+
* or `undefined` if no init response is available or no account is linked.
|
|
149
|
+
*
|
|
150
|
+
* Used by the discovery endpoint to determine whether `claimed: true`
|
|
151
|
+
* should be included in the response.
|
|
152
|
+
*/
|
|
153
|
+
declare function getLinkedAccountId(): string | undefined;
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Options for constructing a {@link GlasstraceExporter}.
|
|
157
|
+
*/
|
|
158
|
+
interface GlasstraceExporterOptions {
|
|
159
|
+
getApiKey: () => string;
|
|
160
|
+
sessionManager: SessionManager;
|
|
161
|
+
getConfig: () => CaptureConfig;
|
|
162
|
+
environment: string | undefined;
|
|
163
|
+
endpointUrl: string;
|
|
164
|
+
createDelegate: ((url: string, headers: Record<string, string>) => SpanExporter) | null;
|
|
165
|
+
/** When true, logs diagnostic details about enrichment decisions via sdkLog. */
|
|
166
|
+
verbose?: boolean;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* A SpanExporter that enriches spans with glasstrace.* attributes at export
|
|
170
|
+
* time, then delegates to a real OTLP exporter.
|
|
171
|
+
*
|
|
172
|
+
* This design resolves three issues:
|
|
173
|
+
* - Spans emitted before the API key resolves are buffered (not dropped)
|
|
174
|
+
* and flushed once the key is available.
|
|
175
|
+
* - Enrichment happens in the exporter (not onEnding), so it works
|
|
176
|
+
* on Vercel where CompositeSpanProcessor does not forward onEnding().
|
|
177
|
+
* - Session ID is computed at export time using the resolved API key,
|
|
178
|
+
* not the "pending" placeholder.
|
|
179
|
+
*/
|
|
180
|
+
declare class GlasstraceExporter implements SpanExporter {
|
|
181
|
+
private readonly getApiKey;
|
|
182
|
+
private readonly sessionManager;
|
|
183
|
+
private readonly getConfig;
|
|
184
|
+
private readonly environment;
|
|
185
|
+
private readonly endpointUrl;
|
|
186
|
+
private readonly createDelegateFn;
|
|
187
|
+
private readonly verbose;
|
|
188
|
+
private delegate;
|
|
189
|
+
private delegateKey;
|
|
190
|
+
private pendingBatches;
|
|
191
|
+
private pendingSpanCount;
|
|
192
|
+
private overflowLogged;
|
|
193
|
+
constructor(options: GlasstraceExporterOptions);
|
|
194
|
+
export(spans: ReadableSpan[], resultCallback: (result: ExportResult) => void): void;
|
|
195
|
+
/**
|
|
196
|
+
* Called when the API key transitions from "pending" to a resolved value.
|
|
197
|
+
* Creates the delegate exporter and flushes all buffered spans.
|
|
198
|
+
*/
|
|
199
|
+
notifyKeyResolved(): void;
|
|
200
|
+
shutdown(): Promise<void>;
|
|
201
|
+
/**
|
|
202
|
+
* Flushes any pending buffered spans (if the API key has resolved) and
|
|
203
|
+
* delegates to the underlying exporter's forceFlush to drain its queue.
|
|
204
|
+
*/
|
|
205
|
+
forceFlush(): Promise<void>;
|
|
206
|
+
/**
|
|
207
|
+
* Enriches a ReadableSpan with all glasstrace.* attributes.
|
|
208
|
+
* Returns a new ReadableSpan wrapper; the original span is not mutated.
|
|
209
|
+
*
|
|
210
|
+
* Only {@link SessionManager.getSessionId} is individually guarded because
|
|
211
|
+
* it calls into crypto and schema validation — a session ID failure should
|
|
212
|
+
* not prevent the rest of enrichment. The other helper calls
|
|
213
|
+
* ({@link deriveErrorCategory}, {@link deriveOrmProvider},
|
|
214
|
+
* {@link classifyFetchTarget}) are pure functions on typed string inputs
|
|
215
|
+
* and rely on the outer catch for any unexpected failure.
|
|
216
|
+
*
|
|
217
|
+
* On total failure, returns the original span unchanged.
|
|
218
|
+
*/
|
|
219
|
+
private enrichSpan;
|
|
220
|
+
/**
|
|
221
|
+
* Lazily creates the delegate OTLP exporter once the API key is resolved.
|
|
222
|
+
* Recreates the delegate if the key has changed (e.g., after key rotation)
|
|
223
|
+
* so the Authorization header stays current.
|
|
224
|
+
*/
|
|
225
|
+
private ensureDelegate;
|
|
226
|
+
/**
|
|
227
|
+
* Buffers raw (unenriched) spans while the API key is pending.
|
|
228
|
+
* Evicts oldest batches if the buffer exceeds MAX_PENDING_SPANS.
|
|
229
|
+
* Re-checks the key after buffering to close the race window where
|
|
230
|
+
* the key resolves between the caller's check and this buffer call.
|
|
231
|
+
*/
|
|
232
|
+
private bufferSpans;
|
|
233
|
+
/**
|
|
234
|
+
* Flushes all buffered spans through the delegate exporter.
|
|
235
|
+
* Enriches spans at flush time (not buffer time) so that session IDs
|
|
236
|
+
* are computed with the resolved API key instead of the "pending" sentinel.
|
|
237
|
+
*/
|
|
238
|
+
private flushPending;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* The primary SDK entry point called by developers in their `instrumentation.ts`.
|
|
243
|
+
* Orchestrates OTel setup, span processor, init client, anon key, and discovery endpoint.
|
|
244
|
+
*
|
|
245
|
+
* This function is synchronous and MUST NOT throw. The developer's server is never blocked.
|
|
246
|
+
* Background work (key resolution, init call) happens via fire-and-forget promises.
|
|
247
|
+
*
|
|
248
|
+
* @param options - Optional SDK configuration. Environment variables are used as fallbacks.
|
|
249
|
+
*
|
|
250
|
+
* @example
|
|
251
|
+
* ```ts
|
|
252
|
+
* // instrumentation.ts
|
|
253
|
+
* import { registerGlasstrace } from "@glasstrace/sdk";
|
|
254
|
+
* registerGlasstrace(); // uses env vars
|
|
255
|
+
* ```
|
|
256
|
+
*/
|
|
257
|
+
declare function registerGlasstrace(options?: GlasstraceOptions): void;
|
|
258
|
+
/**
|
|
259
|
+
* Returns the registered discovery handler, or null if not registered.
|
|
260
|
+
*/
|
|
261
|
+
declare function getDiscoveryHandler(): ((request: Request) => Promise<Response | null>) | null;
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Structural view of Next.js's `NextConfig`. The SDK does not import Next's
|
|
265
|
+
* type directly because Next is not a peer dependency — this wrapper must
|
|
266
|
+
* type-check regardless of which Next.js version the consumer has installed.
|
|
267
|
+
*
|
|
268
|
+
* The constraint is `object` rather than `Record<string, unknown>` because
|
|
269
|
+
* Next's actual `NextConfig` is an interface *without* a string index
|
|
270
|
+
* signature. Requiring `[key: string]: unknown` would fail the assignability
|
|
271
|
+
* check that caused DISC-1256, reported by Next 16 consumers as:
|
|
272
|
+
* > Argument of type 'NextConfig' is not assignable to parameter of type
|
|
273
|
+
* > 'NextConfig'. Index signature for type 'string' is missing in type
|
|
274
|
+
* > 'NextConfig'.
|
|
275
|
+
*
|
|
276
|
+
* `object` accepts every non-primitive value, which is what the wrapper
|
|
277
|
+
* actually handles at runtime (it shallow-copies the input and reads a few
|
|
278
|
+
* known properties defensively). Combined with the generic signature on
|
|
279
|
+
* `withGlasstraceConfig`, callers preserve their exact config subtype.
|
|
280
|
+
*/
|
|
281
|
+
type NextConfig = object;
|
|
282
|
+
/**
|
|
283
|
+
* Wraps the developer's Next.js config to enable source map generation
|
|
284
|
+
* and upload .map files to the ingestion API at build time.
|
|
285
|
+
*
|
|
286
|
+
* The build NEVER fails because of Glasstrace — all errors are caught
|
|
287
|
+
* and logged as warnings.
|
|
288
|
+
*
|
|
289
|
+
* ## What the wrapper configures for you
|
|
290
|
+
*
|
|
291
|
+
* - `experimental.serverSourceMaps: true` — enables server-side source maps
|
|
292
|
+
* so Glasstrace can resolve stack traces back to your source.
|
|
293
|
+
* - `serverExternalPackages: ["@glasstrace/sdk"]` — tells Next to load the
|
|
294
|
+
* SDK via Node's `require()` at runtime instead of bundling it through
|
|
295
|
+
* webpack or Turbopack on the RSC / Route Handler paths. This is the same
|
|
296
|
+
* pattern Prisma, `@vercel/otel`, Sentry, `sharp`, and `bcrypt` ship with.
|
|
297
|
+
* - A webpack `externals` entry that marks every Node.js built-in import
|
|
298
|
+
* (both `node:*` and bare forms like `zlib` or `stream`) as a runtime
|
|
299
|
+
* `commonjs` require. `serverExternalPackages` does not apply to the
|
|
300
|
+
* instrumentation path under `next dev --webpack`
|
|
301
|
+
* (vercel/next.js#58003, #28774), so any bundled SDK chunk that imports
|
|
302
|
+
* `node:child_process` or the bare `zlib` specifier used by
|
|
303
|
+
* `@opentelemetry/otlp-exporter-base` would otherwise crash with
|
|
304
|
+
* `UnhandledSchemeError` or `Can't resolve 'zlib'`. This entry is the
|
|
305
|
+
* actual DISC-1257 fix for the dev-webpack path. Turbopack is
|
|
306
|
+
* unaffected — it ignores `config.webpack` and resolves Node built-ins
|
|
307
|
+
* natively.
|
|
308
|
+
* - An empty `turbopack: {}` when none is set, so Next 16 does not reject
|
|
309
|
+
* the config for setting `webpack` without a companion `turbopack` key
|
|
310
|
+
* (DISC-1256).
|
|
311
|
+
* - A `webpack` hook that collects and uploads `.map` files on client-side
|
|
312
|
+
* production builds.
|
|
313
|
+
*
|
|
314
|
+
* ## Turbopack
|
|
315
|
+
*
|
|
316
|
+
* Next.js 16 made Turbopack the default bundler for `next build`, and Next
|
|
317
|
+
* rejects configs that set `webpack` without also setting `turbopack`. This
|
|
318
|
+
* wrapper therefore seeds an empty `turbopack: {}` when the user has not set
|
|
319
|
+
* one themselves, preserving existing behaviour for explicit Turbopack configs.
|
|
320
|
+
*
|
|
321
|
+
* **Source-map upload is currently webpack-only.** Under Turbopack the build
|
|
322
|
+
* succeeds, but the afterEmit hook that collects and uploads `.map` files does
|
|
323
|
+
* not fire. Run `next build --webpack` to get source-map uploads, or wait for
|
|
324
|
+
* a follow-up release that ports the plugin to Turbopack.
|
|
325
|
+
*
|
|
326
|
+
* @param nextConfig - The developer's existing Next.js configuration object.
|
|
327
|
+
* @returns A new config object with source map generation and upload enabled.
|
|
328
|
+
* The return type mirrors the input type so that caller-side config
|
|
329
|
+
* properties are preserved. The `object` constraint (rather than
|
|
330
|
+
* `Record<string, unknown>`) is what makes the wrapper accept Next's
|
|
331
|
+
* real `NextConfig` interface (DISC-1256).
|
|
332
|
+
*/
|
|
333
|
+
declare function withGlasstraceConfig<T extends NextConfig>(nextConfig: T): T;
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* Returns true when the SDK is in ACTIVE or ACTIVE_DEGRADED state.
|
|
337
|
+
*/
|
|
338
|
+
declare function isReady(): boolean;
|
|
339
|
+
/**
|
|
340
|
+
* Resolves when the SDK reaches ACTIVE or ACTIVE_DEGRADED.
|
|
341
|
+
* Rejects on PRODUCTION_DISABLED, REGISTRATION_FAILED, or timeout.
|
|
342
|
+
*
|
|
343
|
+
* Checks current state synchronously first — resolves/rejects immediately
|
|
344
|
+
* if the SDK has already reached a terminal or ready state.
|
|
345
|
+
*/
|
|
346
|
+
declare function waitForReady(timeoutMs?: number): Promise<void>;
|
|
347
|
+
/**
|
|
348
|
+
* Simplified public state query for external consumers.
|
|
349
|
+
* Hides implementation details like coexistence scenarios.
|
|
350
|
+
*
|
|
351
|
+
* The returned `tracing` field is the canonical user-observable signal
|
|
352
|
+
* for OTel coexistence outcomes:
|
|
353
|
+
*
|
|
354
|
+
* - `"active"` — the SDK owns the OTel provider and is exporting spans.
|
|
355
|
+
* - `"coexistence"` — another OTel provider was detected and the SDK
|
|
356
|
+
* either auto-attached its span processor or found one already
|
|
357
|
+
* present. Spans are exported through the existing pipeline.
|
|
358
|
+
* - `"degraded"` — the SDK is exporting but the core lifecycle entered
|
|
359
|
+
* `ACTIVE_DEGRADED` (e.g., a non-fatal export failure).
|
|
360
|
+
* - `"not-configured"` — the SDK could not configure tracing. Covers
|
|
361
|
+
* `OtelState.UNCONFIGURED`, `OtelState.CONFIGURING`, and
|
|
362
|
+
* `OtelState.COEXISTENCE_FAILED` (the DISC-1556 Next 16 production
|
|
363
|
+
* "auto-attach returned null" path). When the value is
|
|
364
|
+
* `"not-configured"` after `registerGlasstrace()` has resolved,
|
|
365
|
+
* spans are NOT reaching the Glasstrace exporter and the manual
|
|
366
|
+
* `createGlasstraceSpanProcessor()` workaround should be applied.
|
|
367
|
+
* See `runtime-state.json`'s `lastError` field for the structured
|
|
368
|
+
* failure record.
|
|
369
|
+
*/
|
|
370
|
+
declare function getStatus(): {
|
|
371
|
+
ready: boolean;
|
|
372
|
+
mode: "anonymous" | "authenticated" | "claiming" | "disabled";
|
|
373
|
+
tracing: "active" | "degraded" | "not-configured" | "coexistence";
|
|
374
|
+
};
|
|
375
|
+
|
|
376
|
+
/**
|
|
377
|
+
* OTel Coexistence Public API
|
|
378
|
+
*
|
|
379
|
+
* Provides createGlasstraceSpanProcessor() for developers who want to
|
|
380
|
+
* manually integrate Glasstrace with their existing OTel provider
|
|
381
|
+
* (e.g., Sentry's openTelemetrySpanProcessors config option).
|
|
382
|
+
*
|
|
383
|
+
* Also provides the auto-attach path (tryAutoAttachGlasstraceProcessor)
|
|
384
|
+
* that configureOtel() uses when it detects a pre-registered provider
|
|
385
|
+
* at runtime (Next.js 16 production, Sentry, Datadog, New Relic). Both
|
|
386
|
+
* entry points reuse the same span-processor factory so the manual and
|
|
387
|
+
* automatic paths stay in lockstep.
|
|
388
|
+
*
|
|
389
|
+
* Design: sdk-otel-coexistence.md Sections 3, 4, 5, 6
|
|
390
|
+
*/
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
* Creates a Glasstrace span processor for manual integration with an
|
|
394
|
+
* existing OTel provider.
|
|
395
|
+
*
|
|
396
|
+
* Use this when another tool (e.g., Sentry) owns the OTel provider and
|
|
397
|
+
* you want to add Glasstrace to their processor list:
|
|
398
|
+
*
|
|
399
|
+
* @example
|
|
400
|
+
* ```ts
|
|
401
|
+
* import * as Sentry from "@sentry/nextjs";
|
|
402
|
+
* import { createGlasstraceSpanProcessor } from "@glasstrace/sdk";
|
|
403
|
+
*
|
|
404
|
+
* Sentry.init({
|
|
405
|
+
* dsn: "...",
|
|
406
|
+
* openTelemetrySpanProcessors: [createGlasstraceSpanProcessor()],
|
|
407
|
+
* });
|
|
408
|
+
* ```
|
|
409
|
+
*
|
|
410
|
+
* **Important:** `registerGlasstrace()` is still required even when using
|
|
411
|
+
* this function. The processor handles span transport (enrichment and
|
|
412
|
+
* export). `registerGlasstrace()` handles everything else: init calls,
|
|
413
|
+
* config sync, session management, anonymous key generation, discovery
|
|
414
|
+
* endpoint, and health reporting.
|
|
415
|
+
*
|
|
416
|
+
* @param options - Optional SDK configuration. If omitted, uses the same
|
|
417
|
+
* config as registerGlasstrace() (environment variables).
|
|
418
|
+
* @returns A BatchSpanProcessor wrapping a GlasstraceExporter with the
|
|
419
|
+
* branded Symbol.for('glasstrace.exporter') for coexistence detection.
|
|
420
|
+
*/
|
|
421
|
+
declare function createGlasstraceSpanProcessor(options?: GlasstraceOptions): SpanProcessor;
|
|
422
|
+
|
|
423
|
+
/**
|
|
424
|
+
* Manual error capture API.
|
|
425
|
+
*
|
|
426
|
+
* Provides a simple function for developers to manually record errors
|
|
427
|
+
* as span events, independent of the `consoleErrors` config flag.
|
|
428
|
+
*/
|
|
429
|
+
/**
|
|
430
|
+
* Records an error as a span event on the currently active OTel span.
|
|
431
|
+
*
|
|
432
|
+
* Works regardless of the `consoleErrors` configuration — this is an
|
|
433
|
+
* explicit, opt-in API for manual error reporting. If no span is active
|
|
434
|
+
* or OTel is not available, the call is silently ignored.
|
|
435
|
+
*
|
|
436
|
+
* On the first captured error, may display a one-time diagnostic nudge
|
|
437
|
+
* to stderr if the MCP connection marker is absent (dev environments only).
|
|
438
|
+
*
|
|
439
|
+
* @param error - The error to capture. Accepts `Error` objects, strings, or any value.
|
|
440
|
+
*
|
|
441
|
+
* @example
|
|
442
|
+
* ```ts
|
|
443
|
+
* import { captureError } from "@glasstrace/sdk";
|
|
444
|
+
*
|
|
445
|
+
* try {
|
|
446
|
+
* await riskyOperation();
|
|
447
|
+
* } catch (err) {
|
|
448
|
+
* captureError(err);
|
|
449
|
+
* // handle error normally...
|
|
450
|
+
* }
|
|
451
|
+
* ```
|
|
452
|
+
*/
|
|
453
|
+
declare function captureError(error: unknown): void;
|
|
454
|
+
|
|
455
|
+
export { type FetchTarget as F, GlasstraceExporter as G, type InitClaimResult as I, type ResolvedConfig as R, type GlasstraceExporterOptions as a, classifyFetchTarget as b, captureError as c, createGlasstraceSpanProcessor as d, getDiscoveryHandler as e, getLinkedAccountId as f, getActiveConfig as g, getOrCreateAnonKey as h, getStatus as i, isAnonymousMode as j, isProductionDisabled as k, isReady as l, loadCachedConfig as m, readEnvVars as n, registerGlasstrace as o, performInit as p, resolveConfig as q, readAnonKey as r, saveCachedConfig as s, sendInitRequest as t, withGlasstraceConfig as u, waitForReady as w };
|
|
@@ -13802,7 +13802,18 @@ var CaptureConfigSchema = external_exports.object({
|
|
|
13802
13802
|
fullConsoleOutput: external_exports.boolean(),
|
|
13803
13803
|
importGraph: external_exports.boolean(),
|
|
13804
13804
|
consoleErrors: external_exports.boolean().optional().default(false),
|
|
13805
|
-
errorResponseBodies: external_exports.boolean().optional().default(false)
|
|
13805
|
+
errorResponseBodies: external_exports.boolean().optional().default(false),
|
|
13806
|
+
/**
|
|
13807
|
+
* Account opt-in for side-effect evidence emission (SDK-049).
|
|
13808
|
+
*
|
|
13809
|
+
* When `false` (default), `recordSideEffect()` is a silent no-op:
|
|
13810
|
+
* no allowlist evaluation runs and no `glasstrace.side_effect.*`
|
|
13811
|
+
* attribute reaches the wire. When `true`, allowlisted side-effect
|
|
13812
|
+
* metadata is attached to the active OTel span subject to the
|
|
13813
|
+
* client-side allowlist enforcement layered with the product's
|
|
13814
|
+
* storage-time filter as defense-in-depth.
|
|
13815
|
+
*/
|
|
13816
|
+
sideEffectEvidence: external_exports.boolean().optional().default(false)
|
|
13806
13817
|
});
|
|
13807
13818
|
var SdkCachedConfigSchema = external_exports.object({
|
|
13808
13819
|
response: external_exports.record(external_exports.string(), external_exports.unknown()),
|
|
@@ -13862,7 +13873,37 @@ var GLASSTRACE_ATTRIBUTE_NAMES = {
|
|
|
13862
13873
|
TRIGGER_TYPE: "glasstrace.trigger.type",
|
|
13863
13874
|
ELEMENT_FINGERPRINT: "glasstrace.element.fingerprint",
|
|
13864
13875
|
ELEMENT_CONFIDENCE: "glasstrace.element.confidence",
|
|
13865
|
-
TAB_ID: "glasstrace.tab.id"
|
|
13876
|
+
TAB_ID: "glasstrace.tab.id",
|
|
13877
|
+
// Side-effect evidence (SDK-049 / SCHEMA-036).
|
|
13878
|
+
// Top-level operation attributes attached to the active span when a
|
|
13879
|
+
// side-effect is recorded via `recordSideEffect()`. The wire-string
|
|
13880
|
+
// set aligns verbatim with the product-side filter in
|
|
13881
|
+
// `packages/ingestion/src/services/trace-writer.ts`.
|
|
13882
|
+
SIDE_EFFECT_KIND: "glasstrace.side_effect.kind",
|
|
13883
|
+
SIDE_EFFECT_OPERATION: "glasstrace.side_effect.operation",
|
|
13884
|
+
SIDE_EFFECT_STATUS: "glasstrace.side_effect.status",
|
|
13885
|
+
SIDE_EFFECT_PHASE: "glasstrace.side_effect.phase",
|
|
13886
|
+
// Allowlisted semantic field attributes — one per allowlisted key.
|
|
13887
|
+
// Wire keys are camelCase to match the SCHEMA-036 enum members
|
|
13888
|
+
// exactly; the SDK constant names are SCREAMING_SNAKE per the rest
|
|
13889
|
+
// of GLASSTRACE_ATTRIBUTE_NAMES.
|
|
13890
|
+
SIDE_EFFECT_FIELD_TEMPLATE_KEY: "glasstrace.side_effect.field.templateKey",
|
|
13891
|
+
SIDE_EFFECT_FIELD_PROVIDER_OPERATION: "glasstrace.side_effect.field.providerOperation",
|
|
13892
|
+
SIDE_EFFECT_FIELD_ROLE: "glasstrace.side_effect.field.role",
|
|
13893
|
+
SIDE_EFFECT_FIELD_LOCALE: "glasstrace.side_effect.field.locale",
|
|
13894
|
+
SIDE_EFFECT_FIELD_TIMEZONE: "glasstrace.side_effect.field.timezone",
|
|
13895
|
+
SIDE_EFFECT_FIELD_STATUS: "glasstrace.side_effect.field.status",
|
|
13896
|
+
SIDE_EFFECT_FIELD_PHASE: "glasstrace.side_effect.field.phase",
|
|
13897
|
+
// Omission reason attributes — one per allowlisted reason. The
|
|
13898
|
+
// attribute value carries an integer count; the rejected value is
|
|
13899
|
+
// never echoed.
|
|
13900
|
+
SIDE_EFFECT_OMITTED_PII: "glasstrace.side_effect.omitted.pii",
|
|
13901
|
+
SIDE_EFFECT_OMITTED_SECRET: "glasstrace.side_effect.omitted.secret",
|
|
13902
|
+
SIDE_EFFECT_OMITTED_RAW_PAYLOAD: "glasstrace.side_effect.omitted.raw_payload",
|
|
13903
|
+
SIDE_EFFECT_OMITTED_UNSUPPORTED_KEY: "glasstrace.side_effect.omitted.unsupported_key",
|
|
13904
|
+
SIDE_EFFECT_OMITTED_VALUE_TOO_LONG: "glasstrace.side_effect.omitted.value_too_long",
|
|
13905
|
+
SIDE_EFFECT_OMITTED_NOT_EMITTED: "glasstrace.side_effect.omitted.not_emitted",
|
|
13906
|
+
SIDE_EFFECT_OMITTED_CAPTURE_DISABLED: "glasstrace.side_effect.omitted.capture_disabled"
|
|
13866
13907
|
};
|
|
13867
13908
|
var DEFAULT_CAPTURE_CONFIG = {
|
|
13868
13909
|
requestBodies: false,
|
|
@@ -13871,7 +13912,8 @@ var DEFAULT_CAPTURE_CONFIG = {
|
|
|
13871
13912
|
fullConsoleOutput: false,
|
|
13872
13913
|
importGraph: false,
|
|
13873
13914
|
consoleErrors: false,
|
|
13874
|
-
errorResponseBodies: false
|
|
13915
|
+
errorResponseBodies: false,
|
|
13916
|
+
sideEffectEvidence: false
|
|
13875
13917
|
};
|
|
13876
13918
|
var MAX_SOURCE_MAP_FILE_PATH_LENGTH = 512;
|
|
13877
13919
|
var MAX_SOURCE_MAP_FILE_SIZE = 50 * 1024 * 1024;
|
|
@@ -14137,6 +14179,45 @@ function deriveSessionId(apiKey, origin, date5, windowIndex) {
|
|
|
14137
14179
|
const digest = sha256Hex(input).slice(0, 16);
|
|
14138
14180
|
return SessionIdSchema.parse(digest);
|
|
14139
14181
|
}
|
|
14182
|
+
var SIDE_EFFECT_OPERATION_KINDS = [
|
|
14183
|
+
"email",
|
|
14184
|
+
"calendar_link",
|
|
14185
|
+
"webhook",
|
|
14186
|
+
"external_api",
|
|
14187
|
+
"queue",
|
|
14188
|
+
"after_callback"
|
|
14189
|
+
];
|
|
14190
|
+
var SIDE_EFFECT_SEMANTIC_FIELD_KEYS = [
|
|
14191
|
+
"templateKey",
|
|
14192
|
+
"providerOperation",
|
|
14193
|
+
"role",
|
|
14194
|
+
"locale",
|
|
14195
|
+
"timezone",
|
|
14196
|
+
"status",
|
|
14197
|
+
"phase"
|
|
14198
|
+
];
|
|
14199
|
+
var SIDE_EFFECT_OMISSION_REASONS = [
|
|
14200
|
+
"pii",
|
|
14201
|
+
"secret",
|
|
14202
|
+
"raw_payload",
|
|
14203
|
+
"unsupported_key",
|
|
14204
|
+
"value_too_long",
|
|
14205
|
+
"not_emitted",
|
|
14206
|
+
"capture_disabled"
|
|
14207
|
+
];
|
|
14208
|
+
var SIDE_EFFECT_OPERATION_STATUSES = [
|
|
14209
|
+
"scheduled",
|
|
14210
|
+
"started",
|
|
14211
|
+
"succeeded",
|
|
14212
|
+
"failed",
|
|
14213
|
+
"unknown"
|
|
14214
|
+
];
|
|
14215
|
+
var SIDE_EFFECT_OPERATION_PHASES = [
|
|
14216
|
+
"request",
|
|
14217
|
+
"post_response",
|
|
14218
|
+
"background",
|
|
14219
|
+
"unknown"
|
|
14220
|
+
];
|
|
14140
14221
|
|
|
14141
14222
|
export {
|
|
14142
14223
|
DevApiKeySchema,
|
|
@@ -14150,6 +14231,11 @@ export {
|
|
|
14150
14231
|
SourceMapUploadResponseSchema,
|
|
14151
14232
|
PresignedUploadResponseSchema,
|
|
14152
14233
|
SourceMapManifestResponseSchema,
|
|
14153
|
-
deriveSessionId
|
|
14234
|
+
deriveSessionId,
|
|
14235
|
+
SIDE_EFFECT_OPERATION_KINDS,
|
|
14236
|
+
SIDE_EFFECT_SEMANTIC_FIELD_KEYS,
|
|
14237
|
+
SIDE_EFFECT_OMISSION_REASONS,
|
|
14238
|
+
SIDE_EFFECT_OPERATION_STATUSES,
|
|
14239
|
+
SIDE_EFFECT_OPERATION_PHASES
|
|
14154
14240
|
};
|
|
14155
|
-
//# sourceMappingURL=chunk-
|
|
14241
|
+
//# sourceMappingURL=chunk-4WI7B5FQ.js.map
|