Stackdriver

How to integrate Stackdriver with Asayer and see backend errors alongside session replays.

1. Create Google Cloud Service Account

  1. In the GCP Console, go to the Create Service Account Key page.
  2. From the Service account list, select New Service Account.
  3. In the Service account name field, enter "asayer-stackdriver".
  4. From the Role list, add Logging > Logs Viewer and Stackdriver > Stackdriver Accounts Viewer.
  5. Click Create to download the JSON file that contains your key.

2. Enable Stackdriver in Asayer

Paste your Log Name and asayer-stackdriver credentials in Asayer dashboard under Preferences > Integrations.

Stackdriver Integration in Asayer

3. Propagate asayerSessionId

To link a Stackdriver event with the recorded user session, a unique id has to be propagated from your frontend to your backend on each request you want to track. This can be done using a custom HTTP header. In the below example, we use the fetch function to send that header.

const headers = {
Accept: 'application/json',
'Content-Type': 'application/json',
};
if (window.asayer && window.asayer.id()) {
headers['X-Session-Id'] = window.asayer.id(); // Inject asayer_session_id
}
fetch('www.your-backend.com', {
'GET',
headers,
});

In order for Asayer to associate a Stackdriver log entry with the recorded user session, a unique id has to be propagated as a label to each backend error you wish to track.

Below is an example in Stackdriver's Python API.

google_logger.log_text("A LOG ENTRY", severity='ERROR', labels={"asayerSessionId": ASAYER_SESSION_ID})
#or
google_logger.log_struct({"message": "A LOG ENTRY"}, severity='ERROR', labels={"asayerSessionId": ASAYER_SESSION_ID})

The name of the tag asayerSessionId is case sensitive.