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

Add typescript types and onboarding ping #525

Merged
merged 19 commits into from
Jun 16, 2024
Merged
Show file tree
Hide file tree
Changes from 17 commits
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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Unused normalize.css file

-->
## [3.1.0]

### Added
Hamish-taylor marked this conversation as resolved.
Show resolved Hide resolved
- Added a ping to tell Raygun that raygun4js has been set up correctly, this information will be used to help users when setting up a new application. This can be disabled using the new `sendPing` option e.g., `rg4js('sendPing', false)`. The ping contains the version of Raygun4js being used, aswell as what products that have been enabled (CrashReporting and or Real User Monitoring)
- Moved the typescript types into the main raygun4js repo
- Added an new option for enabling Real user monitoring
Hamish-taylor marked this conversation as resolved.
Show resolved Hide resolved

## [3.0.1]

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "raygun4js",
"version": "2.28.0",
"version": "3.1.0",
"homepage": "http://raygun.com",
"authors": [
"Mindscape <[email protected]>"
Expand Down
2,051 changes: 1,021 additions & 1,030 deletions package-lock.json

Large diffs are not rendered by default.

24 changes: 13 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
"name": "raygun4js",
"main": "dist/raygun.umd.js",
"files": [
"dist/*"
"dist/*",
"types/*"
],
"title": "Raygun4js",
"description": "Raygun.com plugin for JavaScript",
"version": "3.0.1",
"version": "3.1.0",
"homepage": "https://github.com/MindscapeHQ/raygun4js",
"author": {
"name": "MindscapeHQ",
Expand All @@ -16,17 +17,18 @@
"type": "git",
"url": "https://github.com/MindscapeHQ/raygun4js.git"
},
"types": "./types/index.d.ts",
"bugs": "https://github.com/MindscapeHQ/raygun4js/issues",
"license": "SEE LICENSE IN https://github.com/MindscapeHQ/raygun4js/blob/master/LICENSE",
"devDependencies": {
"@wdio/cli": "^8.11.2",
"@wdio/dot-reporter": "^8.11.0",
"@wdio/jasmine-framework": "^8.11.2",
"@wdio/local-runner": "^8.11.2",
"@wdio/selenium-standalone-service": "^8.11.0",
"@wdio/spec-reporter": "^8.11.2",
"@wdio/static-server-service": "^8.11.0",
"chromedriver": "^119.0.1",
"@wdio/cli": "^8.36.1",
"@wdio/dot-reporter": "^8.36.1",
"@wdio/jasmine-framework": "^8.36.1",
"@wdio/local-runner": "^8.36.1",
"@wdio/selenium-standalone-service": "^8.14.0",
"@wdio/spec-reporter": "^8.36.1",
"@wdio/static-server-service": "^8.36.1",
"chromedriver": "^124.0.3",
"cross-env": "^7.0.3",
"grunt": "^1.6.1",
"grunt-browserify": "^6.0.0",
Expand All @@ -36,7 +38,7 @@
"grunt-contrib-uglify": "^5.2.2",
"grunt-contrib-watch": "^1.1.0",
"grunt-string-replace": "^1.3.1",
"jasmine": "^5.0.2",
"jasmine": "^5.1.0",
"underscore": "^1.13.6",
"wdio-chromedriver-service": "^8.1.1"
},
Expand Down
2 changes: 1 addition & 1 deletion raygun4js.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>raygun4js</id>
<version>2.28.0</version>
<version>3.1.0</version>
<title>Raygun4js</title>
<authors>Raygun Limited</authors>
<owners>Raygun Limited</owners>
Expand Down
15 changes: 7 additions & 8 deletions src/raygun.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ var raygunFactory = function (window, $, undefined) {
};

var _userKey = 'raygun4js-userid';

// State variables
var _traceKit = TraceKit,
_raygun = window.Raygun,
Expand All @@ -56,7 +55,6 @@ var raygunFactory = function (window, $, undefined) {
_groupingKeyCallback,
_beforeXHRCallback,
_afterSendCallback,
_raygunApiUrl = 'https://api.raygun.io',
_excludedHostnames = null,
_excludedUserAgents = null,
_filterScope = 'customData',
Expand Down Expand Up @@ -101,6 +99,7 @@ var raygunFactory = function (window, $, undefined) {
init: function (key, options, customdata) {
_traceKit.remoteFetching = false;

Raygun.Options._raygunApiUrl = 'https://api.raygun.io';
this.Options._raygunApiKey = key;

if (customdata) {
Expand Down Expand Up @@ -129,8 +128,8 @@ var raygunFactory = function (window, $, undefined) {
_trackViewportDimensions = options.trackViewportDimensions === undefined ? true : options.trackViewportDimensions;

if (options.apiUrl) {
_raygunApiUrl = options.apiUrl;
_customEndpointSet = true;
this.Options._raygunApiUrl = options.apiUrl;
this.Options._customEndpointSet = true;
}

if (typeof options.wrapAsynchronousCallbacks !== 'undefined') {
Expand All @@ -151,8 +150,8 @@ var raygunFactory = function (window, $, undefined) {
}

if (options.apiEndpoint) {
_raygunApiUrl = options.apiEndpoint;
_customEndpointSet = true;
this.Options._raygunApiUrl = options.apiEndpoint;
this.Options._customEndpointSet = true;
}

if (options.from) {
Expand Down Expand Up @@ -500,7 +499,7 @@ var raygunFactory = function (window, $, undefined) {
var startRum = function () {
_rum = new Raygun.RealUserMonitoring(
Raygun.Options._raygunApiKey,
_raygunApiUrl,
Raygun.Options._raygunApiUrl,
makePostCorsRequest,
_user,
_version,
Expand Down Expand Up @@ -978,7 +977,7 @@ var raygunFactory = function (window, $, undefined) {
}

Raygun.Utilities.log('Sending exception data to Raygun:', data);
var url = _raygunApiUrl + '/entries?apikey=' + encodeURIComponent(Raygun.Options._raygunApiKey);
var url = Raygun.Options._raygunApiUrl + '/entries?apikey=' + encodeURIComponent(Raygun.Options._raygunApiKey);
makePostCorsRequest(url, JSON.stringify(data));
}

Expand Down
62 changes: 55 additions & 7 deletions src/raygun.loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,18 @@
delayedCommands = [],
apiKey,
options,
attach,
enablePulse,
noConflict,
realUserMonitoringEnabled = false,
crashReportingEnabled = false,
captureUnhandledRejections;

var metadata = {
ping : {
sendPing : true,
pingIntervalId : -1,
failedPings : 0
},
};
var snippetOnErrorSignature = ['function (b,c,d,f,g){', '||(g=new Error(b)),a[e].q=a[e].q||[]'];

errorQueue = window[window['RaygunObject']].q;
Expand Down Expand Up @@ -51,6 +58,9 @@

if (key) {
switch (key) {
case 'sendPing':
metadata.ping.sendPing = value;
break;
// React Native only
case 'boot':
onLoadHandler();
Expand All @@ -68,12 +78,13 @@
break;
case 'attach':
case 'enableCrashReporting':
attach = value;
crashReportingEnabled = value;
hasLoaded = true;
break;
case 'enableRealUserMonitoring':
case 'enableRUM':
case 'enablePulse':
enablePulse = value;
realUserMonitoringEnabled = value;
hasLoaded = true;
break;
case 'detach':
Expand Down Expand Up @@ -218,6 +229,39 @@
}
};

function ping() {
if(metadata.ping.failedPings > 10) {
clearInterval(metadata.ping.pingIntervalId);
Hamish-taylor marked this conversation as resolved.
Show resolved Hide resolved
}

var url = Raygun.Options._raygunApiUrl + "/ping?apiKey=" + encodeURIComponent(Raygun.Options._raygunApiKey);
var data = {
crashReportingEnabled: crashReportingEnabled ? true : false,
realUserMonitoringEnabled: realUserMonitoringEnabled ? true : false,
providerName: "raygun4js",
providerVersion: '{{VERSION}}'
};

fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
}).then(function(response) {
if (response.ok) {
metadata.ping.failedPings = 0;
} else {
// Request failed
metadata.ping.failedPings++;
}
})
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit ugly here, we normally put the .catch in the line. No worries for now

.catch(function() {
metadata.ping.failedPings++;
});
}


var installGlobalExecutor = function() {
window[window['RaygunObject']] = function() {
return executor(arguments);
Expand All @@ -232,21 +276,21 @@
if (noConflict) {
rg = Raygun.noConflict();
}

if (apiKey) {
if (!options) {
options = {};
}

if (enablePulse) {
if (realUserMonitoringEnabled) {
options.disablePulse = false;
}

options.from = 'onLoad';
rg.init(apiKey, options, null);
}

if (attach) {
if (crashReportingEnabled) {
rg.attach();

errorQueue = window[window['RaygunObject']].q;
Expand Down Expand Up @@ -275,6 +319,10 @@
installGlobalExecutor();
}

if(metadata.ping.sendPing) {
ping(); //call immediately
metadata.ping.pingIntervalId = setInterval(ping, 1000 * 60 * 5); //5 minutes
}
window[window['RaygunObject']].q = errorQueue;
};

Expand Down
Loading
Loading