This article shows you the steps of storing your Backtrace project crash&error report to brainCloud custom entities with a Unity app that has Backtrace integrated.
Step1: Create a webhook with a linked script from brainCloud console
- Login to brainCloud console, select an app for storing backtrace reports, create a custom collection, set the Owned property to true if you want to classify the reports by users. 
- Create a Webhook and link the following script to this Webhook. Note that to change the - entityTypename to your custom collection name and default user profileId accordingly. Check out this link for setting up webhook in brainCloud.- "use strict"; 
 function main() {
 var response = {};
 bridge.logInfoJson("Script inputs", data);
 var webHookParms = JSON.parse(JSON.stringify(data));
 webHookParms.headers = safeMap(data.headers);
 webHookParms.parameters = safeMap(data.parameters);
 webHookParms.jsonBody = safeMap(data.jsonBody);
 webHookParms.jsonBody.attributes = safeMap(data.jsonBody.attributes);
 
 // for the case backtrace error coming but user not logging in yet
 // save the log to default user
 var profileId = "d5127546-b027-464d-bade-96b1832e97eb";
 if (data.jsonBody.attributes.profileId[0][0].length > 5 ){
 profileId = data.jsonBody.attributes.profileId[0][0];
 }
 
 bridge.logInfo("passed in profileId from backtrace", profileId);
 
 bridge.logInfoJson("Received the webhook start...", data);
 
 var userSession = bridge.getSessionForProfile(profileId);
 
 //store backtrace jsonBody to an owned custom entity
 var entityType = "backTraceReport";
 var dataJson = {
 "fingerprint": data.jsonBody.fingerprint,
 "jsonBody": webHookParms.jsonBody
 };
 var acl = {
 "other": 1
 };
 var timeToLive = null;
 var isOwned = true;
 var customEntityProxy = bridge.getCustomEntityServiceProxy(userSession);
 
 var postResult = customEntityProxy.createEntity(entityType, dataJson, acl, timeToLive, isOwned);
 if (postResult.status == 200) {
 response.createdEntityStatus = "successfully create a custom entity with fingerprint " + webHookParms.jsonBody.fingerprint;
 }
 var logService = bridge.getLogServiceProxy();
 logService.logInfo("Webhook [ " + webHookParms.requestUrl + " ] - dumping parameters...", JSON.stringify(webHookParms));
 response.jsonResponse = {};
 response.message = "Webhook received";
 response.jsonResponse.receivedInCCdata = data;
 return response;
 }
 function safeMap(aMap) {
 var newMap = {};
 var newKey = "";
 for (var key in aMap) {
 newKey = key.replace(/\./g, "_");
 newMap[newKey] = aMap[key];
 }
 return newMap;
 }
 main();
Step2: Set up a project in Backtrace
- Login to your backtrace account, create a project then go to Project settings. Following their integration guides to integrate backtrace to your platform accordingly, our example uses Unity. 
- Go to Workflow integrations section, add brainCloud webhook to there. 
- Open Attribute section, add a profileId attribute to there, we will use it in the Unity app. 
- If your app uses backtrace API, generate one from the API tokens section. 
Step3: Send out Backtrace report from the Unity app
- Once you follow backtrace integration guides to integrate backtrace to your Unity app, make sure to add backtrace send report method to each brainCloud error call back. - public void authError_BCcall(int statusCode, int reasonCode, string statusMessage, object cbObject) 
 {
 AddStatusText("authenticate bc fail \n " + statusMessage);
 var report = new BacktraceReport(
 message: statusMessage,
 attributes: new Dictionary<string, string>() { { "attibutestest", "attibutestestvalue" }, { "profileId", profileId } },
 attachmentPaths: new List<string>() { @"file_path_1", @"file_path_2" }
 );
 _backtraceClient.Send(report);
 //_backtraceClient.Send(new Exception(statusMessage));
 }







