Navigate back to the homepage
Browse Repo

Visualize Your Elastic Errors in OpenReplay

Laurena Dehlouz
December 11th, 2019 · 1 min read

A large part of any engineering team’s efforts is spent monitoring, troubleshooting and debugging issues. Using a Log Management platform makes it easier to find and identify problems in complex architectures.

Elastic Stack (formerly ELK Stack) is the most popular open source logging platform. Consisting of Elasticsearch, Logstash, Kibana and Beats, the tool centralizes all the logs coming in from multiple sources (your servers, virtual machines and containers), all at the same time. It then collects, enriches and transforms a wide array of different data types into a defined destination for storage.

How it works


OpenReplay is an observability tool that helps engineers debug more easily. It records and lets you replay user sessions alongside the behavior from the rest of your stack. Our new integrations allows you to associate your Elastic stack events and logs with the individual user session so that you can see exactly what the user did, and how the rest of your stack behaved (frontend, network activity, redux and more).

By associating your Elastic Stack events with the session replay, you can easily grasp the full context of every issue and get to the root cause instantly.

Setting it up

1. Create a new API key

From your Kibana dashboard, head over to Dev Tools > Console and execute the following query:

1POST /_security/api_key
3 "name": "asayer-api-key",
4 "role_descriptors": {
5 "asayer-role": {
6 "cluster": [
7 "all"
8 ],
9 "index": [
10 {
11 "names": [
12 "*log*"
13 ],
14 "privileges": [
15 "read"
16 ]
17 }
18 ]
19 }
20 }

This will generate an id and the api_key needed for the integration.

2. Enable Elasticsearch in OpenReplay

In the OpenReplay Dashboard, head over to Preferences > Integrations and put in your host address, port, id and api_key.


3. Propagate asayerSessionId

To link and Elastic Stack event with its recorded user session, you need to propagate a unique id from your frontend to your backend for each request you want to track using a custom HTTP header.

For example you can use the fetch function:

1const headers = {
2 Accept: 'application/json',
3 'Content-Type': 'application/json',
5if (window.asayer && {
6 headers['X-Session-Id'] =; // Inject asayer_session_id
8fetch('', {
9 'GET',
10 headers,

To link Elastic logs with the recorded user session, you need to propagate a unique ID as part of each backend error you wish to track.

Here is an example using Python with Monkey Patching:

1import sys
2import traceback
4old_tb = traceback.print_exception
5old_f = sys.stdout
6old_e = sys.stderr
9class F:
10 def write(self, x):
11 if ASAYER_SESSION_ID is not None and x != '\n':
12 old_f.write(f"[asayer_session_id={ASAYER_SESSION_ID}] {x}")
13 else:
14 old_f.write(x)
16 def flush(self):
17 pass
19def tb_print_exception(etype, value, tb, limit=None, file=None, chain=True):
20 if ASAYER_SESSION_ID is not None:
21 value = type(value)(f"[asayer_session_id={ASAYER_SESSION_ID}] " + str(value))
22 old_tb(etype, value, tb, limit, file, chain)
24traceback.print_exception = tb_print_exception
26sys.stderr = F()

Head over to our documentation for more detailed instructions.

Happy debugging !

More articles from OpenReplay Blog

Observability and Debugging - Two peas in a pod

Why you need to adopt an Observability Strategy if you want to effectively debug issues across your web applications.

December 4th, 2019 · 2 min read

Building An Observability Strategy

Tired of looking for errors and exceptions? Invest in some tools that monitor each aspect of your software, so that you don’t have to.

November 20th, 2019 · 2 min read
© 2021 OpenReplay Blog
Link to $ to $ to $