@maple-dev/browser 0.2.0 → 0.3.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 +13 -0
- package/dist/index.d.mts +4 -4
- package/dist/index.mjs +14 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -35,6 +35,19 @@ That single call:
|
|
|
35
35
|
- writes session metadata at start (`active`) and on page hide (`ended`),
|
|
36
36
|
including the trace ids observed during the session.
|
|
37
37
|
|
|
38
|
+
## Identifying users
|
|
39
|
+
|
|
40
|
+
Pass `userId` to `init()` when you already know the signed-in user, or call
|
|
41
|
+
`MapleBrowser.identify(user.id)` later. The id is attached to future session
|
|
42
|
+
metadata rows and stamped as `user.id` on future browser-created spans.
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
MapleBrowser.identify(user.id)
|
|
46
|
+
|
|
47
|
+
// after sign-out
|
|
48
|
+
MapleBrowser.identify(null)
|
|
49
|
+
```
|
|
50
|
+
|
|
38
51
|
## Privacy
|
|
39
52
|
|
|
40
53
|
`maskAllInputs` (default **on**) masks every `<input>` value. Use rrweb's
|
package/dist/index.d.mts
CHANGED
|
@@ -16,8 +16,8 @@ interface MapleBrowserConfig {
|
|
|
16
16
|
readonly serviceVersion?: string;
|
|
17
17
|
/** Deployment environment, e.g. "production". */
|
|
18
18
|
readonly environment?: string;
|
|
19
|
-
/** Optional user id attached to
|
|
20
|
-
readonly userId?: string;
|
|
19
|
+
/** Optional user id attached to replay sessions and future browser spans. */
|
|
20
|
+
readonly userId?: string | null | undefined;
|
|
21
21
|
readonly tracing?: {
|
|
22
22
|
/** Default true. */readonly enabled?: boolean;
|
|
23
23
|
/**
|
|
@@ -65,8 +65,8 @@ interface MapleBrowserHandle {
|
|
|
65
65
|
* ```
|
|
66
66
|
*/
|
|
67
67
|
declare const MapleBrowser: {
|
|
68
|
-
init: (config: MapleBrowserConfig) => MapleBrowserHandle; /** Attach
|
|
69
|
-
identify: (userId
|
|
68
|
+
init: (config: MapleBrowserConfig) => MapleBrowserHandle; /** Attach, replace, or clear the user id on the active session. Safe to call repeatedly. */
|
|
69
|
+
identify: (userId?: string | null) => void;
|
|
70
70
|
};
|
|
71
71
|
//#endregion
|
|
72
72
|
export { MapleBrowser, type MapleBrowserConfig, type MapleBrowserHandle };
|
package/dist/index.mjs
CHANGED
|
@@ -730,6 +730,9 @@ function startReplaySession(options) {
|
|
|
730
730
|
//#endregion
|
|
731
731
|
//#region src/config.ts
|
|
732
732
|
const DEFAULT_ENDPOINT = "https://ingest.maple.dev";
|
|
733
|
+
function normalizeUserId(userId) {
|
|
734
|
+
return userId ? userId : void 0;
|
|
735
|
+
}
|
|
733
736
|
function resolveConfig(config) {
|
|
734
737
|
return {
|
|
735
738
|
ingestKey: config.ingestKey,
|
|
@@ -738,7 +741,7 @@ function resolveConfig(config) {
|
|
|
738
741
|
serviceNamespace: config.serviceNamespace,
|
|
739
742
|
serviceVersion: config.serviceVersion,
|
|
740
743
|
environment: config.environment,
|
|
741
|
-
userId: config.userId,
|
|
744
|
+
userId: normalizeUserId(config.userId),
|
|
742
745
|
tracingEnabled: config.tracing?.enabled ?? true,
|
|
743
746
|
tracingInstrumentFetch: config.tracing?.instrumentFetch ?? true,
|
|
744
747
|
replayEnabled: config.replay?.enabled ?? true,
|
|
@@ -754,8 +757,13 @@ function resolveConfig(config) {
|
|
|
754
757
|
* alongside the BatchSpanProcessor, does no export of its own.
|
|
755
758
|
*/
|
|
756
759
|
var TraceIdCollector = class {
|
|
760
|
+
constructor(getUserId = () => void 0) {
|
|
761
|
+
this.getUserId = getUserId;
|
|
762
|
+
}
|
|
757
763
|
onStart(span) {
|
|
758
764
|
recordTraceId(span.spanContext().traceId);
|
|
765
|
+
const userId = this.getUserId();
|
|
766
|
+
if (userId !== void 0) span.setAttribute("user.id", userId);
|
|
759
767
|
}
|
|
760
768
|
onEnd(_span) {}
|
|
761
769
|
forceFlush() {
|
|
@@ -794,7 +802,7 @@ function setupTracing(config, sessionId) {
|
|
|
794
802
|
});
|
|
795
803
|
const provider = new WebTracerProvider({
|
|
796
804
|
resource: resourceFromAttributes(attributes),
|
|
797
|
-
spanProcessors: [new TraceIdCollector(), new BatchSpanProcessor(exporter)]
|
|
805
|
+
spanProcessors: [new TraceIdCollector(() => config.userId), new BatchSpanProcessor(exporter)]
|
|
798
806
|
});
|
|
799
807
|
provider.register();
|
|
800
808
|
if (config.tracingInstrumentFetch) registerInstrumentations({ instrumentations: [new FetchInstrumentation({ ignoreUrls: [new RegExp(`${escapeRegExp(config.endpoint)}/v1/`)] })] });
|
|
@@ -854,18 +862,14 @@ function init(rawConfig) {
|
|
|
854
862
|
return handle;
|
|
855
863
|
}
|
|
856
864
|
/**
|
|
857
|
-
* Attach
|
|
858
|
-
* call on every render.
|
|
859
|
-
*
|
|
860
|
-
* moment — so an id set here before the session ends is what the session is
|
|
861
|
-
* tagged with.
|
|
865
|
+
* Attach, replace, or clear the user id on the active session. Idempotent and
|
|
866
|
+
* safe to call on every render. Future browser-created spans read this value
|
|
867
|
+
* when they start, and future session metadata rows read it when they post.
|
|
862
868
|
*/
|
|
863
869
|
function identify(userId) {
|
|
864
870
|
if (typeof window === "undefined") return;
|
|
865
871
|
if (!activeConfig) return;
|
|
866
|
-
|
|
867
|
-
if (activeConfig.userId === userId) return;
|
|
868
|
-
activeConfig.userId = userId;
|
|
872
|
+
activeConfig.userId = normalizeUserId(userId);
|
|
869
873
|
}
|
|
870
874
|
//#endregion
|
|
871
875
|
//#region src/index.ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@maple-dev/browser",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Maple browser SDK — OpenTelemetry tracing and rrweb session replay in one package. Every span and replay event shares a session id for trace↔replay correlation.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"maple",
|