@glasstrace/sdk 0.1.0 → 0.2.1
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/adapters/drizzle.js +2 -0
- package/dist/adapters/drizzle.js.map +1 -1
- package/dist/chunk-CUFIV225.js +14083 -0
- package/dist/chunk-CUFIV225.js.map +1 -0
- package/dist/chunk-PZ5AY32C.js +10 -0
- package/dist/chunk-PZ5AY32C.js.map +1 -0
- package/dist/cli/init.cjs +13855 -4
- package/dist/cli/init.cjs.map +1 -1
- package/dist/cli/init.js +2 -1
- package/dist/cli/init.js.map +1 -1
- package/dist/index.cjs +14254 -203
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +156 -6
- package/dist/index.d.ts +156 -6
- package/dist/index.js +262 -111
- package/dist/index.js.map +1 -1
- package/package.json +2 -4
- package/dist/chunk-BKMITIEZ.js +0 -169
- package/dist/chunk-BKMITIEZ.js.map +0 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,8 +1,126 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as z from './v4/classic/external.cjs';
|
|
2
2
|
import { Context } from '@opentelemetry/api';
|
|
3
3
|
import { SpanProcessor, Span, ReadableSpan, SpanExporter } from '@opentelemetry/sdk-trace-base';
|
|
4
4
|
import { ExportResult } from '@opentelemetry/core';
|
|
5
5
|
|
|
6
|
+
/** Anonymous API key: `gt_anon_` + 48 hex chars. */
|
|
7
|
+
declare const AnonApiKeySchema: z.core.$ZodBranded<z.ZodString, "AnonApiKey", "out">;
|
|
8
|
+
type AnonApiKey = z.infer<typeof AnonApiKeySchema>;
|
|
9
|
+
/** Session ID: 16 hex chars (deterministic, derived from API key + time window). */
|
|
10
|
+
declare const SessionIdSchema: z.core.$ZodBranded<z.ZodString, "SessionId", "out">;
|
|
11
|
+
type SessionId = z.infer<typeof SessionIdSchema>;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* SDK-specific enums.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/** Diagnostic codes the SDK can report during health checks. */
|
|
18
|
+
declare const SdkDiagnosticCodeSchema: z.ZodEnum<{
|
|
19
|
+
ingestion_unreachable: "ingestion_unreachable";
|
|
20
|
+
ingestion_auth_failed: "ingestion_auth_failed";
|
|
21
|
+
ingestion_rate_limited: "ingestion_rate_limited";
|
|
22
|
+
config_sync_failed: "config_sync_failed";
|
|
23
|
+
source_map_upload_failed: "source_map_upload_failed";
|
|
24
|
+
}>;
|
|
25
|
+
type SdkDiagnosticCode = z.infer<typeof SdkDiagnosticCodeSchema>;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* SDK configuration types.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
/** SDK capture configuration: which events to capture. */
|
|
32
|
+
declare const CaptureConfigSchema: z.ZodObject<{
|
|
33
|
+
requestBodies: z.ZodBoolean;
|
|
34
|
+
queryParamValues: z.ZodBoolean;
|
|
35
|
+
envVarValues: z.ZodBoolean;
|
|
36
|
+
fullConsoleOutput: z.ZodBoolean;
|
|
37
|
+
importGraph: z.ZodBoolean;
|
|
38
|
+
consoleErrors: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
39
|
+
}, z.core.$strip>;
|
|
40
|
+
type CaptureConfig = z.infer<typeof CaptureConfigSchema>;
|
|
41
|
+
/** Developer-facing config for registerGlasstrace(). */
|
|
42
|
+
declare const GlasstraceOptionsSchema: z.ZodObject<{
|
|
43
|
+
apiKey: z.ZodOptional<z.ZodString>;
|
|
44
|
+
endpoint: z.ZodOptional<z.ZodString>;
|
|
45
|
+
forceEnable: z.ZodOptional<z.ZodBoolean>;
|
|
46
|
+
verbose: z.ZodOptional<z.ZodBoolean>;
|
|
47
|
+
}, z.core.$strip>;
|
|
48
|
+
type GlasstraceOptions = z.infer<typeof GlasstraceOptionsSchema>;
|
|
49
|
+
/** All recognized SDK environment variables. */
|
|
50
|
+
declare const GlasstraceEnvVarsSchema: z.ZodObject<{
|
|
51
|
+
GLASSTRACE_API_KEY: z.ZodOptional<z.ZodString>;
|
|
52
|
+
GLASSTRACE_FORCE_ENABLE: z.ZodOptional<z.ZodString>;
|
|
53
|
+
GLASSTRACE_ENV: z.ZodOptional<z.ZodString>;
|
|
54
|
+
GLASSTRACE_COVERAGE_MAP: z.ZodOptional<z.ZodString>;
|
|
55
|
+
NODE_ENV: z.ZodOptional<z.ZodString>;
|
|
56
|
+
VERCEL_ENV: z.ZodOptional<z.ZodString>;
|
|
57
|
+
}, z.core.$strip>;
|
|
58
|
+
type GlasstraceEnvVars = z.infer<typeof GlasstraceEnvVarsSchema>;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Wire format types for SDK ↔ backend communication.
|
|
62
|
+
*
|
|
63
|
+
* These schemas define the request/response shapes for:
|
|
64
|
+
* - SDK initialization (POST /v1/sdk/init)
|
|
65
|
+
* - SDK health diagnostics (embedded in init requests)
|
|
66
|
+
* - Discovery endpoint (GET /__glasstrace/config)
|
|
67
|
+
* - Source map upload (POST /v1/source-maps)
|
|
68
|
+
*/
|
|
69
|
+
|
|
70
|
+
/** Test file import relationships, embedded in SDK init request. */
|
|
71
|
+
declare const ImportGraphPayloadSchema: z.ZodObject<{
|
|
72
|
+
buildHash: z.core.$ZodBranded<z.ZodString, "BuildHash", "out">;
|
|
73
|
+
graph: z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString>>;
|
|
74
|
+
}, z.core.$strip>;
|
|
75
|
+
type ImportGraphPayload = z.infer<typeof ImportGraphPayloadSchema>;
|
|
76
|
+
/** SDK health diagnostics included in init requests. */
|
|
77
|
+
declare const SdkHealthReportSchema: z.ZodObject<{
|
|
78
|
+
tracesExportedSinceLastInit: z.ZodNumber;
|
|
79
|
+
tracesDropped: z.ZodNumber;
|
|
80
|
+
initFailures: z.ZodNumber;
|
|
81
|
+
configAge: z.ZodNumber;
|
|
82
|
+
sdkVersion: z.ZodString;
|
|
83
|
+
}, z.core.$strip>;
|
|
84
|
+
type SdkHealthReport = z.infer<typeof SdkHealthReportSchema>;
|
|
85
|
+
/**
|
|
86
|
+
* Response from POST /v1/sdk/init.
|
|
87
|
+
*
|
|
88
|
+
* Note: SdkInitRequest is intentionally NOT in the protocol package.
|
|
89
|
+
* The request schema includes backend-specific types (TierLimits,
|
|
90
|
+
* SubscriptionStatus) that are not part of the public contract.
|
|
91
|
+
* The backend owns the request validation; the SDK only needs to
|
|
92
|
+
* understand the response.
|
|
93
|
+
*/
|
|
94
|
+
declare const SdkInitResponseSchema: z.ZodObject<{
|
|
95
|
+
config: z.ZodObject<{
|
|
96
|
+
requestBodies: z.ZodBoolean;
|
|
97
|
+
queryParamValues: z.ZodBoolean;
|
|
98
|
+
envVarValues: z.ZodBoolean;
|
|
99
|
+
fullConsoleOutput: z.ZodBoolean;
|
|
100
|
+
importGraph: z.ZodBoolean;
|
|
101
|
+
consoleErrors: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
102
|
+
}, z.core.$strip>;
|
|
103
|
+
subscriptionStatus: z.ZodString;
|
|
104
|
+
linkedAccountId: z.ZodOptional<z.ZodString>;
|
|
105
|
+
minimumSdkVersion: z.ZodString;
|
|
106
|
+
apiVersion: z.ZodString;
|
|
107
|
+
tierLimits: z.ZodObject<{
|
|
108
|
+
tracesPerMinute: z.ZodNumber;
|
|
109
|
+
storageTtlHours: z.ZodNumber;
|
|
110
|
+
maxTraceSizeBytes: z.ZodNumber;
|
|
111
|
+
maxConcurrentSessions: z.ZodNumber;
|
|
112
|
+
}, z.core.$strip>;
|
|
113
|
+
}, z.core.$strip>;
|
|
114
|
+
type SdkInitResponse = z.infer<typeof SdkInitResponseSchema>;
|
|
115
|
+
/** Response from POST /v1/source-maps. */
|
|
116
|
+
declare const SourceMapUploadResponseSchema: z.ZodObject<{
|
|
117
|
+
success: z.ZodLiteral<true>;
|
|
118
|
+
buildHash: z.core.$ZodBranded<z.ZodString, "BuildHash", "out">;
|
|
119
|
+
fileCount: z.ZodNumber;
|
|
120
|
+
totalSizeBytes: z.ZodNumber;
|
|
121
|
+
}, z.core.$strip>;
|
|
122
|
+
type SourceMapUploadResponse = z.infer<typeof SourceMapUploadResponseSchema>;
|
|
123
|
+
|
|
6
124
|
/**
|
|
7
125
|
* Internal SDK error class with a typed diagnostic code.
|
|
8
126
|
* Caught at the boundary and converted to a log message + diagnostic entry.
|
|
@@ -217,6 +335,7 @@ declare class GlasstraceExporter implements SpanExporter {
|
|
|
217
335
|
private readonly endpointUrl;
|
|
218
336
|
private readonly createDelegateFn;
|
|
219
337
|
private delegate;
|
|
338
|
+
private delegateKey;
|
|
220
339
|
private pendingBatches;
|
|
221
340
|
private pendingSpanCount;
|
|
222
341
|
private overflowLogged;
|
|
@@ -232,22 +351,30 @@ declare class GlasstraceExporter implements SpanExporter {
|
|
|
232
351
|
/**
|
|
233
352
|
* Enriches a ReadableSpan with all glasstrace.* attributes.
|
|
234
353
|
* Returns a new ReadableSpan wrapper; the original span is not mutated.
|
|
235
|
-
*
|
|
236
|
-
*
|
|
354
|
+
*
|
|
355
|
+
* External function calls (getSessionId, deriveErrorCategory,
|
|
356
|
+
* deriveOrmProvider, classifyFetchTarget) are individually guarded so a
|
|
357
|
+
* failure in one does not prevent the remaining attributes from being set.
|
|
358
|
+
* On total failure, returns the original span unchanged.
|
|
237
359
|
*/
|
|
238
360
|
private enrichSpan;
|
|
239
361
|
/**
|
|
240
362
|
* Lazily creates the delegate OTLP exporter once the API key is resolved.
|
|
363
|
+
* Recreates the delegate if the key has changed (e.g., after key rotation)
|
|
364
|
+
* so the Authorization header stays current.
|
|
241
365
|
*/
|
|
242
366
|
private ensureDelegate;
|
|
243
367
|
/**
|
|
244
|
-
* Buffers
|
|
368
|
+
* Buffers raw (unenriched) spans while the API key is pending.
|
|
245
369
|
* Evicts oldest batches if the buffer exceeds MAX_PENDING_SPANS.
|
|
370
|
+
* Re-checks the key after buffering to close the race window where
|
|
371
|
+
* the key resolves between the caller's check and this buffer call.
|
|
246
372
|
*/
|
|
247
373
|
private bufferSpans;
|
|
248
374
|
/**
|
|
249
375
|
* Flushes all buffered spans through the delegate exporter.
|
|
250
|
-
*
|
|
376
|
+
* Enriches spans at flush time (not buffer time) so that session IDs
|
|
377
|
+
* are computed with the resolved API key instead of the "pending" sentinel.
|
|
251
378
|
*/
|
|
252
379
|
private flushPending;
|
|
253
380
|
}
|
|
@@ -325,6 +452,29 @@ declare function computeBuildHash(maps?: SourceMapEntry[]): Promise<string>;
|
|
|
325
452
|
*/
|
|
326
453
|
declare function uploadSourceMaps(apiKey: string, endpoint: string, buildHash: string, maps: SourceMapEntry[]): Promise<SourceMapUploadResponse>;
|
|
327
454
|
|
|
455
|
+
/**
|
|
456
|
+
* Records an error as a span event on the currently active OTel span.
|
|
457
|
+
*
|
|
458
|
+
* Works regardless of the `consoleErrors` configuration — this is an
|
|
459
|
+
* explicit, opt-in API for manual error reporting. If no span is active
|
|
460
|
+
* or OTel is not available, the call is silently ignored.
|
|
461
|
+
*
|
|
462
|
+
* @param error - The error to capture. Accepts `Error` objects, strings, or any value.
|
|
463
|
+
*
|
|
464
|
+
* @example
|
|
465
|
+
* ```ts
|
|
466
|
+
* import { captureError } from "@glasstrace/sdk";
|
|
467
|
+
*
|
|
468
|
+
* try {
|
|
469
|
+
* await riskyOperation();
|
|
470
|
+
* } catch (err) {
|
|
471
|
+
* captureError(err);
|
|
472
|
+
* // handle error normally...
|
|
473
|
+
* }
|
|
474
|
+
* ```
|
|
475
|
+
*/
|
|
476
|
+
declare function captureError(error: unknown): void;
|
|
477
|
+
|
|
328
478
|
/**
|
|
329
479
|
* Discovers test files by scanning the project directory for conventional
|
|
330
480
|
* test file patterns. Also reads vitest/jest config files for custom include
|
|
@@ -354,4 +504,4 @@ declare function extractImports(fileContent: string): string[];
|
|
|
354
504
|
*/
|
|
355
505
|
declare function buildImportGraph(projectRoot: string): Promise<ImportGraphPayload>;
|
|
356
506
|
|
|
357
|
-
export { type FetchTarget, GlasstraceExporter, type GlasstraceExporterOptions, GlasstraceSpanProcessor, type ResolvedConfig, SdkError, SessionManager, type SourceMapEntry, buildImportGraph, classifyFetchTarget, collectSourceMaps, computeBuildHash, createDiscoveryHandler, deriveSessionId, discoverTestFiles, extractImports, getActiveConfig, getDateString, getDiscoveryHandler, getOrCreateAnonKey, getOrigin, isAnonymousMode, isProductionDisabled, loadCachedConfig, performInit, readAnonKey, readEnvVars, registerGlasstrace, resolveConfig, saveCachedConfig, sendInitRequest, uploadSourceMaps, withGlasstraceConfig };
|
|
507
|
+
export { type FetchTarget, GlasstraceExporter, type GlasstraceExporterOptions, GlasstraceSpanProcessor, type ResolvedConfig, SdkError, SessionManager, type SourceMapEntry, buildImportGraph, captureError, classifyFetchTarget, collectSourceMaps, computeBuildHash, createDiscoveryHandler, deriveSessionId, discoverTestFiles, extractImports, getActiveConfig, getDateString, getDiscoveryHandler, getOrCreateAnonKey, getOrigin, isAnonymousMode, isProductionDisabled, loadCachedConfig, performInit, readAnonKey, readEnvVars, registerGlasstrace, resolveConfig, saveCachedConfig, sendInitRequest, uploadSourceMaps, withGlasstraceConfig };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,126 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as z from './v4/classic/external.cjs';
|
|
2
2
|
import { Context } from '@opentelemetry/api';
|
|
3
3
|
import { SpanProcessor, Span, ReadableSpan, SpanExporter } from '@opentelemetry/sdk-trace-base';
|
|
4
4
|
import { ExportResult } from '@opentelemetry/core';
|
|
5
5
|
|
|
6
|
+
/** Anonymous API key: `gt_anon_` + 48 hex chars. */
|
|
7
|
+
declare const AnonApiKeySchema: z.core.$ZodBranded<z.ZodString, "AnonApiKey", "out">;
|
|
8
|
+
type AnonApiKey = z.infer<typeof AnonApiKeySchema>;
|
|
9
|
+
/** Session ID: 16 hex chars (deterministic, derived from API key + time window). */
|
|
10
|
+
declare const SessionIdSchema: z.core.$ZodBranded<z.ZodString, "SessionId", "out">;
|
|
11
|
+
type SessionId = z.infer<typeof SessionIdSchema>;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* SDK-specific enums.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/** Diagnostic codes the SDK can report during health checks. */
|
|
18
|
+
declare const SdkDiagnosticCodeSchema: z.ZodEnum<{
|
|
19
|
+
ingestion_unreachable: "ingestion_unreachable";
|
|
20
|
+
ingestion_auth_failed: "ingestion_auth_failed";
|
|
21
|
+
ingestion_rate_limited: "ingestion_rate_limited";
|
|
22
|
+
config_sync_failed: "config_sync_failed";
|
|
23
|
+
source_map_upload_failed: "source_map_upload_failed";
|
|
24
|
+
}>;
|
|
25
|
+
type SdkDiagnosticCode = z.infer<typeof SdkDiagnosticCodeSchema>;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* SDK configuration types.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
/** SDK capture configuration: which events to capture. */
|
|
32
|
+
declare const CaptureConfigSchema: z.ZodObject<{
|
|
33
|
+
requestBodies: z.ZodBoolean;
|
|
34
|
+
queryParamValues: z.ZodBoolean;
|
|
35
|
+
envVarValues: z.ZodBoolean;
|
|
36
|
+
fullConsoleOutput: z.ZodBoolean;
|
|
37
|
+
importGraph: z.ZodBoolean;
|
|
38
|
+
consoleErrors: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
39
|
+
}, z.core.$strip>;
|
|
40
|
+
type CaptureConfig = z.infer<typeof CaptureConfigSchema>;
|
|
41
|
+
/** Developer-facing config for registerGlasstrace(). */
|
|
42
|
+
declare const GlasstraceOptionsSchema: z.ZodObject<{
|
|
43
|
+
apiKey: z.ZodOptional<z.ZodString>;
|
|
44
|
+
endpoint: z.ZodOptional<z.ZodString>;
|
|
45
|
+
forceEnable: z.ZodOptional<z.ZodBoolean>;
|
|
46
|
+
verbose: z.ZodOptional<z.ZodBoolean>;
|
|
47
|
+
}, z.core.$strip>;
|
|
48
|
+
type GlasstraceOptions = z.infer<typeof GlasstraceOptionsSchema>;
|
|
49
|
+
/** All recognized SDK environment variables. */
|
|
50
|
+
declare const GlasstraceEnvVarsSchema: z.ZodObject<{
|
|
51
|
+
GLASSTRACE_API_KEY: z.ZodOptional<z.ZodString>;
|
|
52
|
+
GLASSTRACE_FORCE_ENABLE: z.ZodOptional<z.ZodString>;
|
|
53
|
+
GLASSTRACE_ENV: z.ZodOptional<z.ZodString>;
|
|
54
|
+
GLASSTRACE_COVERAGE_MAP: z.ZodOptional<z.ZodString>;
|
|
55
|
+
NODE_ENV: z.ZodOptional<z.ZodString>;
|
|
56
|
+
VERCEL_ENV: z.ZodOptional<z.ZodString>;
|
|
57
|
+
}, z.core.$strip>;
|
|
58
|
+
type GlasstraceEnvVars = z.infer<typeof GlasstraceEnvVarsSchema>;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Wire format types for SDK ↔ backend communication.
|
|
62
|
+
*
|
|
63
|
+
* These schemas define the request/response shapes for:
|
|
64
|
+
* - SDK initialization (POST /v1/sdk/init)
|
|
65
|
+
* - SDK health diagnostics (embedded in init requests)
|
|
66
|
+
* - Discovery endpoint (GET /__glasstrace/config)
|
|
67
|
+
* - Source map upload (POST /v1/source-maps)
|
|
68
|
+
*/
|
|
69
|
+
|
|
70
|
+
/** Test file import relationships, embedded in SDK init request. */
|
|
71
|
+
declare const ImportGraphPayloadSchema: z.ZodObject<{
|
|
72
|
+
buildHash: z.core.$ZodBranded<z.ZodString, "BuildHash", "out">;
|
|
73
|
+
graph: z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString>>;
|
|
74
|
+
}, z.core.$strip>;
|
|
75
|
+
type ImportGraphPayload = z.infer<typeof ImportGraphPayloadSchema>;
|
|
76
|
+
/** SDK health diagnostics included in init requests. */
|
|
77
|
+
declare const SdkHealthReportSchema: z.ZodObject<{
|
|
78
|
+
tracesExportedSinceLastInit: z.ZodNumber;
|
|
79
|
+
tracesDropped: z.ZodNumber;
|
|
80
|
+
initFailures: z.ZodNumber;
|
|
81
|
+
configAge: z.ZodNumber;
|
|
82
|
+
sdkVersion: z.ZodString;
|
|
83
|
+
}, z.core.$strip>;
|
|
84
|
+
type SdkHealthReport = z.infer<typeof SdkHealthReportSchema>;
|
|
85
|
+
/**
|
|
86
|
+
* Response from POST /v1/sdk/init.
|
|
87
|
+
*
|
|
88
|
+
* Note: SdkInitRequest is intentionally NOT in the protocol package.
|
|
89
|
+
* The request schema includes backend-specific types (TierLimits,
|
|
90
|
+
* SubscriptionStatus) that are not part of the public contract.
|
|
91
|
+
* The backend owns the request validation; the SDK only needs to
|
|
92
|
+
* understand the response.
|
|
93
|
+
*/
|
|
94
|
+
declare const SdkInitResponseSchema: z.ZodObject<{
|
|
95
|
+
config: z.ZodObject<{
|
|
96
|
+
requestBodies: z.ZodBoolean;
|
|
97
|
+
queryParamValues: z.ZodBoolean;
|
|
98
|
+
envVarValues: z.ZodBoolean;
|
|
99
|
+
fullConsoleOutput: z.ZodBoolean;
|
|
100
|
+
importGraph: z.ZodBoolean;
|
|
101
|
+
consoleErrors: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
102
|
+
}, z.core.$strip>;
|
|
103
|
+
subscriptionStatus: z.ZodString;
|
|
104
|
+
linkedAccountId: z.ZodOptional<z.ZodString>;
|
|
105
|
+
minimumSdkVersion: z.ZodString;
|
|
106
|
+
apiVersion: z.ZodString;
|
|
107
|
+
tierLimits: z.ZodObject<{
|
|
108
|
+
tracesPerMinute: z.ZodNumber;
|
|
109
|
+
storageTtlHours: z.ZodNumber;
|
|
110
|
+
maxTraceSizeBytes: z.ZodNumber;
|
|
111
|
+
maxConcurrentSessions: z.ZodNumber;
|
|
112
|
+
}, z.core.$strip>;
|
|
113
|
+
}, z.core.$strip>;
|
|
114
|
+
type SdkInitResponse = z.infer<typeof SdkInitResponseSchema>;
|
|
115
|
+
/** Response from POST /v1/source-maps. */
|
|
116
|
+
declare const SourceMapUploadResponseSchema: z.ZodObject<{
|
|
117
|
+
success: z.ZodLiteral<true>;
|
|
118
|
+
buildHash: z.core.$ZodBranded<z.ZodString, "BuildHash", "out">;
|
|
119
|
+
fileCount: z.ZodNumber;
|
|
120
|
+
totalSizeBytes: z.ZodNumber;
|
|
121
|
+
}, z.core.$strip>;
|
|
122
|
+
type SourceMapUploadResponse = z.infer<typeof SourceMapUploadResponseSchema>;
|
|
123
|
+
|
|
6
124
|
/**
|
|
7
125
|
* Internal SDK error class with a typed diagnostic code.
|
|
8
126
|
* Caught at the boundary and converted to a log message + diagnostic entry.
|
|
@@ -217,6 +335,7 @@ declare class GlasstraceExporter implements SpanExporter {
|
|
|
217
335
|
private readonly endpointUrl;
|
|
218
336
|
private readonly createDelegateFn;
|
|
219
337
|
private delegate;
|
|
338
|
+
private delegateKey;
|
|
220
339
|
private pendingBatches;
|
|
221
340
|
private pendingSpanCount;
|
|
222
341
|
private overflowLogged;
|
|
@@ -232,22 +351,30 @@ declare class GlasstraceExporter implements SpanExporter {
|
|
|
232
351
|
/**
|
|
233
352
|
* Enriches a ReadableSpan with all glasstrace.* attributes.
|
|
234
353
|
* Returns a new ReadableSpan wrapper; the original span is not mutated.
|
|
235
|
-
*
|
|
236
|
-
*
|
|
354
|
+
*
|
|
355
|
+
* External function calls (getSessionId, deriveErrorCategory,
|
|
356
|
+
* deriveOrmProvider, classifyFetchTarget) are individually guarded so a
|
|
357
|
+
* failure in one does not prevent the remaining attributes from being set.
|
|
358
|
+
* On total failure, returns the original span unchanged.
|
|
237
359
|
*/
|
|
238
360
|
private enrichSpan;
|
|
239
361
|
/**
|
|
240
362
|
* Lazily creates the delegate OTLP exporter once the API key is resolved.
|
|
363
|
+
* Recreates the delegate if the key has changed (e.g., after key rotation)
|
|
364
|
+
* so the Authorization header stays current.
|
|
241
365
|
*/
|
|
242
366
|
private ensureDelegate;
|
|
243
367
|
/**
|
|
244
|
-
* Buffers
|
|
368
|
+
* Buffers raw (unenriched) spans while the API key is pending.
|
|
245
369
|
* Evicts oldest batches if the buffer exceeds MAX_PENDING_SPANS.
|
|
370
|
+
* Re-checks the key after buffering to close the race window where
|
|
371
|
+
* the key resolves between the caller's check and this buffer call.
|
|
246
372
|
*/
|
|
247
373
|
private bufferSpans;
|
|
248
374
|
/**
|
|
249
375
|
* Flushes all buffered spans through the delegate exporter.
|
|
250
|
-
*
|
|
376
|
+
* Enriches spans at flush time (not buffer time) so that session IDs
|
|
377
|
+
* are computed with the resolved API key instead of the "pending" sentinel.
|
|
251
378
|
*/
|
|
252
379
|
private flushPending;
|
|
253
380
|
}
|
|
@@ -325,6 +452,29 @@ declare function computeBuildHash(maps?: SourceMapEntry[]): Promise<string>;
|
|
|
325
452
|
*/
|
|
326
453
|
declare function uploadSourceMaps(apiKey: string, endpoint: string, buildHash: string, maps: SourceMapEntry[]): Promise<SourceMapUploadResponse>;
|
|
327
454
|
|
|
455
|
+
/**
|
|
456
|
+
* Records an error as a span event on the currently active OTel span.
|
|
457
|
+
*
|
|
458
|
+
* Works regardless of the `consoleErrors` configuration — this is an
|
|
459
|
+
* explicit, opt-in API for manual error reporting. If no span is active
|
|
460
|
+
* or OTel is not available, the call is silently ignored.
|
|
461
|
+
*
|
|
462
|
+
* @param error - The error to capture. Accepts `Error` objects, strings, or any value.
|
|
463
|
+
*
|
|
464
|
+
* @example
|
|
465
|
+
* ```ts
|
|
466
|
+
* import { captureError } from "@glasstrace/sdk";
|
|
467
|
+
*
|
|
468
|
+
* try {
|
|
469
|
+
* await riskyOperation();
|
|
470
|
+
* } catch (err) {
|
|
471
|
+
* captureError(err);
|
|
472
|
+
* // handle error normally...
|
|
473
|
+
* }
|
|
474
|
+
* ```
|
|
475
|
+
*/
|
|
476
|
+
declare function captureError(error: unknown): void;
|
|
477
|
+
|
|
328
478
|
/**
|
|
329
479
|
* Discovers test files by scanning the project directory for conventional
|
|
330
480
|
* test file patterns. Also reads vitest/jest config files for custom include
|
|
@@ -354,4 +504,4 @@ declare function extractImports(fileContent: string): string[];
|
|
|
354
504
|
*/
|
|
355
505
|
declare function buildImportGraph(projectRoot: string): Promise<ImportGraphPayload>;
|
|
356
506
|
|
|
357
|
-
export { type FetchTarget, GlasstraceExporter, type GlasstraceExporterOptions, GlasstraceSpanProcessor, type ResolvedConfig, SdkError, SessionManager, type SourceMapEntry, buildImportGraph, classifyFetchTarget, collectSourceMaps, computeBuildHash, createDiscoveryHandler, deriveSessionId, discoverTestFiles, extractImports, getActiveConfig, getDateString, getDiscoveryHandler, getOrCreateAnonKey, getOrigin, isAnonymousMode, isProductionDisabled, loadCachedConfig, performInit, readAnonKey, readEnvVars, registerGlasstrace, resolveConfig, saveCachedConfig, sendInitRequest, uploadSourceMaps, withGlasstraceConfig };
|
|
507
|
+
export { type FetchTarget, GlasstraceExporter, type GlasstraceExporterOptions, GlasstraceSpanProcessor, type ResolvedConfig, SdkError, SessionManager, type SourceMapEntry, buildImportGraph, captureError, classifyFetchTarget, collectSourceMaps, computeBuildHash, createDiscoveryHandler, deriveSessionId, discoverTestFiles, extractImports, getActiveConfig, getDateString, getDiscoveryHandler, getOrCreateAnonKey, getOrigin, isAnonymousMode, isProductionDisabled, loadCachedConfig, performInit, readAnonKey, readEnvVars, registerGlasstrace, resolveConfig, saveCachedConfig, sendInitRequest, uploadSourceMaps, withGlasstraceConfig };
|