CloudWatch
How to integrate CloudWatch with OpenReplay and see backend errors alongside session replays.
1. Create a Service Account
Section titled 1. Create a Service Account- Login to your AWS account.
- Go to IAM dashboard.
- Click on Users.
- Click on Add user button.
- Set the name to “openreplay_cw”.
- In access type, select Programmatic access.
- Click on Next: Permissions button.
- Choose Attach existing policies directly
- In the list of permissions, choose CloudWatchReadOnlyAccess.
- Click Next: Tags button.
- Click Next: Review button.
- Click Create user button.
- Copy the
Access key ID
and theSecret access key
.
2. Enable CloudWatch in OpenReplay
Section titled 2. Enable CloudWatch in OpenReplayPut your Access key ID
and Secret access key
in OpenReplay dashboard under ‘Preferences > Integration’, select the region and select the log group that you want to track from the dropdown list.
3. Propagate openReplaySessionToken
Section titled 3. Propagate openReplaySessionTokenTo link a CloudWatch event with the recorded user session, a unique token 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 (tracker.getSessionToken()) { // use window.OpenReplay instead of tracker if you're using the snippet
headers['X-OpenReplay-SessionToken'] = tracker.getSessionToken(); // Inject openReplaySessionToken
}
fetch('www.your-backend.com', {
'GET',
headers,
});
In order for OpenReplay to associate a Cloudwatch log entry with the recorded user session, a unique token has to be propagated as part of each backend error you wish to track.
Below is an example in Python using Monkey Patching.
import sys
import traceback
#...
old_tb = traceback.print_exception
old_f = sys.stdout
old_e = sys.stderr
OPENREPLAY_SESSION_TOKEN = None
class F:
def write(self, x):
if OPENREPLAY_SESSION_TOKEN is not None and x != '\n':
old_f.write(f"[openReplaySessionToken={OPENREPLAY_SESSION_TOKEN}] {x}")
else:
old_f.write(x)
def flush(self):
pass
def tb_print_exception(etype, value, tb, limit=None, file=None, chain=True):
if OPENREPLAY_SESSION_TOKEN is not None:
value = type(value)(f"[openReplaySessionToken={OPENREPLAY_SESSION_TOKEN}] " + str(value))
old_tb(etype, value, tb, limit, file, chain)
traceback.print_exception = tb_print_exception
sys.stderr = F()
The name of the tag openReplaySessionToken
is case sensitive.
Have questions?
Section titled Have questions?If you encounter any issues, connect to our Slack and get help from our community.