grafana / faro-web-sdk

The Grafana Faro Web SDK, part of the Grafana Faro project, is a highly configurable web SDK for real user monitoring (RUM) that instruments browser frontend applications to capture observability signals. Frontend telemetry can then be correlated with backend and infrastructure data for full-stack observability.
https://grafana.com/oss/faro/
Apache License 2.0
688 stars 62 forks source link

Session Manager: guard against circular references when stringifying a session #587

Open codecapitano opened 1 month ago

codecapitano commented 1 month ago

Description

A user reported a Maximum call stack size exceeded exception in Faro.

A "Maximum call stack size exceeded" during JSON serialisation happens when an object contains circular references. Circular references happen when an object references itself directly or through one of its child objects.

Example for a circular reference.

const x = {};
const y = { x };
x.y = y

Proposed solution

To handle circular references, you can use a custom replacer function as the second argument to JSON.stringify(). This function can check for circular references and either replace them with something JSON can serialize (like null or a special marker) or omit them from the resulting JSON.

Context

image