@monoscopetech/browser 0.7.1 → 0.7.2

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 CHANGED
@@ -71,6 +71,7 @@ The `Monoscope` constructor accepts the following options:
71
71
  | `replaySampleRate` | `number` | Replay sampling rate from `0` to `1`. Default `1` (100%). |
72
72
  | `enabled` | `boolean` | Whether to start collecting data immediately. Default `true`. |
73
73
  | `resourceTimingThresholdMs` | `number` | Minimum resource duration (ms) to report. Default `200`. |
74
+ | `enableUserInteraction` | `boolean` | Trace user clicks and interactions, linking them to downstream network calls. Default `false`. |
74
75
 
75
76
  ---
76
77
 
@@ -198,6 +199,76 @@ function MyApp() {
198
199
 
199
200
  ---
200
201
 
202
+ ## Custom Instrumentation
203
+
204
+ ### Custom Spans
205
+
206
+ Use `startSpan()` to instrument specific operations with timing and attributes. It supports both sync and async functions — the span is automatically ended when the function returns or the promise resolves.
207
+
208
+ ```javascript
209
+ // Sync
210
+ monoscope.startSpan("parse-config", (span) => {
211
+ span.setAttribute("config.size", rawConfig.length);
212
+ return parseConfig(rawConfig);
213
+ });
214
+
215
+ // Async
216
+ const data = await monoscope.startSpan("fetch-dashboard", async (span) => {
217
+ span.setAttribute("dashboard.id", dashboardId);
218
+ const res = await fetch(`/api/dashboards/${dashboardId}`);
219
+ span.setAttribute("http.status", res.status);
220
+ return res.json();
221
+ });
222
+ ```
223
+
224
+ ### Custom Events
225
+
226
+ Use `recordEvent()` to track discrete events without wrapping a code block:
227
+
228
+ ```javascript
229
+ monoscope.recordEvent("feature_flag_evaluated", {
230
+ "flag.name": "new-checkout",
231
+ "flag.value": true,
232
+ });
233
+ ```
234
+
235
+ ### React Components
236
+
237
+ Use the `useMonoscope()` hook to instrument React components:
238
+
239
+ ```tsx
240
+ import { useMonoscope } from "@monoscopetech/browser/react";
241
+
242
+ function CheckoutButton() {
243
+ const monoscope = useMonoscope();
244
+
245
+ const handleClick = () => {
246
+ monoscope?.startSpan("checkout.submit", async (span) => {
247
+ span.setAttribute("cart.items", cartItems.length);
248
+ await submitOrder();
249
+ });
250
+ };
251
+
252
+ return <button onClick={handleClick}>Checkout</button>;
253
+ }
254
+ ```
255
+
256
+ ### Additional OpenTelemetry Instrumentations
257
+
258
+ Pass extra OTel instrumentations via the `instrumentations` config to extend tracing beyond the built-in set:
259
+
260
+ ```javascript
261
+ import { LongTaskInstrumentation } from "@opentelemetry/instrumentation-long-task";
262
+
263
+ const monoscope = new Monoscope({
264
+ projectId: "YOUR_PROJECT_ID",
265
+ serviceName: "my-app",
266
+ instrumentations: [new LongTaskInstrumentation()],
267
+ });
268
+ ```
269
+
270
+ ---
271
+
201
272
  ## Features
202
273
 
203
274
  ### Session Replay