From 07ec175931bfa3b59759e91594a5cdda346c64f5 Mon Sep 17 00:00:00 2001 From: Nick Johnstone Date: Wed, 24 Jun 2020 11:26:33 +1200 Subject: [PATCH] Only generate and attach correlationId if apm is present Saves both the UUID computation and transport bytes for the id if we're not going to use it in the end. --- lib/raygun.ts | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/raygun.ts b/lib/raygun.ts index 5401886..713baba 100644 --- a/lib/raygun.ts +++ b/lib/raygun.ts @@ -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) { @@ -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) { @@ -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);