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

1. Create a new API key

If you are using Kibana dashboard: 1. Login to your Kibana dashboard. 2. Go to Dev Tools > Console. 3. Copy the following console code to your console and run it.

If you are using CURL commands: 1. Execute the following cURL command in your terminal.

PS: by default, this integration will search for logs inside any index that matches *log*, if you have a specific index for logs that doesn't match this pattern, please change the name of the index in line 12 in the following command. If you want to specify more than 1 index, you can separate the names with ,.

POST /_security/api_key
"name": "asayer-api-key",
"role_descriptors": {
"asayer-role": {
"cluster": [
"index": [
"names": [
"privileges": [

If you used any of the previous methods to generate an API key, you will get a result as the following:

"id" : "eQWAIG0Bo0VqB8HXFH9-",
"name" : "asayer-api-key",
"api_key" : "dZ5ycVRJTU-5UW_RYfi1_w"

Make sure to copy the id and the api_key as we need them for our integration. For more information about creating an API key, please refer to this documentation.

2. Enable Elasticsearch in Asayer

Put your host address, port, id and api_key in Asayer dashboard under Preferences > Integrations. If you changed the index when generating the api_key, please specify the name in indexes.

Elasticsearch Integration in Asayer

3. Propagate asayerSessionId

To link a Elasticsearch 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', {

In order for Asayer to associate a Elasticsearch log entry with the recorded user session, a unique id 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
class F:
def write(self, x):
if ASAYER_SESSION_ID is not None and x != '\n':
old_f.write(f"[asayer_session_id={ASAYER_SESSION_ID}] {x}")
def flush(self):
def tb_print_exception(etype, value, tb, limit=None, file=None, chain=True):
if ASAYER_SESSION_ID is not None:
value = type(value)(f"[asayer_session_id={ASAYER_SESSION_ID}] " + str(value))
old_tb(etype, value, tb, limit, file, chain)
traceback.print_exception = tb_print_exception
sys.stderr = F()

The name of the tag asayer_session_id is case sensitive.

4. Special Consideration

By default, we look for each log associated to an Asayer session using the attributes message and utc_time, we are only interested in error logs, to identify error logs we check the attribute tags to contain the value error.

If you have a different set of configuration, please contact our technical support.