Skip to content
This repository was archived by the owner on Apr 23, 2024. It is now read-only.
Fabio Russo edited this page Oct 21, 2021 · 19 revisions

The "Send" method

The "Send" method is the core way of communicating with the BugReplay full stack API. Basically this will allow you to send any payload from the server side code of the app you are recording with the BugReplay web extension. This will give you not only and idea of what happens on the frontend, but will also allow you to send specific data from the backend and it will be displayed back in sync with the video on your BugReplay report video.

You can place the send call in any backend method that will be triggered during the recording of your web app. During a BugReplay extension recording, if you have Fullstack enabled, there will be a key in the Header called br-recording-uuid. That uuid you need to send along in the "send" method on the BugReplay Fullstack API.

The send method will be in POST to the following endpoint: https://app.bugreplay.com/api/fullstack/v1/send with a content type of application/json and an Authorization header of type 'Bearer apikey' where apikey is your BugReplay fullstack api key.

The send method can be of two main types: a log or a stacktrace. In either case the payload you decide to send will be a string. It can be any content, raw, xml, json. If it's JSON we'll make sure to display a nice tree in the report video player though, so that might be good to know. The two fields in the request body's JSON for this kind of payload are:

  • payload
  • metadata

An example of a call with javascript might be as follows:

var myHeaders = new Headers();
myHeaders.append("Authorization", "Bearer **YourBugReplayAPIKEy**");
myHeaders.append("Content-Type", "application/json");

var raw = JSON.stringify({
  "uuid": "asdf-ghjk-klzx-1234",
  "type": "log",
  "payload": "{\"a\":1,\"b\":\"a sample log text\"}",
  "level": "info",
  "timestamp": 1622706694345,
  "metadata": "{\"anything_useful\":\"\"can be added here\"}",
  "title": "sample log today",
  "origin": "Wonderful Linux Server #2"
});

var requestOptions = {
  method: 'POST',
  headers: myHeaders,
  body: raw,
  redirect: 'follow'
};

fetch("https://app.bugreplay.com//api/fullstack/v1/send", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));

N.B. The timestamp is a unix milliseconds and as thus is completely timezone agnostic. It would be the result of something like

new Date()

in javascript, in any other language please make sure to send the unix milliseconds as integer. Another example would be in Go:

time.Now().UnixMilli()

The JSON request body

Let's have a better look at what can be sent in the JSON request body:

var raw = JSON.stringify({
  "uuid": "asdf-ghjk-klzx-1234",
  "type": "log",
  "payload": "{\"a\":1,\"b\":\"a sample log text\"}",
  "level": "info",
  "timestamp": 1622706694345,
  "metadata": "{\"anything_useful\":\"\"can be added here\"}",
  "title": "sample log today",
  "origin": "Wonderful Linux Server #2"
});

The JSON response body

  1. If there is no recording running on the web extension or the callback method with the uuid somehow failed the "send" call will return this:
{
  "success": "false",
  "error": [
    {
      "error_name": "",
      "message": "No BugReplay-Recording-UUID, doing nothing"
    }
  ]
}
  1. If the api key is invalid or you are logged in with a different account while recording the "send" call will return this:
{
  "success": "false",
  "error": [
    {
      "error_name": "ErrUserNotLoggedIn",
      "message": "User is not logged in!"
    }
  ]
}
  1. Validation errors will be shown like this. e.g. here we're sending "something" as type instead of "log" or "exception":
{
  "success": "false",
  "error": [
    {
      "error_name": "",
      "message": "Type must be 'log' or 'exception'"
    }
  ]
}
  1. Finally, if all goes well this is the kind of response to expect:
{
  "success": "true",
  "data": {
    "data": {
      "ok": {
        "id": 18,
        "timestamp": 1625655368523,
        "type": "log",
        "title": "sample log today",
        "payload": "{\"a\":1,\"b\":\"a sample text\"}",
        "uuid": "033e36dc-bb32-45b7-85c0-89f1dee11238",
        "metadata": "{\"key\":100,\"key2\":\"bla bla bla\"}",
        "origin": "my macbook pro"
      }
    },
    "success": true
  }
}

Next: Code snippets in different languages

Clone this wiki locally