Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/airbrake #21

Merged
merged 5 commits into from
Apr 27, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat: add airbrake support
  • Loading branch information
bharathvaj-ganesan committed Apr 27, 2021
commit 1436f903624d6064e383bf3dd543716a75579f21
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ dist
results
.nyc_output
*.tsbuildinfo
temp
92 changes: 92 additions & 0 deletions packages/airbrake/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# fullstory-airbrake

The FullStory-Airbrake integration seamlessly integrates the FullStorys and Airbrake platforms. When you look at a browser error in Airbrake, you will see a
link to the FullStory session replay at that exact moment in time. When you are watching a FullStory replay and your user experiences an error, you will see a
custom error with the basic error details.

<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->

**Table of content**

- [Pre-Requisites](#pre-requisites)
- [Installation](#installation)
- [Setup](#setup)
- [Code Changes](#code-changes)
- [Options](#options)
- [Roadmap](#roadmap)
- [How it works](#how-it-works)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

## Pre-Requisites

For the FullStory-Airbrake integration to work, you must have the [FullStory browser SDK package](https://www.npmjs.com/package/@fullstory/browser) and the
[Airbrake browser SDK package](https://github.com/airbrake/airbrake-js/tree/master/packages/browser).

## Installation

To install the stable version:

with npm:

```
npm install --save @bharathvaj/fullstory-airbrake
```

with yarn:

```
yarn add @bharathvaj/fullstory-airbrake
```

## Setup

### Code Changes

To set up the integration, both FullStory and Airbrake need to be initialized. Please add the following code:

```js
import { Notifier } from '@airbrake/browser';
import * as FullStory from '@fullstory/browser';
import AirbrakeFullStory from '@bharathvaj/fullstory-airbrake';

FullStory.init({ orgId: '__FULLSTORY_ORG_ID__' });

const airbrakeNotifier = new Notifier({
projectId: __YOUR_PROJECT_ID__,
projectKey: __YOUR_API_KEY__,
environment: 'production',
});

AirbrakeFullStory.init(airbrakeNotifier, options);
```

Replace `__YOUR_API_KEY__` and `__YOUR_PROJECT_ID__` with your site credentials.

You also need to replace `__FULLSTORY_ORG_ID__` with the value of `_fs_org` in the FullStory recording snippet on your
[FullStory settings page](https://help.fullstory.com/hc/en-us/articles/360020623514).

### Options

You can also customize the error event name in FullStory by

```js
// ...
// ...
AirbrakeFullStory.init(airbrakeNotifier, {
fsEventName: 'Custom Error Name',
});

//...
```

# Roadmap

[ ] - Add Unit test cases

## How it works

In Airbrake, you should see the `fullstoryUrl` in the context tab under occurences of an Error

In FullStory, you should see an event called `Airbrake Error` on the right sidebar along with the Airbrake'e error URL.
168 changes: 168 additions & 0 deletions packages/airbrake/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions packages/airbrake/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "@bharathvaj/fullstory-airbrake",
"description": "Fullstory Airbrake Integration",
"version": "1.1.0",
"main": "dist/index",
"types": "dist/index.d.ts",
"files": [
"dist"
],
"keywords": [
"airbrake",
"fullstory",
"integration"
],
"scripts": {
"clean": "rimraf -rf ./dist",
"build": "yarn clean && tsc -p tsconfig.build.json",
"prepublishOnly": "yarn run build",
"test": "yarn run build"
},
"peerDependencies": {
"@airbrake/browser": ">=2.1.0",
"@fullstory/browser": ">=1.0.0"
},
"devDependencies": {
"@airbrake/browser": "2.1.4",
"@fullstory/browser": "^1.4.9",
"tslib": "^2.2.0"
},
"publishConfig": {
"access": "public"
},
"author": "Bharathvaj Ganesan <[email protected]>",
"license": "MIT",
"bugs": {
"url": "https://github.com/bharathvaj-ganesan/fullstory-integrations/issues"
},
"homepage": "https://github.com/bharathvaj-ganesan/fullstory-integrations#readme"
}
43 changes: 43 additions & 0 deletions packages/airbrake/src/AirbrakeFullStory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import * as FullStory from '@fullstory/browser';
import { getOriginalExceptionProperties } from './utils';

/**
* This integration creates a link from the Bugsnag Error to the FullStory replay.
* It also creates a link from the FullStory event to the Bugsnag error.
*/

type Options = {
fsEventName: string;
};

class AirbrakeFullStory {
static init(client, options?: Options) {
let fsEventName = options?.fsEventName || 'Airbrake Error';

const originalNotify = client.notify;

client.notify = (...args) => {

// Add fullstory link to Airbrake
client.addFilter((notice) => {
notice.context.fullStoryLink = FullStory.getCurrentSessionURL(true) || 'current session URL API not ready';
return notice;
});

return originalNotify.call(client, ...args).then(result => {
if (result) {
// Sending to FullStory
FullStory.event(fsEventName, {
airbrakeUrl: result.url || 'Could not retrieve url',
...getOriginalExceptionProperties(result.errors[0])
});
}

return result;
})
}
}

}

export default AirbrakeFullStory;
3 changes: 3 additions & 0 deletions packages/airbrake/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import AirbrakeFullStory from './AirbrakeFullStory';

export default AirbrakeFullStory;
21 changes: 21 additions & 0 deletions packages/airbrake/src/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Checks if the exception has message
* @param exception
* @returns
*/
const isError = (exception: string | Error): exception is Error => {
return (exception as Error).message !== undefined;
};

/**
* Get the message and name properties from the original exception
* @param {Object} error
*/
export const getOriginalExceptionProperties = (error: any) => {
if (error && error.message && isError(error)) {
const { name, message } = error;
return { name, message };
}

return {};
};
11 changes: 11 additions & 0 deletions packages/airbrake/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "../../tsconfig.build.json",

"compilerOptions": {
"outDir": "./dist"
},

"include": [
"src/**/*"
]
}
3 changes: 3 additions & 0 deletions packages/airbrake/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../../tsconfig.json"
}
Loading