Skip to content

Commit

Permalink
Merge pull request #87 from MindscapeHQ/notify-apm-of-exceptions
Browse files Browse the repository at this point in the history
Notify apm of exceptions
  • Loading branch information
Widdershin authored Jun 24, 2020
2 parents 5c68362 + 07ec175 commit 4a0b98c
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 5 deletions.
25 changes: 25 additions & 0 deletions lib/raygun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,25 @@ import { OfflineStorage } from "./raygun.offline";
import { startTimer } from './timer';
import * as raygunTransport from "./raygun.transport";

import { v4 as uuidv4 } from "uuid";

const debug = require("debug")("raygun");

let apmBridge:
| undefined
| null
| { notify(e: string | Error, s: string): void } = undefined;

try {
if (module.parent) {
apmBridge = module.parent.require('raygun-apm/lib/src/crash_reporting');
} else {
apmBridge = require('raygun-apm/lib/src/crash_reporting');
}
} catch (e) {
apmBridge = null;
}

type SendCB = (error: Error | null, items: string[] | undefined) => void;

const DEFAULT_BATCH_FREQUENCY = 1000; // ms
Expand Down Expand Up @@ -248,6 +265,14 @@ class Raygun {
: message;
}

if (apmBridge) {
const correlationId = uuidv4();

apmBridge.notify(exception, correlationId);

message.details.correlationId = correlationId;
}

if (this._isOffline) {
this.offlineStorage().save(JSON.stringify(message), callback || emptyCallback);
} else {
Expand Down
1 change: 1 addition & 0 deletions lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export type MessageDetails = {
userCustomData: CustomData;
machineName: string;
environment: Environment;
correlationId: string | null;
};

export type Environment = {
Expand Down
33 changes: 29 additions & 4 deletions package-lock.json

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

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"@types/stack-trace": "0.0.29",
"express": "^4.17.1",
"http-terminator": "^2.0.3",
"@types/uuid": "^7.0.2",
"jshint": "^2.5.6",
"nock": "~9",
"prettier": "^2.0.4",
Expand All @@ -57,7 +58,8 @@
"dependencies": {
"debug": "^4.1.1",
"object-to-human-string": "0.0.3",
"stack-trace": "0.0.6"
"stack-trace": "0.0.6",
"uuid": "^7.0.3"
},
"keywords": []
}

0 comments on commit 4a0b98c

Please sign in to comment.