diff --git a/src/controllers/bulkUpload.ts b/src/controllers/bulkUpload.ts index ab49368461..96216e3718 100644 --- a/src/controllers/bulkUpload.ts +++ b/src/controllers/bulkUpload.ts @@ -1,5 +1,5 @@ /* eslint-disable global-require, import/no-dynamic-require, @typescript-eslint/no-unused-vars */ -import customLogger from "@rudderstack/integrations-lib/build/structured-logger"; +import logger from "@rudderstack/integrations-lib/build/structured-logger"; import { client as errNotificationClient } from '../util/errorNotifier'; import { CatchErr, ContextBodySimple } from '../util/types'; // TODO: To be refactored and redisgned @@ -31,7 +31,7 @@ const getReqMetadata = (ctx) => { }; export const fileUpload = async (ctx) => { - customLogger.debug( + logger.debug( 'Native(Bulk-Upload): Request to transformer:: /fileUpload route', JSON.stringify(ctx.request.body), ); @@ -69,7 +69,7 @@ export const fileUpload = async (ctx) => { }); } ctx.body = response; - customLogger.debug( + logger.debug( 'Native(Bulk-Upload): Response from transformer:: /fileUpload route', JSON.stringify(ctx.body), ); @@ -77,7 +77,7 @@ export const fileUpload = async (ctx) => { }; export const pollStatus = async (ctx) => { - customLogger.debug( + logger.debug( 'Native(Bulk-Upload): Request to transformer:: /pollStatus route', JSON.stringify(ctx.request.body), ); @@ -104,7 +104,7 @@ export const pollStatus = async (ctx) => { }); } ctx.body = response; - customLogger.debug( + logger.debug( 'Native(Bulk-Upload): Request from transformer:: /pollStatus route', JSON.stringify(ctx.body), ); @@ -112,7 +112,7 @@ export const pollStatus = async (ctx) => { }; export const getWarnJobStatus = async (ctx) => { - customLogger.debug( + logger.debug( 'Native(Bulk-Upload): Request to transformer:: /getWarningJobs route', JSON.stringify(ctx.request.body), ); @@ -140,7 +140,7 @@ export const getWarnJobStatus = async (ctx) => { }); } ctx.body = response; - customLogger.debug( + logger.debug( 'Native(Bulk-Upload): Request from transformer:: /getWarningJobs route', JSON.stringify(ctx.body), ); @@ -148,7 +148,7 @@ export const getWarnJobStatus = async (ctx) => { }; export const getFailedJobStatus = async (ctx) => { - customLogger.debug( + logger.debug( 'Native(Bulk-Upload): Request to transformer:: /getFailedJobs route', JSON.stringify(ctx.request.body), ); @@ -176,7 +176,7 @@ export const getFailedJobStatus = async (ctx) => { }); } ctx.body = response; - customLogger.debug( + logger.debug( 'Native(Bulk-Upload): Request from transformer:: /getFailedJobs route', JSON.stringify(ctx.body), ); diff --git a/src/controllers/delivery.ts b/src/controllers/delivery.ts index c06bbd6b6a..cb37cc149b 100644 --- a/src/controllers/delivery.ts +++ b/src/controllers/delivery.ts @@ -1,7 +1,7 @@ /* eslint-disable prefer-destructuring */ /* eslint-disable sonarjs/no-duplicate-string */ import { Context } from 'koa'; -import customLogger from "@rudderstack/integrations-lib/build/structured-logger"; +import logger from "@rudderstack/integrations-lib/build/structured-logger"; import { MiscService } from '../services/misc'; import { DeliveriesResponse, @@ -21,7 +21,7 @@ const NON_DETERMINABLE = 'Non-determinable'; export class DeliveryController { public static async deliverToDestination(ctx: Context) { - customLogger.debug('Native(Delivery):: Request to transformer::', JSON.stringify(ctx.request.body)); + logger.debug('Native(Delivery):: Request to transformer::', JSON.stringify(ctx.request.body)); let deliveryResponse: DeliveryResponse; const requestMetadata = MiscService.getRequestMetadata(ctx); const deliveryRequest = ctx.request.body as ProxyDeliveryRequest; @@ -51,12 +51,12 @@ export class DeliveryController { ctx.body = { output: deliveryResponse }; ControllerUtility.deliveryPostProcess(ctx, deliveryResponse.status); - customLogger.debug('Native(Delivery):: Response from transformer::', JSON.stringify(ctx.body)); + logger.debug('Native(Delivery):: Response from transformer::', JSON.stringify(ctx.body)); return ctx; } public static async deliverToDestinationV1(ctx: Context) { - customLogger.debug('Native(Delivery):: Request to transformer::', JSON.stringify(ctx.request.body)); + logger.debug('Native(Delivery):: Request to transformer::', JSON.stringify(ctx.request.body)); let deliveryResponse: DeliveriesResponse; const requestMetadata = MiscService.getRequestMetadata(ctx); const deliveryRequest = ctx.request.body as ProxyDeliveriesRequest; @@ -86,12 +86,12 @@ export class DeliveryController { ctx.body = { output: deliveryResponse }; ControllerUtility.deliveryPostProcess(ctx, deliveryResponse.status); - customLogger.debug('Native(Delivery):: Response from transformer::', JSON.stringify(ctx.body)); + logger.debug('Native(Delivery):: Response from transformer::', JSON.stringify(ctx.body)); return ctx; } public static async testDestinationDelivery(ctx: Context) { - customLogger.debug( + logger.debug( 'Native(Delivery-Test):: Request to transformer::', JSON.stringify(ctx.request.body), ); @@ -112,7 +112,7 @@ export class DeliveryController { ); ctx.body = { output: response }; ControllerUtility.postProcess(ctx); - customLogger.debug('Native(Delivery-Test):: Response from transformer::', JSON.stringify(ctx.body)); + logger.debug('Native(Delivery-Test):: Response from transformer::', JSON.stringify(ctx.body)); return ctx; } } diff --git a/src/controllers/destination.ts b/src/controllers/destination.ts index db5ecda4e4..b22a09a7c5 100644 --- a/src/controllers/destination.ts +++ b/src/controllers/destination.ts @@ -1,5 +1,5 @@ import { Context } from 'koa'; -import customLogger from "@rudderstack/integrations-lib/build/structured-logger"; +import logger from "@rudderstack/integrations-lib/build/structured-logger"; import { MiscService } from '../services/misc'; import { DestinationPreTransformationService } from '../services/destination/preTransformation'; import { DestinationPostTransformationService } from '../services/destination/postTransformation'; @@ -19,7 +19,7 @@ import { DynamicConfigParser } from '../util/dynamicConfigParser'; export class DestinationController { public static async destinationTransformAtProcessor(ctx: Context) { const startTime = new Date(); - customLogger.debug( + logger.info( 'Native(Process-Transform):: Requst to transformer::', JSON.stringify(ctx.request.body), ); @@ -68,7 +68,7 @@ export class DestinationController { } ctx.body = resplist; ControllerUtility.postProcess(ctx); - customLogger.debug( + logger.info( 'Native(Process-Transform):: Response from transformer::', JSON.stringify(ctx.body), ); @@ -93,9 +93,9 @@ export class DestinationController { public static async destinationTransformAtRouter(ctx: Context) { const startTime = new Date(); - customLogger.debug( + logger.info( 'Native(Router-Transform):: Requst to transformer::', - JSON.stringify(ctx.request.body), + ctx.request.body, ); const requestMetadata = MiscService.getRequestMetadata(ctx); const routerRequest = ctx.request.body as RouterTransformationRequest; @@ -140,7 +140,7 @@ export class DestinationController { version: 'v0', ...metaTags, }); - customLogger.debug( + logger.info( 'Native(Router-Transform):: Response from transformer::', JSON.stringify(ctx.body), ); @@ -154,7 +154,7 @@ export class DestinationController { } public static batchProcess(ctx: Context) { - customLogger.debug( + logger.info( 'Native(Process-Transform-Batch):: Requst to transformer::', JSON.stringify(ctx.request.body), ); @@ -189,7 +189,7 @@ export class DestinationController { ctx.body = [errResp]; } ControllerUtility.postProcess(ctx); - customLogger.debug( + logger.info( 'Native(Process-Transform-Batch):: Response from transformer::', JSON.stringify(ctx.body), ); diff --git a/src/controllers/regulation.ts b/src/controllers/regulation.ts index fd3b1b19c4..158bec6635 100644 --- a/src/controllers/regulation.ts +++ b/src/controllers/regulation.ts @@ -1,5 +1,5 @@ import { Context } from 'koa'; -import customLogger from "@rudderstack/integrations-lib/build/structured-logger"; +import logger from "@rudderstack/integrations-lib/build/structured-logger"; import { UserDeletionRequest, UserDeletionResponse } from '../types'; import { ServiceSelector } from '../helpers/serviceSelector'; import tags from '../v0/util/tags'; @@ -10,7 +10,7 @@ import { CatchErr } from '../util/types'; export class RegulationController { public static async deleteUsers(ctx: Context) { - customLogger.debug( + logger.debug( 'Native(Process-Transform):: Requst to transformer::', JSON.stringify(ctx.request.body), ); @@ -23,7 +23,7 @@ export class RegulationController { rudderDestInfo = destInfoHeader; } } catch (error) { - customLogger.error(`Error while getting rudderDestInfo header value: ${error}`); + logger.error(`Error while getting rudderDestInfo header value: ${error}`); } const userDeletionRequests = ctx.request.body as UserDeletionRequest[]; diff --git a/src/controllers/source.ts b/src/controllers/source.ts index 9115215e73..a17cb09d58 100644 --- a/src/controllers/source.ts +++ b/src/controllers/source.ts @@ -1,5 +1,5 @@ import { Context } from 'koa'; -import customLogger from "@rudderstack/integrations-lib/build/structured-logger"; +import logger from "@rudderstack/integrations-lib/build/structured-logger"; import { MiscService } from '../services/misc'; import { ServiceSelector } from '../helpers/serviceSelector'; import { ControllerUtility } from './util'; @@ -7,7 +7,7 @@ import { SourcePostTransformationService } from '../services/source/postTransfor export class SourceController { public static async sourceTransform(ctx: Context) { - customLogger.debug( + logger.debug( 'Native(Source-Transform):: Request to transformer::', JSON.stringify(ctx.request.body), ); @@ -34,7 +34,7 @@ export class SourceController { ctx.body = [resp]; } ControllerUtility.postProcess(ctx); - customLogger.debug( + logger.debug( 'Native(Source-Transform):: Response from transformer::', JSON.stringify(ctx.body), ); diff --git a/src/index.ts b/src/index.ts index cfdac7fd9e..5772f10765 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,7 +2,7 @@ import Koa from 'koa'; import bodyParser from 'koa-bodyparser'; import gracefulShutdown from 'http-graceful-shutdown'; import dotenv from 'dotenv'; -import customLogger from "@rudderstack/integrations-lib/build/structured-logger"; +import logger from "@rudderstack/integrations-lib/build/structured-logger"; import cluster from './util/cluster'; import { metricsRouter } from './routes/metricsRouter'; import { addStatMiddleware, addRequestSizeMiddleware, initPyroscope } from './middleware'; @@ -32,13 +32,13 @@ app.use( addRequestSizeMiddleware(app); addSwaggerRoutes(app); -customLogger.info('Using new routes'); +logger.info('Using new routes'); applicationRoutes(app); function finalFunction() { RedisDB.disconnect(); - customLogger.info('Redis client disconnected'); - customLogger.error(`Process (pid: ${process.pid}) was gracefully shutdown`); + logger.info('Redis client disconnected'); + logger.error(`Process (pid: ${process.pid}) was gracefully shutdown`); logProcessInfo(); } @@ -59,15 +59,15 @@ if (clusterEnabled) { const server = app.listen(port); process.on('SIGTERM', () => { - customLogger.error(`SIGTERM signal received`); + logger.error(`SIGTERM signal received`); }); process.on('SIGINT', () => { - customLogger.error(`SIGINT signal received`); + logger.error(`SIGINT signal received`); }); process.on('SIGSEGV', () => { - customLogger.error(`SIGSEGV - JavaScript memory error occurred`); + logger.error(`SIGSEGV - JavaScript memory error occurred`); }); gracefulShutdown(server, { @@ -77,7 +77,7 @@ if (clusterEnabled) { finally: finalFunction, }); - customLogger.info(`App started. Listening on port: ${port}`); + logger.info(`App started. Listening on port: ${port}`); } export default app; diff --git a/src/services/misc.ts b/src/services/misc.ts index f3d01ce4ee..8afb18c1cb 100644 --- a/src/services/misc.ts +++ b/src/services/misc.ts @@ -2,9 +2,10 @@ import fs from 'fs'; import path from 'path'; import { Context } from 'koa'; -import customLogger from '@rudderstack/integrations-lib'; +import { LoggableExtraData } from '@rudderstack/integrations-lib'; +import logger from "@rudderstack/integrations-lib/build/structured-logger"; import { DestHandlerMap } from '../constants/destinationCanonicalNames'; -import { ErrorDetailer, LoggableExtraData, Metadata } from '../types'; +import { ErrorDetailer, Metadata } from '../types'; import { getCPUProfile, getHeapProfile } from '../middleware'; export class MiscService { @@ -85,11 +86,23 @@ export class MiscService { ...(errorDetailer?.destType && { destType: errorDetailer.destType }), module: errorDetailer.module, implementation: errorDetailer.implementation, + feature: errorDetailer.feature, }; } public static logError(errorMessage: string, errorDetailer: ErrorDetailer) { const loggableExtraData: Partial = this.getLoggableData(errorDetailer); - customLogger.errorw(errorMessage || '', loggableExtraData); + logger.errorw(errorMessage || '', loggableExtraData); } + + public static logInfo(message: string, loggingDetails: ErrorDetailer) { + const loggableExtraData: Partial = this.getLoggableData(loggingDetails); + logger.infow(message || '', loggableExtraData); + } + + public static logDebug(errorMessage: string, errorDetailer: ErrorDetailer) { + const loggableExtraData: Partial = this.getLoggableData(errorDetailer); + logger.debugw(errorMessage || '', loggableExtraData); + } + } diff --git a/src/services/profile.ts b/src/services/profile.ts index f8ac297545..8351d476f7 100644 --- a/src/services/profile.ts +++ b/src/services/profile.ts @@ -6,7 +6,7 @@ import v8 from 'v8'; import pprof, { heap } from '@datadog/pprof'; import { promisify } from 'util'; -import customLogger from "@rudderstack/integrations-lib/build/structured-logger"; +import logger from "@rudderstack/integrations-lib/build/structured-logger"; // eslint-disable-next-line @typescript-eslint/no-unused-vars import { CatchErr } from '../util/types'; @@ -17,8 +17,8 @@ const intervalBytes = parseInt(process.env.PROF_INTERVAL_BYTES || '524288', 10); // The maximum stack depth for samples collected. const stackDepth = parseInt(process.env.PROF_STACK_DEPTH || '64', 10); -customLogger.info(`Stack Depth set: ${stackDepth}`); -customLogger.info(`Interval Bytes set: ${intervalBytes}`); +logger.info(`Stack Depth set: ${stackDepth}`); +logger.info(`Interval Bytes set: ${intervalBytes}`); heap.start(intervalBytes, stackDepth); @@ -44,7 +44,7 @@ export class ProfileService { resolve(Buffer.concat(chunks).toString()); }); readable.on('error', (err) => { - customLogger.error(err); + logger.error(err); reject(err); }); }); @@ -69,7 +69,7 @@ export class ProfileService { }); upload.on('httpUploadProgress', (progress) => { - customLogger.info(progress); + logger.info(progress); }); const uploadResult = await upload.done(); @@ -82,7 +82,7 @@ export class ProfileService { try { const supportedCloudProvidersForDumpStorage = ['aws']; const shouldGenerateLocally = !credBucketDetails.sendTo; - customLogger.info('Before Heapsnapshot converted into a readable stream'); + logger.info('Before Heapsnapshot converted into a readable stream'); let fileName = ''; // eslint-disable-next-line no-param-reassign format = 'pb.gz'; @@ -97,18 +97,18 @@ export class ProfileService { snapshotReadableStream = await pprof.encode(profile); } - customLogger.info('Heapsnapshot into a buffer'); + logger.info('Heapsnapshot into a buffer'); fileName = `heap_${moment.utc().format('YYYY-MM-DD_HH:mm:ss.sss')}.${format}`; let data; if (shouldGenerateLocally) { - customLogger.info('Before pipeline'); + logger.info('Before pipeline'); try { await writeFileProm(fileName, snapshotReadableStream); } catch (error: CatchErr) { - customLogger.error('Error occurred:', error); + logger.error('Error occurred:', error); throw new Error(error); } - customLogger.info('After pipeline'); + logger.info('After pipeline'); } else if (credBucketDetails.sendTo) { if (credBucketDetails.sendTo === 'aws') { data = await this.uploadToAWS(credBucketDetails, fileName, snapshotReadableStream); @@ -121,7 +121,7 @@ export class ProfileService { } } // snapshotReadableStream.destroy(); - customLogger.info('Success', data); + logger.info('Success', data); return { success: true, message: `Generated ${ @@ -129,7 +129,7 @@ export class ProfileService { } with filename: ${fileName}`, }; } catch (error: CatchErr) { - customLogger.error(error); + logger.error(error); return { success: false, message: error.message, diff --git a/src/services/trackingPlan.ts b/src/services/trackingPlan.ts index f5b3bcccfa..883293e5f7 100644 --- a/src/services/trackingPlan.ts +++ b/src/services/trackingPlan.ts @@ -1,4 +1,4 @@ -import customLogger from "@rudderstack/integrations-lib/build/structured-logger"; +import logger from "@rudderstack/integrations-lib/build/structured-logger"; import { RetryRequestError, RespStatusError, constructValidationErrors } from '../util/utils'; import { getMetadata } from '../v0/util'; import eventValidator from '../util/eventValidation'; @@ -44,7 +44,7 @@ export class TrackingPlanservice { } } catch (error) { const errMessage = `Error occurred while validating : ${error}`; - customLogger.error(errMessage); + logger.error(errMessage); let status = 200; if (error instanceof RetryRequestError) { ctxStatusCode = error.statusCode; diff --git a/src/services/userTransform.ts b/src/services/userTransform.ts index 5d555b36c4..d1a358fefd 100644 --- a/src/services/userTransform.ts +++ b/src/services/userTransform.ts @@ -1,6 +1,6 @@ import groupBy from 'lodash/groupBy'; import isEmpty from 'lodash/isEmpty'; -import customLogger from "@rudderstack/integrations-lib/build/structured-logger"; +import logger from "@rudderstack/integrations-lib/build/structured-logger"; import { userTransformHandler } from '../routerUtils'; import { UserTransformationLibrary, @@ -76,7 +76,7 @@ export class UserTransformService { if (!transformationVersionId) { const errorMessage = 'Transformation VersionID not found'; - customLogger.error(`[CT] ${errorMessage}`); + logger.error(`[CT] ${errorMessage}`); transformedEvents.push({ statusCode: 400, error: errorMessage, @@ -141,7 +141,7 @@ export class UserTransformService { transformedEvents.push(...transformedEventsWithMetadata); } catch (error: CatchErr) { - customLogger.error(error); + logger.error(error); let status = 400; const errorString = error.toString(); if (error instanceof RetryRequestError) { @@ -198,7 +198,7 @@ export class UserTransformService { throw new Error('Invalid request. Missing events'); } - customLogger.debug(`[CT] Test Input Events: ${JSON.stringify(events)}`); + logger.debug(`[CT] Test Input Events: ${JSON.stringify(events)}`); // eslint-disable-next-line no-param-reassign trRevCode.versionId = 'testVersionId'; response.body = await userTransformHandler()( @@ -208,7 +208,7 @@ export class UserTransformService { trRevCode, true, ); - customLogger.debug(`[CT] Test Output Events: ${JSON.stringify(response.body.transformedEvents)}`); + logger.debug(`[CT] Test Output Events: ${JSON.stringify(response.body.transformedEvents)}`); response.status = 200; } catch (error: CatchErr) { response.status = 400; diff --git a/src/types/index.ts b/src/types/index.ts index 99cf6052aa..f4432e5c2a 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -304,14 +304,6 @@ type SourceInput = { event: NonNullable[]; source?: Source; }; -type LoggableExtraData = { - destinationId: string; - workspaceId: string; - module: string; - implementation: string; - sourceId: string; - destType: string; -}; export { ComparatorInput, DeliveryJobState, @@ -340,5 +332,4 @@ export { UserTransformationLibrary, UserTransformationResponse, UserTransformationServiceResponse, - LoggableExtraData, }; diff --git a/src/v0/destinations/campaign_manager/transform.js b/src/v0/destinations/campaign_manager/transform.js index 3b480dbac2..b2bba5139a 100644 --- a/src/v0/destinations/campaign_manager/transform.js +++ b/src/v0/destinations/campaign_manager/transform.js @@ -1,4 +1,6 @@ const { InstrumentationError } = require('@rudderstack/integrations-lib'); +import logger from "@rudderstack/integrations-lib/build/structured-logger"; +import { MiscService } from '../../../services/misc'; const lodash = require('lodash'); const { EventType } = require('../../../constants'); const { @@ -246,6 +248,7 @@ const batchEvents = (eventChunksArray) => { const processRouterDest = async (inputs, reqMetadata) => { const errorRespEvents = checkInvalidRtTfEvents(inputs); + logger.debugw('infow processing batch request for', reqMetadata.loggerCtx); if (errorRespEvents.length > 0) { return errorRespEvents; }