@strada.sh/light 0.1.0 → 0.2.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/attrs.d.ts +6 -0
- package/dist/attrs.d.ts.map +1 -1
- package/dist/attrs.js +6 -0
- package/dist/index.d.ts +103 -21
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +419 -72
- package/package.json +1 -1
- package/src/attrs.ts +6 -0
- package/src/index.ts +534 -89
package/dist/attrs.d.ts
CHANGED
|
@@ -22,5 +22,11 @@ export declare const ATTR: {
|
|
|
22
22
|
readonly "exception.mechanism.type": "exception.mechanism.type";
|
|
23
23
|
readonly "exception.mechanism.handled": "exception.mechanism.handled";
|
|
24
24
|
readonly "exception.fingerprint": "exception.fingerprint";
|
|
25
|
+
readonly "session.id": "session.id";
|
|
26
|
+
readonly "url.path": "url.path";
|
|
27
|
+
readonly "url.query": "url.query";
|
|
28
|
+
readonly "url.full": "url.full";
|
|
29
|
+
readonly "http.request.header.referer": "http.request.header.referer";
|
|
30
|
+
readonly "pageview.source": "pageview.source";
|
|
25
31
|
};
|
|
26
32
|
//# sourceMappingURL=attrs.d.ts.map
|
package/dist/attrs.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attrs.d.ts","sourceRoot":"","sources":["../src/attrs.ts"],"names":[],"mappings":"AAAA,sFAAsF;AACtF,eAAO,MAAM,IAAI
|
|
1
|
+
{"version":3,"file":"attrs.d.ts","sourceRoot":"","sources":["../src/attrs.ts"],"names":[],"mappings":"AAAA,sFAAsF;AACtF,eAAO,MAAM,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6BP,CAAC"}
|
package/dist/attrs.js
CHANGED
|
@@ -22,4 +22,10 @@ export const ATTR = {
|
|
|
22
22
|
"exception.mechanism.type": "exception.mechanism.type",
|
|
23
23
|
"exception.mechanism.handled": "exception.mechanism.handled",
|
|
24
24
|
"exception.fingerprint": "exception.fingerprint",
|
|
25
|
+
"session.id": "session.id",
|
|
26
|
+
"url.path": "url.path",
|
|
27
|
+
"url.query": "url.query",
|
|
28
|
+
"url.full": "url.full",
|
|
29
|
+
"http.request.header.referer": "http.request.header.referer",
|
|
30
|
+
"pageview.source": "pageview.source",
|
|
25
31
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,23 +1,32 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `@strada.sh/light`: a zero-dependency,
|
|
2
|
+
* `@strada.sh/light`: a zero-dependency, explicit-only subset of `@strada.sh/sdk`.
|
|
3
3
|
*
|
|
4
4
|
* Switch by changing the import path. Same function names, same option
|
|
5
|
-
* names, same `otel_logs`
|
|
6
|
-
* `strada.user.identify`), so every Strada query
|
|
7
|
-
* light build does not support is not exported or
|
|
8
|
-
* that relies on it fails at compile time instead
|
|
9
|
-
* `index.test.ts` type-checks
|
|
10
|
-
* sync.
|
|
5
|
+
* names, same rows in `otel_logs` / `otel_traces` (`event.name`, `custom.*`,
|
|
6
|
+
* `exception.*`, `strada.user.identify`, `pageview`), so every Strada query
|
|
7
|
+
* works unchanged. What the light build does not support is not exported or
|
|
8
|
+
* not accepted, so a switch that relies on it fails at compile time instead
|
|
9
|
+
* of silently dropping data. `index.test.ts` type-checks every export against
|
|
10
|
+
* the full SDK to keep both in sync.
|
|
11
11
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* command args).
|
|
16
|
-
*
|
|
12
|
+
* Explicit only: nothing is captured unless you call it. `initStrada()`
|
|
13
|
+
* installs nothing global: no OTel providers, no process or window error
|
|
14
|
+
* handlers, no fetch patching, no resource detectors (no hostname, OS
|
|
15
|
+
* username, or command args). Records are built as OTLP JSON by hand and
|
|
16
|
+
* POSTed with `fetch` to `/v1/logs` and `/v1/traces`. The flush timer is
|
|
17
|
+
* unref'd, so call `flush()` before a short-lived process exits.
|
|
18
|
+
*
|
|
19
|
+
* Span parenting across `await` uses AsyncLocalStorage when the runtime
|
|
20
|
+
* exposes `process.getBuiltinModule` (Node 20.16+, Bun, Workers with
|
|
21
|
+
* nodejs_compat). Elsewhere (browsers) only synchronous nesting works, the
|
|
22
|
+
* same limitation as the full browser SDK.
|
|
17
23
|
*
|
|
18
24
|
* Every function follows "telemetry never throws": failures are returned as
|
|
19
|
-
* values and logged once with console.warn.
|
|
25
|
+
* values and logged once with console.warn. `startSpan()` rethrows the
|
|
26
|
+
* callback's own error, like the full SDK.
|
|
20
27
|
*/
|
|
28
|
+
export type AttributeValue = string | number | boolean;
|
|
29
|
+
export type Attributes = Record<string, AttributeValue>;
|
|
21
30
|
export interface StradaOptions {
|
|
22
31
|
/** Strada project identifier. Blank disables sending. */
|
|
23
32
|
projectId: string;
|
|
@@ -39,10 +48,20 @@ export interface StradaOptions {
|
|
|
39
48
|
releaseBranch?: string;
|
|
40
49
|
/** deployment.id resource attribute. Defaults to releaseCommit. */
|
|
41
50
|
deploymentId?: string;
|
|
42
|
-
/**
|
|
51
|
+
/** Drop errors whose message matches any of these patterns */
|
|
52
|
+
ignoreErrors?: Array<string | RegExp>;
|
|
53
|
+
/** Drop errors whose stack trace matches any of these patterns */
|
|
54
|
+
denyUrls?: Array<string | RegExp>;
|
|
55
|
+
/** Return null to drop an error before it is sent */
|
|
56
|
+
beforeSend?: (error: Error) => Error | null;
|
|
57
|
+
/** Current user id, sent as user.id on every event, log, error, and span. */
|
|
43
58
|
userId?: string | (() => string | undefined);
|
|
44
|
-
/** Same shape as the full SDK. Only
|
|
59
|
+
/** Same shape as the full SDK. Only batching delay and size apply here. */
|
|
45
60
|
telemetry?: {
|
|
61
|
+
traces?: {
|
|
62
|
+
scheduledDelayMillis?: number;
|
|
63
|
+
maxExportBatchSize?: number;
|
|
64
|
+
};
|
|
46
65
|
logs?: {
|
|
47
66
|
scheduledDelayMillis?: number;
|
|
48
67
|
maxExportBatchSize?: number;
|
|
@@ -79,20 +98,83 @@ export interface CaptureExceptionOptions {
|
|
|
79
98
|
/** Custom fingerprint override for issue grouping. */
|
|
80
99
|
fingerprint?: string[];
|
|
81
100
|
}
|
|
82
|
-
|
|
101
|
+
export interface TrackPageviewOptions {
|
|
102
|
+
/** Page pathname, e.g. "/pricing". Required. */
|
|
103
|
+
path: string;
|
|
104
|
+
/** Full page URL, e.g. "https://acme.com/pricing?plan=pro". */
|
|
105
|
+
url?: string;
|
|
106
|
+
/** Query string, e.g. "?plan=pro". Derived from url if not set. */
|
|
107
|
+
query?: string;
|
|
108
|
+
/** Referrer URL or domain. */
|
|
109
|
+
referrer?: string;
|
|
110
|
+
/** Session ID. Falls back to an ephemeral server id. */
|
|
111
|
+
sessionId?: string;
|
|
112
|
+
/** User ID. Falls back to the userId init option. */
|
|
113
|
+
userId?: string;
|
|
114
|
+
/** Extra span attributes to set on the pageview span. */
|
|
115
|
+
attributes?: Record<string, string>;
|
|
116
|
+
}
|
|
117
|
+
export interface StartSpanOptions {
|
|
118
|
+
name: string;
|
|
119
|
+
attributes?: Attributes;
|
|
120
|
+
}
|
|
121
|
+
/** Same values as OTel SpanStatusCode. */
|
|
122
|
+
export declare const SpanStatusCode: {
|
|
123
|
+
readonly UNSET: 0;
|
|
124
|
+
readonly OK: 1;
|
|
125
|
+
readonly ERROR: 2;
|
|
126
|
+
};
|
|
127
|
+
/** Subset of the OTel Span interface, so full SDK spans fit wherever a light span is expected. */
|
|
128
|
+
export interface Span {
|
|
129
|
+
spanContext(): {
|
|
130
|
+
traceId: string;
|
|
131
|
+
spanId: string;
|
|
132
|
+
traceFlags: number;
|
|
133
|
+
};
|
|
134
|
+
setAttribute(key: string, value: AttributeValue): this;
|
|
135
|
+
setAttributes(attributes: Attributes): this;
|
|
136
|
+
addEvent(name: string, attributes?: Attributes): this;
|
|
137
|
+
setStatus(status: {
|
|
138
|
+
code: number;
|
|
139
|
+
message?: string;
|
|
140
|
+
}): this;
|
|
141
|
+
updateName(name: string): this;
|
|
142
|
+
recordException(exception: Error | string): void;
|
|
143
|
+
isRecording(): boolean;
|
|
144
|
+
end(): void;
|
|
145
|
+
}
|
|
146
|
+
export type DisposableSpan = Span & Disposable;
|
|
147
|
+
type LogMethod = (...args: unknown[]) => void;
|
|
148
|
+
/** Console-style logger. The full SDK logger also has OTel `emit()`, light does not. */
|
|
149
|
+
export interface StradaLogger {
|
|
150
|
+
trace: LogMethod;
|
|
151
|
+
debug: LogMethod;
|
|
152
|
+
info: LogMethod;
|
|
153
|
+
warn: LogMethod;
|
|
154
|
+
error: LogMethod;
|
|
155
|
+
fatal: LogMethod;
|
|
156
|
+
}
|
|
83
157
|
export declare function initStrada(options: StradaOptions): Error | undefined;
|
|
84
158
|
/** Product analytics event. Properties are stored as `custom.*` attributes. */
|
|
85
|
-
export declare function track(name: string, properties?:
|
|
159
|
+
export declare function track(name: string, properties?: Attributes): Error | undefined;
|
|
86
160
|
/** Full profile snapshot for `otel_users`. Call from trusted code with every field you want to keep. */
|
|
87
161
|
export declare function identifyUser(user: StradaUserIdentity): Error | undefined;
|
|
88
162
|
/** Tags merged into every captureException() call. */
|
|
89
163
|
export declare function setTags(next: Record<string, string>): void;
|
|
164
|
+
/** Report an error as an issue. Applies KnownError, ignoreErrors, denyUrls, and beforeSend. */
|
|
165
|
+
export declare function captureException(error: unknown, opts?: CaptureExceptionOptions): Error | undefined;
|
|
166
|
+
/** Console-style logger that sends to `otel_logs`. Not exception capture: use captureException() for issues. */
|
|
167
|
+
export declare function getLogger(name?: string): StradaLogger;
|
|
168
|
+
/** Create a detached span. Call `span.end()` or use `using`. It does not parent later spans. */
|
|
169
|
+
export declare function startInactiveSpan(options: StartSpanOptions): DisposableSpan;
|
|
90
170
|
/**
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
* the
|
|
171
|
+
* Run `callback` inside an active span that auto-ends. Spans, logs, events,
|
|
172
|
+
* and errors created inside are parented to it. A thrown error is recorded on
|
|
173
|
+
* the span and rethrown.
|
|
94
174
|
*/
|
|
95
|
-
export declare function
|
|
175
|
+
export declare function startSpan<T>(options: StartSpanOptions, callback: (span: Span) => T): T;
|
|
176
|
+
/** Server-side pageview span. Feeds the same analytics views as browser pageviews. */
|
|
177
|
+
export declare function trackPageview(opts: TrackPageviewOptions): Error | undefined;
|
|
96
178
|
export declare function flush(): Promise<Error | undefined>;
|
|
97
179
|
export declare function shutdown(): Promise<Error | undefined>;
|
|
98
180
|
export {};
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAKH,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AACvD,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;AAExD,MAAM,WAAW,aAAa;IAC5B,yDAAyD;IACzD,SAAS,EAAE,MAAM,CAAC;IAClB,sCAAsC;IACtC,OAAO,EAAE,MAAM,CAAC;IAChB,0GAA0G;IAC1G,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,qFAAqF;IACrF,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,oFAAoF;IACpF,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,yCAAyC;IACzC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,qDAAqD;IACrD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,+CAA+C;IAC/C,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,2CAA2C;IAC3C,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,mEAAmE;IACnE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,8DAA8D;IAC9D,YAAY,CAAC,EAAE,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC;IACtC,kEAAkE;IAClE,QAAQ,CA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