@glasstrace/sdk 0.20.0 → 1.0.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 +37 -5
- package/dist/chunk-3TU62WD6.js +142 -0
- package/dist/chunk-3TU62WD6.js.map +1 -0
- package/dist/chunk-67RIOAXV.js +105 -0
- package/dist/chunk-67RIOAXV.js.map +1 -0
- package/dist/{chunk-VN3GZDV6.js → chunk-7PDDBLST.js} +4 -141
- package/dist/chunk-7PDDBLST.js.map +1 -0
- package/dist/chunk-BT2OCXCG.js +178 -0
- package/dist/chunk-BT2OCXCG.js.map +1 -0
- package/dist/chunk-D3WYZBQA.js +4547 -0
- package/dist/chunk-D3WYZBQA.js.map +1 -0
- package/dist/{chunk-F2TZRBEH.js → chunk-DO2YPMQ5.js} +9 -181
- package/dist/chunk-DO2YPMQ5.js.map +1 -0
- package/dist/{chunk-YPXW2TN3.js → chunk-IP4NMDJK.js} +2 -2
- package/dist/{chunk-6JRI4OGB.js → chunk-LU3PPAOQ.js} +5 -3
- package/dist/{chunk-6JRI4OGB.js.map → chunk-LU3PPAOQ.js.map} +1 -1
- package/dist/{chunk-5N2IR4EO.js → chunk-TQ54WLCZ.js} +1 -1
- package/dist/{chunk-5N2IR4EO.js.map → chunk-TQ54WLCZ.js.map} +1 -1
- package/dist/cli/init.cjs +5 -3
- package/dist/cli/init.cjs.map +1 -1
- package/dist/cli/init.js +8 -6
- package/dist/cli/init.js.map +1 -1
- package/dist/cli/mcp-add.cjs.map +1 -1
- package/dist/cli/mcp-add.js +2 -2
- package/dist/cli/uninit.cjs +3 -1
- package/dist/cli/uninit.cjs.map +1 -1
- package/dist/cli/uninit.js +2 -2
- package/dist/edge-entry-CFq085RZ.d.ts +130 -0
- package/dist/edge-entry-DYl05SJ-.d.cts +130 -0
- package/dist/edge-entry.cjs +14839 -0
- package/dist/edge-entry.cjs.map +1 -0
- package/dist/edge-entry.d.cts +6 -0
- package/dist/edge-entry.d.ts +6 -0
- package/dist/edge-entry.js +14 -0
- package/dist/index.cjs +38 -244
- package/dist/index.cjs.map +1 -1
- package/dist/index.d-CYYe3PxB.d.cts +191 -0
- package/dist/index.d-CYYe3PxB.d.ts +191 -0
- package/dist/index.d.cts +8 -461
- package/dist/index.d.ts +8 -461
- package/dist/index.js +25 -4636
- package/dist/index.js.map +1 -1
- package/dist/node-entry.cjs +22481 -0
- package/dist/node-entry.cjs.map +1 -0
- package/dist/node-entry.d.cts +10 -0
- package/dist/node-entry.d.ts +10 -0
- package/dist/node-entry.js +100 -0
- package/dist/node-entry.js.map +1 -0
- package/dist/node-subpath.cjs +14506 -0
- package/dist/node-subpath.cjs.map +1 -0
- package/dist/node-subpath.d.cts +132 -0
- package/dist/node-subpath.d.ts +132 -0
- package/dist/node-subpath.js +31 -0
- package/dist/node-subpath.js.map +1 -0
- package/dist/{source-map-uploader-VPDZWWM2.js → source-map-uploader-ZHA3B4GE.js} +4 -3
- package/dist/source-map-uploader-ZHA3B4GE.js.map +1 -0
- package/package.json +13 -1
- package/dist/chunk-F2TZRBEH.js.map +0 -1
- package/dist/chunk-VN3GZDV6.js.map +0 -1
- /package/dist/{chunk-YPXW2TN3.js.map → chunk-IP4NMDJK.js.map} +0 -0
- /package/dist/{source-map-uploader-VPDZWWM2.js.map → edge-entry.js.map} +0 -0
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { c as SdkDiagnosticCode, e as SessionId, C as CaptureConfig } from './index.d-CYYe3PxB.js';
|
|
2
|
+
import { ReadableSpan } from './export/ReadableSpan';
|
|
3
|
+
import { Span } from './Span';
|
|
4
|
+
import { SpanProcessor } from './SpanProcessor';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Internal SDK error class with a typed diagnostic code.
|
|
8
|
+
* Caught at the boundary and converted to a log message + diagnostic entry.
|
|
9
|
+
* Never thrown to the developer.
|
|
10
|
+
*/
|
|
11
|
+
declare class SdkError extends Error {
|
|
12
|
+
readonly code: SdkDiagnosticCode;
|
|
13
|
+
constructor(code: SdkDiagnosticCode, message: string, cause?: Error);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Returns the origin string for the current process.
|
|
18
|
+
* If GLASSTRACE_ENV is set, returns that value.
|
|
19
|
+
* Otherwise returns `localhost:{PORT}` (PORT defaults to 3000).
|
|
20
|
+
*
|
|
21
|
+
* @returns The origin string used as a session derivation input.
|
|
22
|
+
*/
|
|
23
|
+
declare function getOrigin(): string;
|
|
24
|
+
/**
|
|
25
|
+
* Returns the current UTC date as a YYYY-MM-DD string.
|
|
26
|
+
*
|
|
27
|
+
* @returns The UTC date formatted as "YYYY-MM-DD".
|
|
28
|
+
*/
|
|
29
|
+
declare function getDateString(): string;
|
|
30
|
+
/**
|
|
31
|
+
* Tracks the current session state with 4-hour window tracking.
|
|
32
|
+
* Instantiated once by the orchestrator.
|
|
33
|
+
*/
|
|
34
|
+
declare class SessionManager {
|
|
35
|
+
private windowIndex;
|
|
36
|
+
private lastActivityTimestamp;
|
|
37
|
+
private lastDate;
|
|
38
|
+
private lastApiKey;
|
|
39
|
+
private currentSessionId;
|
|
40
|
+
/**
|
|
41
|
+
* Returns the current session ID, deriving a new one if:
|
|
42
|
+
* - More than 4 hours have elapsed since last activity
|
|
43
|
+
* - The UTC date has changed (resets window index to 0)
|
|
44
|
+
* - The API key has changed (e.g., deferred anonymous key swap)
|
|
45
|
+
* - This is the first call
|
|
46
|
+
*
|
|
47
|
+
* @param apiKey - The project's API key used in session derivation.
|
|
48
|
+
* @returns The current or newly derived SessionId.
|
|
49
|
+
*/
|
|
50
|
+
getSessionId(apiKey: string): SessionId;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Lightweight SpanProcessor that delegates to a wrapped processor.
|
|
55
|
+
*
|
|
56
|
+
* All glasstrace.* attribute enrichment has been moved to {@link GlasstraceExporter}
|
|
57
|
+
* (see enriching-exporter.ts), which enriches spans at export time. This resolves:
|
|
58
|
+
* - Cold-start spans are buffered in the exporter, not dropped
|
|
59
|
+
* - Vercel's CompositeSpanProcessor skips onEnding(); the exporter doesn't need it
|
|
60
|
+
* - Session ID is computed at export time with the resolved API key
|
|
61
|
+
*
|
|
62
|
+
* This class is retained for backward compatibility. New code should use
|
|
63
|
+
* GlasstraceExporter directly.
|
|
64
|
+
*
|
|
65
|
+
* @deprecated Use GlasstraceExporter for span enrichment. This processor is now a pass-through.
|
|
66
|
+
*/
|
|
67
|
+
declare class GlasstraceSpanProcessor implements SpanProcessor {
|
|
68
|
+
private readonly wrappedProcessor;
|
|
69
|
+
constructor(wrappedProcessor: SpanProcessor, _sessionManager?: SessionManager, _apiKey?: string | (() => string), _getConfig?: () => CaptureConfig, _environment?: string);
|
|
70
|
+
onStart(span: Span, parentContext: Parameters<SpanProcessor["onStart"]>[1]): void;
|
|
71
|
+
onEnd(readableSpan: ReadableSpan): void;
|
|
72
|
+
shutdown(): Promise<void>;
|
|
73
|
+
forceFlush(): Promise<void>;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Minimal Fetch-API `Headers`-like interface supporting case-insensitive
|
|
78
|
+
* single-value lookup. Matches `Headers` from `undici` / the Web Fetch API.
|
|
79
|
+
*/
|
|
80
|
+
interface FetchHeadersLike {
|
|
81
|
+
get(name: string): string | null;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Minimal Node `IncomingMessage.headers`-like shape: a dictionary mapping
|
|
85
|
+
* (typically lower-cased) header names to a value, a list of values, or
|
|
86
|
+
* `undefined`.
|
|
87
|
+
*/
|
|
88
|
+
type NodeHeadersLike = Record<string, string | string[] | undefined>;
|
|
89
|
+
/**
|
|
90
|
+
* Accepted request shape for {@link captureCorrelationId}. Intentionally
|
|
91
|
+
* loose so callers can pass either a Fetch `Request` (or `NextRequest`)
|
|
92
|
+
* or a Node `IncomingMessage` without adapting the type.
|
|
93
|
+
*/
|
|
94
|
+
interface CorrelationIdRequest {
|
|
95
|
+
headers: FetchHeadersLike | NodeHeadersLike | undefined;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Captures the Glasstrace correlation ID header (`x-gt-cid`) from an
|
|
99
|
+
* incoming request and materializes it as the
|
|
100
|
+
* `glasstrace.correlation.id` attribute on the currently active OTel span
|
|
101
|
+
* (DISC-1253).
|
|
102
|
+
*
|
|
103
|
+
* The SDK does not own any HTTP instrumentation, so it cannot read this
|
|
104
|
+
* header itself. Users opt in by calling this helper from a hook that
|
|
105
|
+
* runs inside the request's OTel context — typically a Next.js
|
|
106
|
+
* `middleware.ts` or a custom server request handler.
|
|
107
|
+
*
|
|
108
|
+
* The function is intentionally forgiving:
|
|
109
|
+
* - No active span → no-op.
|
|
110
|
+
* - Missing / empty header → no-op.
|
|
111
|
+
* - Array header values (Node IncomingMessage) → the first non-empty
|
|
112
|
+
* value is used; subsequent values are ignored because a correlation
|
|
113
|
+
* ID is a single logical value.
|
|
114
|
+
* - Malformed or unexpected `headers` shapes → caught and ignored; the
|
|
115
|
+
* helper never throws.
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* ```ts
|
|
119
|
+
* // Next.js middleware.ts
|
|
120
|
+
* import { captureCorrelationId } from "@glasstrace/sdk";
|
|
121
|
+
*
|
|
122
|
+
* export function middleware(req: Request) {
|
|
123
|
+
* captureCorrelationId(req);
|
|
124
|
+
* return NextResponse.next();
|
|
125
|
+
* }
|
|
126
|
+
* ```
|
|
127
|
+
*/
|
|
128
|
+
declare function captureCorrelationId(req: CorrelationIdRequest | null | undefined): void;
|
|
129
|
+
|
|
130
|
+
export { type CorrelationIdRequest as C, GlasstraceSpanProcessor as G, SdkError as S, SessionManager as a, getOrigin as b, captureCorrelationId as c, getDateString as g };
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { c as SdkDiagnosticCode, e as SessionId, C as CaptureConfig } from './index.d-CYYe3PxB.cjs';
|
|
2
|
+
import { ReadableSpan } from './export/ReadableSpan';
|
|
3
|
+
import { Span } from './Span';
|
|
4
|
+
import { SpanProcessor } from './SpanProcessor';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Internal SDK error class with a typed diagnostic code.
|
|
8
|
+
* Caught at the boundary and converted to a log message + diagnostic entry.
|
|
9
|
+
* Never thrown to the developer.
|
|
10
|
+
*/
|
|
11
|
+
declare class SdkError extends Error {
|
|
12
|
+
readonly code: SdkDiagnosticCode;
|
|
13
|
+
constructor(code: SdkDiagnosticCode, message: string, cause?: Error);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Returns the origin string for the current process.
|
|
18
|
+
* If GLASSTRACE_ENV is set, returns that value.
|
|
19
|
+
* Otherwise returns `localhost:{PORT}` (PORT defaults to 3000).
|
|
20
|
+
*
|
|
21
|
+
* @returns The origin string used as a session derivation input.
|
|
22
|
+
*/
|
|
23
|
+
declare function getOrigin(): string;
|
|
24
|
+
/**
|
|
25
|
+
* Returns the current UTC date as a YYYY-MM-DD string.
|
|
26
|
+
*
|
|
27
|
+
* @returns The UTC date formatted as "YYYY-MM-DD".
|
|
28
|
+
*/
|
|
29
|
+
declare function getDateString(): string;
|
|
30
|
+
/**
|
|
31
|
+
* Tracks the current session state with 4-hour window tracking.
|
|
32
|
+
* Instantiated once by the orchestrator.
|
|
33
|
+
*/
|
|
34
|
+
declare class SessionManager {
|
|
35
|
+
private windowIndex;
|
|
36
|
+
private lastActivityTimestamp;
|
|
37
|
+
private lastDate;
|
|
38
|
+
private lastApiKey;
|
|
39
|
+
private currentSessionId;
|
|
40
|
+
/**
|
|
41
|
+
* Returns the current session ID, deriving a new one if:
|
|
42
|
+
* - More than 4 hours have elapsed since last activity
|
|
43
|
+
* - The UTC date has changed (resets window index to 0)
|
|
44
|
+
* - The API key has changed (e.g., deferred anonymous key swap)
|
|
45
|
+
* - This is the first call
|
|
46
|
+
*
|
|
47
|
+
* @param apiKey - The project's API key used in session derivation.
|
|
48
|
+
* @returns The current or newly derived SessionId.
|
|
49
|
+
*/
|
|
50
|
+
getSessionId(apiKey: string): SessionId;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Lightweight SpanProcessor that delegates to a wrapped processor.
|
|
55
|
+
*
|
|
56
|
+
* All glasstrace.* attribute enrichment has been moved to {@link GlasstraceExporter}
|
|
57
|
+
* (see enriching-exporter.ts), which enriches spans at export time. This resolves:
|
|
58
|
+
* - Cold-start spans are buffered in the exporter, not dropped
|
|
59
|
+
* - Vercel's CompositeSpanProcessor skips onEnding(); the exporter doesn't need it
|
|
60
|
+
* - Session ID is computed at export time with the resolved API key
|
|
61
|
+
*
|
|
62
|
+
* This class is retained for backward compatibility. New code should use
|
|
63
|
+
* GlasstraceExporter directly.
|
|
64
|
+
*
|
|
65
|
+
* @deprecated Use GlasstraceExporter for span enrichment. This processor is now a pass-through.
|
|
66
|
+
*/
|
|
67
|
+
declare class GlasstraceSpanProcessor implements SpanProcessor {
|
|
68
|
+
private readonly wrappedProcessor;
|
|
69
|
+
constructor(wrappedProcessor: SpanProcessor, _sessionManager?: SessionManager, _apiKey?: string | (() => string), _getConfig?: () => CaptureConfig, _environment?: string);
|
|
70
|
+
onStart(span: Span, parentContext: Parameters<SpanProcessor["onStart"]>[1]): void;
|
|
71
|
+
onEnd(readableSpan: ReadableSpan): void;
|
|
72
|
+
shutdown(): Promise<void>;
|
|
73
|
+
forceFlush(): Promise<void>;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Minimal Fetch-API `Headers`-like interface supporting case-insensitive
|
|
78
|
+
* single-value lookup. Matches `Headers` from `undici` / the Web Fetch API.
|
|
79
|
+
*/
|
|
80
|
+
interface FetchHeadersLike {
|
|
81
|
+
get(name: string): string | null;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Minimal Node `IncomingMessage.headers`-like shape: a dictionary mapping
|
|
85
|
+
* (typically lower-cased) header names to a value, a list of values, or
|
|
86
|
+
* `undefined`.
|
|
87
|
+
*/
|
|
88
|
+
type NodeHeadersLike = Record<string, string | string[] | undefined>;
|
|
89
|
+
/**
|
|
90
|
+
* Accepted request shape for {@link captureCorrelationId}. Intentionally
|
|
91
|
+
* loose so callers can pass either a Fetch `Request` (or `NextRequest`)
|
|
92
|
+
* or a Node `IncomingMessage` without adapting the type.
|
|
93
|
+
*/
|
|
94
|
+
interface CorrelationIdRequest {
|
|
95
|
+
headers: FetchHeadersLike | NodeHeadersLike | undefined;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Captures the Glasstrace correlation ID header (`x-gt-cid`) from an
|
|
99
|
+
* incoming request and materializes it as the
|
|
100
|
+
* `glasstrace.correlation.id` attribute on the currently active OTel span
|
|
101
|
+
* (DISC-1253).
|
|
102
|
+
*
|
|
103
|
+
* The SDK does not own any HTTP instrumentation, so it cannot read this
|
|
104
|
+
* header itself. Users opt in by calling this helper from a hook that
|
|
105
|
+
* runs inside the request's OTel context — typically a Next.js
|
|
106
|
+
* `middleware.ts` or a custom server request handler.
|
|
107
|
+
*
|
|
108
|
+
* The function is intentionally forgiving:
|
|
109
|
+
* - No active span → no-op.
|
|
110
|
+
* - Missing / empty header → no-op.
|
|
111
|
+
* - Array header values (Node IncomingMessage) → the first non-empty
|
|
112
|
+
* value is used; subsequent values are ignored because a correlation
|
|
113
|
+
* ID is a single logical value.
|
|
114
|
+
* - Malformed or unexpected `headers` shapes → caught and ignored; the
|
|
115
|
+
* helper never throws.
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* ```ts
|
|
119
|
+
* // Next.js middleware.ts
|
|
120
|
+
* import { captureCorrelationId } from "@glasstrace/sdk";
|
|
121
|
+
*
|
|
122
|
+
* export function middleware(req: Request) {
|
|
123
|
+
* captureCorrelationId(req);
|
|
124
|
+
* return NextResponse.next();
|
|
125
|
+
* }
|
|
126
|
+
* ```
|
|
127
|
+
*/
|
|
128
|
+
declare function captureCorrelationId(req: CorrelationIdRequest | null | undefined): void;
|
|
129
|
+
|
|
130
|
+
export { type CorrelationIdRequest as C, GlasstraceSpanProcessor as G, SdkError as S, SessionManager as a, getOrigin as b, captureCorrelationId as c, getDateString as g };
|