Skip to content

Commit

Permalink
Only generate and attach correlationId if apm is present
Browse files Browse the repository at this point in the history
Saves both the UUID computation and transport bytes for the id if we're
not going to use it in the end.
  • Loading branch information
Widdershin committed Jun 23, 2020
1 parent 8d311a0 commit 07ec175
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions lib/raygun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ import { v4 as uuidv4 } from "uuid";

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


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

try {
if (module.parent) {
Expand Down Expand Up @@ -222,12 +224,6 @@ class Raygun {
request?: Request,
tags?: Tag[]
): Message {
const correlationId = uuidv4();

if (apmBridge) {
apmBridge.notify(exception, correlationId);
}

let mergedTags: Tag[] = [];

if (this._tags) {
Expand Down Expand Up @@ -269,7 +265,13 @@ class Raygun {
: message;
}

message.details.correlationId = correlationId;
if (apmBridge) {
const correlationId = uuidv4();

apmBridge.notify(exception, correlationId);

message.details.correlationId = correlationId;
}

if (this._isOffline) {
this.offlineStorage().save(JSON.stringify(message), callback || emptyCallback);
Expand Down

0 comments on commit 07ec175

Please sign in to comment.