From 73f656d3df992c9c24dd7a21a58b2ce19803c595 Mon Sep 17 00:00:00 2001 From: Dima Grossman Date: Mon, 2 Oct 2023 10:09:26 +0300 Subject: [PATCH 1/2] feat: add newrelic custom attributes --- .../src/app/workflow/usecases/run-job/run-job.usecase.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/apps/worker/src/app/workflow/usecases/run-job/run-job.usecase.ts b/apps/worker/src/app/workflow/usecases/run-job/run-job.usecase.ts index f7b1f2b4e5b..f371b07e827 100644 --- a/apps/worker/src/app/workflow/usecases/run-job/run-job.usecase.ts +++ b/apps/worker/src/app/workflow/usecases/run-job/run-job.usecase.ts @@ -1,3 +1,5 @@ +const nr = require('newrelic'); + import { Injectable, Logger } from '@nestjs/common'; import { JobEntity, JobRepository, JobStatusEnum } from '@novu/dal'; import { StepTypeEnum } from '@novu/shared'; @@ -32,6 +34,12 @@ export class RunJob { const job = await this.jobRepository.findById(command.jobId); if (!job) throw new PlatformException(`Job with id ${command.jobId} not found`); + nr.addCustomAttributes({ + jobType: job.type, + organizationId: job._organizationId, + transactionId: job.transactionId, + }); + try { this.logger?.assign({ transactionId: job.transactionId, From 638683b3308214dfa781779d6c28ac9cd97766a6 Mon Sep 17 00:00:00 2001 From: Dima Grossman Date: Mon, 2 Oct 2023 20:18:04 +0300 Subject: [PATCH 2/2] refactor: custom attributes context reuse --- .../workflow/usecases/run-job/run-job.usecase.ts | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/apps/worker/src/app/workflow/usecases/run-job/run-job.usecase.ts b/apps/worker/src/app/workflow/usecases/run-job/run-job.usecase.ts index f371b07e827..39849b1979c 100644 --- a/apps/worker/src/app/workflow/usecases/run-job/run-job.usecase.ts +++ b/apps/worker/src/app/workflow/usecases/run-job/run-job.usecase.ts @@ -34,19 +34,18 @@ export class RunJob { const job = await this.jobRepository.findById(command.jobId); if (!job) throw new PlatformException(`Job with id ${command.jobId} not found`); - nr.addCustomAttributes({ - jobType: job.type, - organizationId: job._organizationId, - transactionId: job.transactionId, - }); - try { - this.logger?.assign({ + const contextData = { transactionId: job.transactionId, environmentId: job._environmentId, organizationId: job._organizationId, jobId: job._id, - }); + jobType: job.type, + }; + + nr.addCustomAttributes(contextData); + + this.logger?.assign(contextData); } catch (e) { Logger.error(e, 'RunJob'); }