|
1 | 1 | # Exceptionless.JavaScript
|
2 | 2 | [](https://ci.appveyor.com/project/Exceptionless/exceptionless-javascript) [](https://gitter.im/exceptionless/Discuss)
|
3 | 3 |
|
4 |
| -Exceptionless JavaScript client |
| 4 | +Exceptionless JavaScript/Node client |
5 | 5 |
|
6 |
| -**We are very very early in development on this project. Use at your own RISK!! All feedback / pull requests are welcome.** |
| 6 | +** We are working towards a 1.0 and would love your help! Please note that we may break the api from build to build until we reach a 1.0. Please feel free to create an issue or send us a pull request. |
| 7 | + |
| 8 | +## Getting Started (Development) |
| 9 | + |
| 10 | +The JavaScript client can be installed via [bower](http://bower.io/search/?q=exceptionless), [npm](https://www.npmjs.com/package/exceptionless) or cdn. If you need help, please contact us via in-app support or [open an issue](https://github.com/exceptionless/Exceptionless.JavaScript/issues/new). We’re always here to help if you have any questions! |
| 11 | + |
| 12 | +1. You will need to clone this repo. |
| 13 | +2. Install [Node.js](https://nodejs.org). _We only use node for our build and test processes._ |
| 14 | +3. Install [tsd](https://github.com/DefinitelyTyped/tsd) and [gulp](http://gulpjs.com) and the development dependencies using [npm](https://www.npmjs.com). |
| 15 | +```javascript |
| 16 | +npm install -g tsd |
| 17 | +npm install -g gulp |
| 18 | +npm install |
| 19 | +``` |
| 20 | +4. Build the project by running the following gulp command. |
| 21 | +```javascript |
| 22 | +gulp build |
| 23 | +``` |
| 24 | +5. Test the project by running the following gulp command. |
| 25 | +```javascript |
| 26 | +gulp test |
| 27 | +``` |
| 28 | + |
| 29 | +## Using Exceptionless |
| 30 | + |
| 31 | +### Installing |
| 32 | + |
| 33 | +Please follow the instructions below for installing the exceptionless JavaScript client. |
| 34 | + |
| 35 | +#### JavaScript |
| 36 | +Use one of the below methods to install exceptionless into your web app. |
| 37 | +##### Bower |
| 38 | +1. Install the package by running `bower install exceptionless` or skip this step and use the scripts hosted on our CDN. |
| 39 | +2. Add the script to your html page. We recommend placing this as the very first script. |
| 40 | +```html |
| 41 | +<script type="application/javascript" src="bower_components/exceptionless/dist/exceptionless.min.js"></script> |
| 42 | +``` |
| 43 | + |
| 44 | +##### CDN |
| 45 | +We will be adding cdn support in the near future. |
| 46 | + |
| 47 | +#### Node.js |
| 48 | +Use this method to install exceptionless into your node app. |
| 49 | +1. Install the package by running `npm install exceptionless`. |
| 50 | +2. Add the exceptionless client to your app: |
| 51 | +```javascript |
| 52 | +var client = require('exceptionless').ExceptionlessClient.default; |
| 53 | +``` |
| 54 | + |
| 55 | +### Configuring the client. |
| 56 | +You can configure the exceptionless client a few different ways. The section below will cover the different ways you can configure the ExceptionlessClient. _NOTE: The only required setting that you need to configure is the clients `apiKey`._ |
| 57 | + |
| 58 | +#### JavaScript |
| 59 | +1. You can configure the `apiKey` or `serverUrl` as part of the script tag. This will be applied to all new instances of the ExceptionlessClient |
| 60 | +```html |
| 61 | +<script type="application/javascript" src="bower_components/exceptionless/dist/exceptionless.min.js?apiKey=API_KEY_HERE"></script> |
| 62 | +``` |
| 63 | +2. You can set the `apiKey` or `serverUrl` on the default ExceptionlessClient instance. |
| 64 | +```javascript |
| 65 | +var client = Exceptionless.ExceptionlessClient.default; |
| 66 | +client.config.apiKey = 'API_KEY_HERE'; |
| 67 | +client.config.serverUrl = 'http://localhost:50000'; |
| 68 | +``` |
| 69 | +3. You can create a new instance of the ExceptionlessClient and specify the `apiKey`, `serverUrl` or [configuration object](https://github.com/exceptionless/Exceptionless.JavaScript/blob/master/src/configuration/IConfigurationSettings.ts). |
| 70 | +```javascript |
| 71 | +var client = new ExceptionlessClient('API_KEY_HERE'); |
| 72 | +// or with a api key and server url. |
| 73 | +var client = new ExceptionlessClient('API_KEY_HERE', 'http://localhost:50000'); |
| 74 | +// or with a configuration object |
| 75 | +var client = new ExceptionlessClient({ |
| 76 | + apiKey: 'API_KEY_HERE', |
| 77 | + serverUrl: 'http://localhost:50000', |
| 78 | + submissionBatchSize: 100 |
| 79 | +}); |
| 80 | +``` |
| 81 | + |
| 82 | +#### Node.js |
| 83 | +1. You can set the `apiKey` or `serverUrl` on the default ExceptionlessClient instance. |
| 84 | +```javascript |
| 85 | +var client = require('exceptionless').ExceptionlessClient.default; |
| 86 | +client.config.apiKey = 'API_KEY_HERE'; |
| 87 | +client.config.serverUrl = 'http://localhost:50000'; |
| 88 | +``` |
| 89 | +2. You can create a new instance of the ExceptionlessClient and specify the `apiKey`, `serverUrl` or [configuration object](https://github.com/exceptionless/Exceptionless.JavaScript/blob/master/src/configuration/IConfigurationSettings.ts). |
| 90 | +```javascript |
| 91 | +var exceptionless = require('exceptionless'); |
| 92 | + |
| 93 | +var client = new exceptionless.ExceptionlessClient('API_KEY_HERE'); |
| 94 | +// or with a api key and server url. |
| 95 | +var client = new exceptionless.ExceptionlessClient('API_KEY_HERE', 'http://localhost:50000'); |
| 96 | +// or with a configuration object |
| 97 | +var client = new exceptionless.ExceptionlessClient({ |
| 98 | + apiKey: 'API_KEY_HERE', |
| 99 | + serverUrl: 'http://localhost:50000', |
| 100 | + submissionBatchSize: 100 |
| 101 | +}); |
| 102 | +``` |
| 103 | + |
| 104 | +### Sending Events |
| 105 | +Once configured, Exceptionless will automatically send any unhandled exceptions that happen in your application. The sections below will show you how to send us different event types as well as customize the data that is sent in. |
| 106 | + |
| 107 | +####Sending Events |
| 108 | + |
| 109 | +You may also want to send us log messages, feature usages or other kinds of events. You can do this very easily with our fluent api. |
| 110 | + |
| 111 | +```javascript |
| 112 | +// javascript |
| 113 | +var client = Exceptionless.ExceptionlessClient.default; |
| 114 | +// Node.Js |
| 115 | +// var client = require('exceptionless').ExceptionlessClient.default; |
| 116 | + |
| 117 | +client.submitLog('Logging made easy'); |
| 118 | + |
| 119 | +// You can also specify the log source and log level. |
| 120 | +// We recommend specifying one of the following log levels: Trace, Debug, Info, Warn, Error |
| 121 | +client.submitLog('app.logger', 'This is so easy', 'Info'); |
| 122 | +client.createLog('app.logger', 'This is so easy', 'Info').addTags('Exceptionless').submit(); |
| 123 | + |
| 124 | +// Submit feature usages |
| 125 | +client.submitFeatureUsage('MyFeature'); |
| 126 | +client.createFeatureUsage('MyFeature').addTags('Exceptionless').submit(); |
| 127 | + |
| 128 | +// Submit a 404 |
| 129 | +client.submitNotFound('/somepage'); |
| 130 | +client.createNotFound('/somepage').addTags('Exceptionless').submit(); |
| 131 | + |
| 132 | +// Submit a custom event type |
| 133 | +client.submitEvent({ message = 'Low Fuel', type = 'racecar', source = 'Fuel System' }); |
| 134 | +``` |
| 135 | +####Manually Sending Errors |
| 136 | + |
| 137 | +In addition to automatically sending all unhandled exceptions, you may want to manually send exceptions to the service. You can do so by using code like this: |
| 138 | + |
| 139 | +```javascript |
| 140 | +// javascript |
| 141 | +var client = Exceptionless.ExceptionlessClient.default; |
| 142 | +// Node.Js |
| 143 | +// var client = require('exceptionless').ExceptionlessClient.default; |
| 144 | + |
| 145 | +try { |
| 146 | + throw new Error('test'); |
| 147 | +} catch (error) { |
| 148 | + client.submitException(error); |
| 149 | +} |
| 150 | +``` |
| 151 | + |
| 152 | +####Sending Additional Information |
| 153 | + |
| 154 | +You can easily include additional information in your error reports using our fluent [event builder API](https://github.com/exceptionless/Exceptionless.JavaScript/blob/master/src/EventBuilder.ts). |
| 155 | +```javascript |
| 156 | +// javascript |
| 157 | +var client = Exceptionless.ExceptionlessClient.default; |
| 158 | +// Node.Js |
| 159 | +// var client = require('exceptionless').ExceptionlessClient.default; |
| 160 | + |
| 161 | +try { |
| 162 | + throw new Error('Unable to create order from quote.'); |
| 163 | +} catch (error) { |
| 164 | + client.createException(error) |
| 165 | + // Set the reference id of the event so we can search for it later (reference:id). |
| 166 | + // This will automatically be populated if you call client.config.useReferenceIds(); |
| 167 | + .setReferenceId('random guid') |
| 168 | + // Add the order object (the ability to exclude specific fields will be coming in a future version). |
| 169 | + .setProperty("Order", order) |
| 170 | + // Set the quote number. |
| 171 | + .setProperty("Quote", 123) |
| 172 | + // Add an order tag. |
| 173 | + .addTags("Order") |
| 174 | + // Mark critical. |
| 175 | + .markAsCritical() |
| 176 | + // Set the coordinates of the end user. |
| 177 | + .setGeo(43.595089, -88.444602) |
| 178 | + // Set the user id that is in our system and provide a friendly name. |
| 179 | + .setUserIdentity(user.Id, user.FullName) |
| 180 | + // Submit the event. |
| 181 | + .submit(); |
| 182 | +} |
| 183 | +``` |
0 commit comments