Skip to content

Commit 17cdf99

Browse files
authored
Merge pull request #18 from trakerr-com/develop
API v3
2 parents 539101d + 267286d commit 17cdf99

File tree

9 files changed

+278
-83
lines changed

9 files changed

+278
-83
lines changed

README.md

Lines changed: 41 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,30 @@
11
# Trakerr - Javascript API Client
22
Get your application events and errors to Trakerr via the *Trakerr API
33

4-
## Requirements
4+
## 3-minute Integration Guide
5+
### Requirements
56
Node or Javascript supported Browser.
6-
[superagent.js](https://github.com/visionmedia/superagent)
7-
[stacktrace.js](https://www.stacktracejs.com/)
7+
- [superagent.js](https://github.com/visionmedia/superagent)
8+
- [stacktrace.js](https://www.stacktracejs.com/)
89

9-
## 3-minute Integration Guide
1010
### HTML/Javascript: 3-minute guide
1111
Include the following in your HTML
1212

1313
```html
1414
<script src="https://cdnjs.cloudflare.com/ajax/libs/superagent/3.5.2/superagent.min.js"></script>
1515
<script src="https://cdnjs.cloudflare.com/ajax/libs/stacktrace.js/1.3.1/stacktrace.min.js"></script>
1616
<script src="https://cdn.jsdelivr.net/trakerr/1.0.2/trakerr.min.js"></script>
17-
<script>function initTrakerr() { var c = new TrakerrClient('<api-key>', '<version of your code>', '<deployment stage of codebase>'); c.handleExceptions(false); } initTrakerr();</script>
17+
<script>function initTrakerr() { var c = new TrakerrClient('<api-key>', '1.0', 'production'); c.handleExceptions(false); } initTrakerr();</script>
1818
```
1919

20-
This will catch all errors using javascript's onerror and send them to trakerr. While this code is useful, we recommend using the Detailed Integration Guide below to send more useful information about errors.
20+
You can replace `1.0` and `production` with the values of app version and deployment stage of your codebase.
21+
22+
This will catch all errors using javascript's onerror and send them to trakerr. While this code is fast and clean, we recommend using the Detailed Integration Guide below to send more useful information about errors.
2123

2224
### NodeJS: 3-minute guide
2325
If you use NPM, install as follows:
2426
```bash
25-
npm install --only=prod --save trakerr-io/trakerr-javascript
27+
npm install --only=prod --save trakerr-com/trakerr-javascript
2628
```
2729

2830
If you use Bower, install as follows:
@@ -33,7 +35,9 @@ bower install https://github.com/trakerr-io/trakerr-javascript
3335
Install global handler
3436
```javascript
3537
var TrakerrClient = require('trakerr-javascript'); //This is only necessary for NPM use.
36-
var client = new TrakerrClient('<api-key>', '<app version here>', '<deployment stage here>'); // replace value within quotes with your values instead
38+
var client = new TrakerrClient('<api-key>', //Your API key
39+
'1.0', //Your app version
40+
'production'); //Custom deployment stage of your code.
3741

3842
//any error thrown with throw new Error('...'); will now be sent to Trakerr
3943
client.handleExceptions(false);
@@ -46,9 +50,12 @@ Include the dependencies and initialize the global client variable with your API
4650
```html
4751
<script src="https://cdnjs.cloudflare.com/ajax/libs/superagent/3.5.2/superagent.min.js"></script>
4852
<script src="https://cdnjs.cloudflare.com/ajax/libs/stacktrace.js/1.3.1/stacktrace.min.js"></script>
49-
<script src="trakerr.min.js"></script>
53+
<script src="https://cdn.jsdelivr.net/gh/trakerr-com/trakerr-javascript@1.1.0/dist/trakerr.min.js"></script>
5054
<!-- initialize the client globally -->
51-
<script> trakerr = new TrakerrClient('<api-key>', '<version of your code>', '<deployment stage of codebase>'); </script>
55+
<script> trakerr = new TrakerrClient('<api-key>', //Your API key
56+
'1.0', //Your app version
57+
'production'); //Custom deployment stage of your code.
58+
</script>
5259
```
5360

5461
And in the angular module, install an $exceptionHandler as shown below:
@@ -65,6 +72,8 @@ angular.module('your app').factory('$exceptionHandler', ['$window', function ($w
6572

6673
$window.trakerr.sendError(exception, "Error", function(error, data, response) {
6774
// ... handle or log response if needed ...
75+
76+
$log.error(exception, cause);//Relogs the error on the console
6877
});
6978
};
7079
}]);
@@ -73,14 +82,14 @@ angular.module('your app').factory('$exceptionHandler', ['$window', function ($w
7382
## Detailed Integration Guide
7483
This library works with both node apps and browser apps seamlessly.
7584

76-
For node apps just installing the above dependencies and bootstrapping the code similar to the below is sufficient. See the instructions below for the browser.
77-
7885
### Create a client
7986
In your script, the first thing before sending an event is to create a client. For npm apps, you may use require, but other options are also listed below.
8087

8188
```javascript
8289
var TrakerrClient = require('trakerr-javascript'); //This is only necessary for NPM use.
83-
var client = new TrakerrClient('<api-key>', '<app version here>', '<deployment stage here>'); // replace value within quotes with your values instead
90+
var client = new TrakerrClient('<api-key>', //Your API key
91+
'<app version here>', //Your app version
92+
'<deployment stage here>'); //Custom deployment stage of your code.
8493
```
8594

8695
### Option-1: Handle exceptions with a global handler
@@ -106,7 +115,7 @@ This will allow you to catch and send a specific error to trakerr, also allowing
106115
```
107116

108117
### Option-3: Send error to Trakerr programmatically and populate some custom properties on the event
109-
Passing a function to sendError will allow you to quickly populate the properties of the created AppEvent. For AppEvent's properties, see it's docs in the generated folder. The function must take in a parameter.
118+
Passing a function to sendError will allow you to quickly populate the properties of the created AppEvent. For [AppEvent's properties](generated/docs/AppEvent.md), see it's docs in the generated folder. The function must take in a parameter.
110119

111120
```javascript
112121
try {
@@ -116,6 +125,13 @@ Passing a function to sendError will allow you to quickly populate the propertie
116125
client.sendError(err, "Error", function(event) {
117126

118127
// set some custom properties on the event
128+
event.contextOperationTimeMillis = 1000
129+
event.eventUser = "jake@trakerr.io"
130+
event.eventSession = "20"
131+
event.contextDevice = "pc"
132+
event.contextAppSku = "mobile"
133+
event.contextTags = ["client", "frontend"]
134+
119135
event.customProperties = {
120136
customString: {
121137
customData1: "Some data"
@@ -162,6 +178,8 @@ var exports = function TrakerrClient(apiKey,
162178

163179
The TrakerrClient module has a lot of exposed properties. The benefit to setting these immediately after after you create the TrakerrClient is that AppEvent will default it's values against the TrakerClient that created it. This way if there is a value that all your AppEvents uses, and the constructor default value currently doesn't suit you; it may be easier to change it in TrakerrClient as it will become the default value for all AppEvents created after. A lot of these are populated by default value by the constructor, but you can populate them with whatever string data you want. The following table provides an in depth look at each of those.
164180

181+
If you're populating an app event directly, you'll want to take a look at the [AppEvent properties](generated/docs/AppEvent.md) as they contain properties unique to each AppEvent which do not have defaults you may set in the client.
182+
165183
Name | Type | Description | Notes
166184
------------ | ------------- | ------------- | -------------
167185
**apiKey** | **string** | API key generated for the application |
@@ -175,12 +193,14 @@ Name | Type | Description | Notes
175193
**contextAppOSVersion** | **string** | OS Version the application is running on. | Default value: OS Version.
176194
**contextAppOSBrowser** | **string** | An optional string browser name the application is running on. | Defaults to the browser name if the app is running from a browser.
177195
**contextAppOSBrowserVersion** | **string** | An optional string browser version the application is running on. | Defaults to the browser version if the app is running from a browser.
178-
**contextDataCenter** | **string** | Data center the application is running on or connected to. | Defaults to `nil`
179-
**contextDataCenterRegion** | **string** | Data center region. | Defaults to `nil`
196+
**contextDataCenter** | **string** | Data center the application is running on or connected to. | Defaults to `'undefined'`
197+
**contextDataCenterRegion** | **string** | Data center region. | Defaults to `'undefined'`
198+
**contextTags** | **Array.<String>** | Array of string tags you can use to tag your components for searching., | Defaults to `'undefined'`
199+
**contextAppSKU** | **string** | Application SKU. | Defaults to `'undefined'`
180200

181201

182202
## Documentation for AppEvent
183-
- [TrakerrApi.AppEvent](https://github.com/trakerr-io/trakerr-javascript/blob/master/generated/docs/AppEvent.md)
203+
- [TrakerrApi.AppEvent](https://github.com/trakerr-com/trakerr-javascript/blob/master/generated/docs/AppEvent.md)
184204

185205
## Developer dependencies
186206
- [grunt.js](https://gruntjs.com/) (if you want to build from source)
@@ -189,27 +209,27 @@ Name | Type | Description | Notes
189209
To install off a branch which may have experimental features, you can use:
190210

191211
```bash
192-
npm install --only=prod --save trakerr-io/trakerr-javascript#<branch name>
212+
npm install --only=prod --save trakerr-com/trakerr-javascript#<branch name>
193213
```
194214
without the angle brackets.
195215

196216
## Building from Source
197217
If you want to build from source for the browser, use the following command:
198218

199219
```bash
200-
npm install [--save] trakerr-io/trakerr-javascript
220+
npm install [--save] trakerr-com/trakerr-javascript
201221
```
202222

203223
or
204224

205225
```bash
206-
npm install [--save] trakerr-io/trakerr-javascript#<branch name>
226+
npm install [--save] trakerr-com/trakerr-javascript#<branch name>
207227
```
208228

209229
you can then use grunt to compile your own minified version of the code. The grunt task we use can be executed with:
210230

211231
```bash
212232
grunt build
213233
```
214-
in the folder with gruntFile.js. If you wish to modify or fork our code, simply running `grunt build` in the folder after acquire the code.
234+
in the folder with gruntFile.js. If you wish to modify or fork our code, simply run `grunt build` after modifying the code to try it out in your browser locally.
215235

dist/trakerr.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/trakerr.min.js

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

generated/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ This SDK is automatically generated by the [Swagger Codegen](https://github.com/
66

77
- API version: 1.0.0
88
- Package version: 1.0.0
9-
- Build date: 2017-03-13T16:35:17.206-07:00
9+
- Build date: 2017-05-05T15:16:43.345-07:00
1010
- Build package: class io.swagger.codegen.languages.JavascriptClientCodegen
1111

1212
## Installation

generated/docs/AppEvent.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Name | Type | Description | Notes
55
------------ | ------------- | ------------- | -------------
66
**apiKey** | **String** | API key generated for the application |
77
**logLevel** | **String** | (optional) Logging level, one of &#39;debug&#39;,&#39;info&#39;,&#39;warning&#39;,&#39;error&#39;, &#39;fatal&#39;, defaults to &#39;error&#39; | [optional]
8-
**classification** | **String** | (optional) one of &#39;error&#39; or a custom string for non-errors, defaults to &#39;error&#39; |
8+
**classification** | **String** | (optional) one of &#39;issue&#39; or a custom string for non-issues, defaults to &#39;issue&#39; |
99
**eventType** | **String** | type of the event or error (eg. NullPointerException) |
1010
**eventMessage** | **String** | message containing details of the event or error |
1111
**eventTime** | **Integer** | (optional) event time in ms since epoch | [optional]
@@ -24,6 +24,14 @@ Name | Type | Description | Notes
2424
**contextAppOSVersion** | **String** | (optional) OS version the application is running on | [optional]
2525
**contextDataCenter** | **String** | (optional) Data center the application is running on or connected to | [optional]
2626
**contextDataCenterRegion** | **String** | (optional) Data center region | [optional]
27+
**contextTags** | **[String]** | | [optional]
28+
**contextURL** | **String** | (optional) The full URL when running in a browser when the event was generated. | [optional]
29+
**contextOperationTimeMillis** | **Integer** | (optional) duration that this event took to occur in millis. Example - database call time in millis. | [optional]
30+
**contextCpuPercentage** | **Integer** | (optional) CPU utilization as a percent when event occured | [optional]
31+
**contextMemoryPercentage** | **Integer** | (optional) Memory utilization as a percent when event occured | [optional]
32+
**contextCrossAppCorrelationId** | **String** | (optional) Cross application correlation ID | [optional]
33+
**contextDevice** | **String** | (optional) Device information | [optional]
34+
**contextAppSku** | **String** | (optional) Application SKU | [optional]
2735
**customProperties** | [**CustomData**](CustomData.md) | | [optional]
2836
**customSegments** | [**CustomData**](CustomData.md) | | [optional]
2937

generated/src/trakerr/model/AppEvent.js

Lines changed: 66 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -53,36 +53,19 @@
5353
* @alias module:trakerr/model/AppEvent
5454
* @class
5555
* @param apiKey {String} API key generated for the application
56-
* @param classification {String} (optional) one of 'error' or a custom string for non-errors, defaults to 'error'
56+
* @param classification {String} (optional) one of 'issue' or a custom string for non-issues, defaults to 'issue'
5757
* @param eventType {String} type of the event or error (eg. NullPointerException)
5858
* @param eventMessage {String} message containing details of the event or error
5959
*/
6060
var exports = function(apiKey, logLevel, classification, eventType, eventMessage) {
6161
var _this = this;
6262

6363
_this['apiKey'] = apiKey;
64-
_this['logLevel'] = logLevel
64+
_this['logLevel'] = logLevel;
6565
_this['classification'] = classification;
6666
_this['eventType'] = eventType;
6767
_this['eventMessage'] = eventMessage;
6868

69-
70-
71-
72-
73-
74-
75-
76-
77-
78-
79-
80-
81-
82-
83-
84-
85-
8669
};
8770

8871
/**
@@ -159,6 +142,30 @@
159142
if (data.hasOwnProperty('contextDataCenterRegion')) {
160143
obj['contextDataCenterRegion'] = ApiClient.convertToType(data['contextDataCenterRegion'], 'String');
161144
}
145+
if (data.hasOwnProperty('contextTags')) {
146+
obj['contextTags'] = ApiClient.convertToType(data['contextTags'], ['String']);
147+
}
148+
if (data.hasOwnProperty('contextURL')) {
149+
obj['contextURL'] = ApiClient.convertToType(data['contextURL'], 'String');
150+
}
151+
if (data.hasOwnProperty('contextOperationTimeMillis')) {
152+
obj['contextOperationTimeMillis'] = ApiClient.convertToType(data['contextOperationTimeMillis'], 'Integer');
153+
}
154+
if (data.hasOwnProperty('contextCpuPercentage')) {
155+
obj['contextCpuPercentage'] = ApiClient.convertToType(data['contextCpuPercentage'], 'Integer');
156+
}
157+
if (data.hasOwnProperty('contextMemoryPercentage')) {
158+
obj['contextMemoryPercentage'] = ApiClient.convertToType(data['contextMemoryPercentage'], 'Integer');
159+
}
160+
if (data.hasOwnProperty('contextCrossAppCorrelationId')) {
161+
obj['contextCrossAppCorrelationId'] = ApiClient.convertToType(data['contextCrossAppCorrelationId'], 'String');
162+
}
163+
if (data.hasOwnProperty('contextDevice')) {
164+
obj['contextDevice'] = ApiClient.convertToType(data['contextDevice'], 'String');
165+
}
166+
if (data.hasOwnProperty('contextAppSku')) {
167+
obj['contextAppSku'] = ApiClient.convertToType(data['contextAppSku'], 'String');
168+
}
162169
if (data.hasOwnProperty('customProperties')) {
163170
obj['customProperties'] = CustomData.constructFromObject(data['customProperties']);
164171
}
@@ -180,7 +187,7 @@
180187
*/
181188
exports.prototype['logLevel'] = undefined;
182189
/**
183-
* (optional) one of 'error' or a custom string for non-errors, defaults to 'error'
190+
* (optional) one of 'issue' or a custom string for non-issues, defaults to 'issue'
184191
* @member {String} classification
185192
*/
186193
exports.prototype['classification'] = undefined;
@@ -273,6 +280,45 @@
273280
* @member {String} contextDataCenterRegion
274281
*/
275282
exports.prototype['contextDataCenterRegion'] = undefined;
283+
/**
284+
* @member {Array.<String>} contextTags
285+
*/
286+
exports.prototype['contextTags'] = undefined;
287+
/**
288+
* (optional) The full URL when running in a browser when the event was generated.
289+
* @member {String} contextURL
290+
*/
291+
exports.prototype['contextURL'] = undefined;
292+
/**
293+
* (optional) duration that this event took to occur in millis. Example - database call time in millis.
294+
* @member {Integer} contextOperationTimeMillis
295+
*/
296+
exports.prototype['contextOperationTimeMillis'] = undefined;
297+
/**
298+
* (optional) CPU utilization as a percent when event occured
299+
* @member {Integer} contextCpuPercentage
300+
*/
301+
exports.prototype['contextCpuPercentage'] = undefined;
302+
/**
303+
* (optional) Memory utilization as a percent when event occured
304+
* @member {Integer} contextMemoryPercentage
305+
*/
306+
exports.prototype['contextMemoryPercentage'] = undefined;
307+
/**
308+
* (optional) Cross application correlation ID
309+
* @member {String} contextCrossAppCorrelationId
310+
*/
311+
exports.prototype['contextCrossAppCorrelationId'] = undefined;
312+
/**
313+
* (optional) Device information
314+
* @member {String} contextDevice
315+
*/
316+
exports.prototype['contextDevice'] = undefined;
317+
/**
318+
* (optional) Application SKU
319+
* @member {String} contextAppSku
320+
*/
321+
exports.prototype['contextAppSku'] = undefined;
276322
/**
277323
* @member {module:trakerr/model/CustomData} customProperties
278324
*/

gruntFile.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,12 @@ module.exports = function (grunt) {
112112
},
113113
uglify: {
114114
options: {
115-
// sourceMap: true
116-
//, sourceMapName: 'src/app-uglified.js.map'
115+
sourceMap: true,
116+
sourceMapName: 'dist/trakerr.js.map'
117117
},
118118
sources: {
119119
src: ['generated/src/trakerr/**/*.js', 'index.js'],
120120
dest: 'dist/trakerr.min.js',
121-
sourceMap: true
122121
}
123122
},
124123
cssmin: {

0 commit comments

Comments
 (0)