highlight / highlight

highlight.io: The open source, full-stack monitoring platform. Error monitoring, session replay, logging, distributed tracing, and more.
https://app.highlight.io
Other
7.22k stars 329 forks source link

cross domain identification - apply identifier across differnet projects based on fingerprint #8790

Open Vadman97 opened 2 weeks ago

Vadman97 commented 2 weeks ago

allow the clientID to persist via a cookie cross-domain for backfilling sessions

linear[bot] commented 2 weeks ago

HIG-4742 cross domain identification - apply identifier across differnet projects based on fingerprint

greptile-apps[bot] commented 2 weeks ago

To implement cross-domain identification and allow the clientID to persist via a cookie for backfilling sessions, follow these steps:

  1. Backend Changes:

    • Update the AppendProperties function in /backend/public-graph/graph/resolver.go to handle cross-domain cookies.
      func (r *Resolver) AppendProperties(ctx context.Context, sessionID int, properties map[string]string, propType Property) error {
      // Existing code...
      // Set cross-domain cookie for clientID
      http.SetCookie(w, &http.Cookie{
         Name:     "clientID",
         Value:    clientID,
         Path:     "/",
         Domain:   ".yourdomain.com", // Set to your domain
         HttpOnly: true,
         Secure:   true,
      })
      // Existing code...
      }
  2. Frontend Changes:

    • Modify the init function in /sdk/firstload/src/index.tsx to read and set the clientID from a cookie.
      init: (projectID?: string | number, options?: HighlightOptions) => {
      // Existing code...
      let clientID = document.cookie.split('; ').find(row => row.startsWith('clientID='))?.split('=')[1];
      if (!clientID) {
         clientID = GenerateSecureID();
         document.cookie = `clientID=${clientID}; path=/; domain=.yourdomain.com; Secure; HttpOnly`;
      }
      // Existing code...
      }
  3. Session Backfilling:

    • Ensure the sessionIsBackfilled function in /frontend/src/pages/Player/utils/utils.ts correctly identifies sessions using the clientID.
      export const sessionIsBackfilled = (session: Session): boolean => {
      return !!session.clientID && !!session.identifier && !session.identified;
      };

References

/backend/public-graph/graph/resolver.go /backend/model/model.go /sdk/firstload/src/index.tsx /sdk/client/src/index.tsx /frontend/src/pages/Player/utils/utils.ts /frontend/src/pages/Player/utils/utils.test.ts /docs-content/getting-started/2_frontend-backend-mapping.md

Ask Greptile