@workleap/logrocket 1.0.1 → 1.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.
@@ -1,4 +1,5 @@
1
- import { getBootstrappingStore, getTelemetryContext } from "@workleap/telemetry";
1
+ import { createCompositeLogger, type RootLogger } from "@workleap/logging";
2
+ import { createBootstrappingStore, createTelemetryContext } from "@workleap/telemetry";
2
3
  import LogRocket from "logrocket";
3
4
  import LogrocketFuzzySanitizer from "logrocket-fuzzy-search-sanitizer";
4
5
  import { applyTransformers, type LogRocketSdkOptionsTransformer } from "./applyTransformers.ts";
@@ -33,26 +34,44 @@ const DefaultPrivateQueryParameterNames = [
33
34
  ];
34
35
 
35
36
  /**
36
- * @see https://workleap.github.io/wl-telemetry
37
+ * @see {@link https://workleap.github.io/wl-telemetry}
37
38
  */
38
39
  export interface RegisterLogRocketInstrumentationOptions {
39
- // Set to capture traffic from all subdomains under one session: https://docs.logrocket.com/reference/roothostname.
40
+ /**
41
+ * A root hostname to track sessions across subdomains. Set this option to capture traffic from all subdomains under one session: https://docs.logrocket.com/reference/roothostname.
42
+ */
40
43
  rootHostname?: LogRocketSdkOptions["rootHostname"];
44
+ /**
45
+ * Names of additional fields to exclude from session replays. These fields will be removed from network requests, responses using a fuzzy-matching algorithm.
46
+ */
41
47
  privateFieldNames?: string[];
48
+ /**
49
+ * Names of additional fields to exclude from session replays. These fields will be removed from query parameters using a fuzzy-matching algorithm.
50
+ */
42
51
  privateQueryParameterNames?: string[];
52
+ /**
53
+ * Indicates whether or not debug information should be logged to the console.
54
+ */
43
55
  verbose?: boolean;
56
+ /**
57
+ * The logger instances that will output messages.
58
+ */
59
+ loggers?: RootLogger[];
60
+ /**
61
+ * Hooks to transform the resulting LogRocket SDK options.
62
+ */
44
63
  transformers?: LogRocketSdkOptionsTransformer[];
45
64
  }
46
65
 
47
66
  // The function return type is mandatory, otherwise we got an error TS4058.
48
- export function getLogRocketSdkOptions(options: RegisterLogRocketInstrumentationOptions): LogRocketSdkOptions {
67
+ export function getLogRocketSdkOptions(userOptions: RegisterLogRocketInstrumentationOptions, logger: RootLogger): LogRocketSdkOptions {
49
68
  const {
50
69
  rootHostname = "workleap.com",
51
70
  privateFieldNames = [],
52
71
  privateQueryParameterNames = [],
53
72
  verbose = false,
54
73
  transformers = []
55
- } = options;
74
+ } = userOptions;
56
75
 
57
76
  const mergedPrivateFieldNames = DefaultPrivateFieldNames.concat(privateFieldNames);
58
77
  const mergedPrivateQueryParameterNames = DefaultPrivateQueryParameterNames.concat(privateQueryParameterNames);
@@ -66,6 +85,8 @@ export function getLogRocketSdkOptions(options: RegisterLogRocketInstrumentation
66
85
 
67
86
  const sdkOptions = {
68
87
  console: {
88
+ // Prevent console logs from being visible in LogRocket session replays and leaking PII.
89
+ // To capture logs in a session replay, use the LogRocketLogger class.
69
90
  isEnabled: false
70
91
  },
71
92
  rootHostname,
@@ -84,7 +105,8 @@ export function getLogRocketSdkOptions(options: RegisterLogRocketInstrumentation
84
105
  } satisfies LogRocketSdkOptions;
85
106
 
86
107
  return applyTransformers(sdkOptions, transformers, {
87
- verbose
108
+ verbose,
109
+ logger
88
110
  });
89
111
  }
90
112
 
@@ -96,21 +118,24 @@ export function __resetRegistrationGuard() {
96
118
  }
97
119
 
98
120
  /**
99
- * @see https://workleap.github.io/wl-telemetry
121
+ * @see {@link https://workleap.github.io/wl-telemetry}
100
122
  */
101
123
  export function registerLogRocketInstrumentation(appId: string, options: RegisterLogRocketInstrumentationOptions = {}) {
102
124
  const {
103
- verbose = false
125
+ verbose = false,
126
+ loggers = []
104
127
  } = options;
105
128
 
129
+ const logger = createCompositeLogger(verbose, loggers);
130
+
106
131
  registrationGuard.throw("[logrocket] The LogRocket instrumentation has already been registered. Did you call the \"registerLogRocketInstrumentation\" function twice?");
107
132
 
108
- const sdkOptions = getLogRocketSdkOptions(options);
133
+ const sdkOptions = getLogRocketSdkOptions(options, logger);
109
134
 
110
135
  // Session starts anonymously when LogRocket.init() is called.
111
136
  LogRocket.init(appId, sdkOptions);
112
137
 
113
- const telemetryContext = getTelemetryContext({ verbose });
138
+ const telemetryContext = createTelemetryContext(logger);
114
139
 
115
140
  // LogRocket maintains the same session even if the user starts as anonymous and later becomes identified via LogRocket.identify().
116
141
  // If LogRocket.identify is called multiple times during a recording, you can search for any of the identified users in the session.
@@ -119,11 +144,12 @@ export function registerLogRocketInstrumentation(appId: string, options: Registe
119
144
  [TelemetryIdTrait]: telemetryContext.telemetryId
120
145
  });
121
146
 
122
- if (verbose) {
123
- LogRocket.getSessionURL(url => {
124
- console.log("[logrocket] Session replay URL is now available:", url);
125
- });
126
- }
147
+ LogRocket.getSessionURL(url => {
148
+ logger
149
+ .withText("[logrocket] Session replay URL is now available:")
150
+ .withText(url)
151
+ .debug();
152
+ });
127
153
 
128
154
  // Indicates to the host applications that logrocket has been initialized.
129
155
  // It's useful in cases where an "add-on", like the platform widgets needs
@@ -143,10 +169,9 @@ export function registerLogRocketInstrumentation(appId: string, options: Registe
143
169
  LogRocket.getSessionURL(listener);
144
170
  };
145
171
 
172
+ const bootstrappingStore = createBootstrappingStore(logger);
146
173
  // Let the other telemetry libraries know that LogRocket instrumentation is ready.
147
- getBootstrappingStore().dispatch({ type: "logrocket-ready" });
174
+ bootstrappingStore.dispatch({ type: "logrocket-ready" });
148
175
 
149
- if (verbose) {
150
- console.log("[logrocket] LogRocket instrumentation is registered.");
151
- }
176
+ logger.debug("[logrocket] LogRocket instrumentation is registered.");
152
177
  }