Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add logger at integration level #3401

Merged
merged 42 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
b982cb4
chore: add logging capability at integration level
May 21, 2024
37b4f47
chore: add structured logger in klaviyo
May 22, 2024
445ce1f
chore: add structured logger to src transform & proxyV1 integrations
May 22, 2024
5bbb38e
chore: add logging to gaec
May 27, 2024
0b7bfec
chore: add structured logger to transformer logger & use it for gaec …
May 27, 2024
65b6146
chore: structured logger referred from transformer logger refactor
May 27, 2024
e533b88
chore: response logging in garl
May 27, 2024
2939647
chore: add support for request logging in logger & gaec handler
May 27, 2024
734f900
chore: merge context & metadata for default notifier into a single ob…
May 27, 2024
8a6bf3a
chore: update response log message & responseDetails
May 27, 2024
4fc6c07
chore: add log to trck the request for offline conversion creation fo…
ItsSudip Jun 4, 2024
8ad1a5f
chore: update loglevel to warn for request and response logs
ItsSudip Jun 4, 2024
2d19625
chore: refactor with different convention of log levels
Jun 10, 2024
827157b
chore: set appropriate level for metalogger in benchmarking
Jun 11, 2024
12a4ce2
chore: load env in logger and fix logLevel condition logic
ItsSudip Jun 12, 2024
efdb9c5
chore: add request logs for google adwords destinations
Jun 12, 2024
365f738
chore: call env load before importing logger
Jun 12, 2024
cc43744
chore: upgrade integrations-lib
Jun 13, 2024
ab27fb7
Merge remote-tracking branch 'origin/develop' into chore.logging
Jun 13, 2024
00dd83b
chore: remove old references of logger
Jun 13, 2024
0f9558d
chore: refactor fire http stats
Jun 13, 2024
883f3cb
chore: add logic to trigger stats for destinations that don't send me…
Jun 13, 2024
1c4a1b0
chore: issues with func args fixed
Jun 13, 2024
c7cc39f
chore: debug-1
Jun 13, 2024
addae95
chore: debug-2
Jun 13, 2024
e1434c9
chore: debug-3
Jun 13, 2024
567c3b3
chore: fix levels problem
Jun 13, 2024
db31a6a
Merge remote-tracking branch 'origin/develop' into chore.logging
Jun 13, 2024
fd36803
Merge remote-tracking branch 'origin/develop' into chore.logging
Jun 14, 2024
a8b0c83
chore: add comment on LOGGER_IMPL
Jun 14, 2024
1e1f87e
chore: revert error log to info
Jun 14, 2024
fe87faa
chore: remove redundant condition on network.js
ItsSudip Jun 14, 2024
cbb9354
chore: update debug level condition
Jun 14, 2024
451fd11
chore: correction in shopify test
Jun 14, 2024
ed7837a
chore: usage of logger in postTransformation
Jun 14, 2024
0f9dc73
Merge remote-tracking branch 'origin/develop' into chore.logging
Jun 14, 2024
a978abf
chore: accept destType key from destinationType in metadata
Jun 14, 2024
710746f
chore: correction log message
Jun 14, 2024
6279c79
chore: add method doc for unexported log method in logger.js
Jun 14, 2024
4adb977
chore: handle non-object arguments for logger
Jun 18, 2024
2406a4b
chore: remove new routes log
Jun 18, 2024
d5b2282
Merge remote-tracking branch 'origin/develop' into chore.logging
Jun 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions benchmark/metaLogger.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,30 @@

const logger = require('../src/logger');

logger.setLogLevel(Number.POSITIVE_INFINITY);
logger.setLogLevel('random');

const debug = (...args) => {
logger.setLogLevel(logger.levelDebug);
logger.setLogLevel('debug');
logger.debug(...args);
logger.setLogLevel(Number.POSITIVE_INFINITY);
logger.setLogLevel('random');
};

const info = (...args) => {
logger.setLogLevel(logger.levelInfo);
logger.setLogLevel('info');
logger.info(...args);
logger.setLogLevel(Number.POSITIVE_INFINITY);
logger.setLogLevel('random');
};

const warn = (...args) => {
logger.setLogLevel(logger.levelWarn);
logger.setLogLevel('warn');
logger.warn(...args);
logger.setLogLevel(Number.POSITIVE_INFINITY);
logger.setLogLevel('random');
};

const error = (...args) => {
logger.setLogLevel(logger.levelError);
logger.setLogLevel('error');
logger.error(...args);
logger.setLogLevel(Number.POSITIVE_INFINITY);
logger.setLogLevel('random');
};

module.exports = {
Expand Down
51 changes: 47 additions & 4 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"@koa/router": "^12.0.0",
"@ndhoule/extend": "^2.0.0",
"@pyroscope/nodejs": "^0.2.9",
"@rudderstack/integrations-lib": "^0.2.8",
"@rudderstack/integrations-lib": "^0.2.10",
"@rudderstack/json-template-engine": "^0.13.2",
"@rudderstack/workflow-engine": "^0.8.2",
"@shopify/jest-koa-mocks": "^5.1.1",
Expand Down
102 changes: 76 additions & 26 deletions src/adapters/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,28 @@ const networkClientConfigs = {
httpsAgent: new https.Agent({ keepAlive: true }),
};

const fireHTTPStats = (clientResponse, startTime, statTags) => {
const destType = statTags.destType ? statTags.destType : '';
const feature = statTags.feature ? statTags.feature : '';
const endpointPath = statTags.endpointPath ? statTags.endpointPath : '';
const requestMethod = statTags.requestMethod ? statTags.requestMethod : '';
const module = statTags.module ? statTags.module : '';
const statusCode = clientResponse.success ? clientResponse.response.status : '';
const fireOutgoingReqStats = ({
destType,
feature,
endpointPath,
requestMethod,
module,
metadata = {},
startTime,
statusCode,
clientResponse,
}) => {
const logMetaInfo = log.getLogMetadata(metadata);
stats.timing('outgoing_request_latency', startTime, {
...logMetaInfo,
feature,
destType,
endpointPath,
requestMethod,
module,
});
stats.counter('outgoing_request_count', 1, {
...logMetaInfo,
feature,
destType,
endpointPath,
Expand All @@ -70,6 +77,36 @@ const fireHTTPStats = (clientResponse, startTime, statTags) => {
});
};

const fireHTTPStats = (clientResponse, startTime, statTags) => {
const destType = statTags.destType ? statTags.destType : '';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[optional] statTags.destType || ''

this is better for eyes right? do for all

const feature = statTags.feature ? statTags.feature : '';
const endpointPath = statTags.endpointPath ? statTags.endpointPath : '';
const requestMethod = statTags.requestMethod ? statTags.requestMethod : '';
const module = statTags.module ? statTags.module : '';
const statusCode = clientResponse.success ? clientResponse.response.status : '';
const defArgs = {
destType,
endpointPath,
feature,
module,
requestMethod,
statusCode,
startTime,
clientResponse,
};
if (statTags?.metadata) {
const metadata = !Array.isArray(statTags?.metadata) ? [statTags.metadata] : statTags.metadata;
metadata?.forEach((m) => {
fireOutgoingReqStats({
...defArgs,
metadata: m,
});
});
return;
}
fireOutgoingReqStats(defArgs);
};

const enhanceRequestOptions = (options) => {
const requestOptions = {
...networkClientConfigs,
Expand Down Expand Up @@ -322,25 +359,6 @@ const prepareProxyRequest = (request) => {
return removeUndefinedValues({ endpoint, data, params, headers, method, config });
};

/**
* depricating: handles proxying requests to destinations from server, expects requsts in "defaultRequestConfig"
* note: needed for test api
* @param {*} request
* @returns
*/
const proxyRequest = async (request, destType) => {
const { endpoint, data, method, params, headers } = prepareProxyRequest(request);
const requestOptions = {
url: endpoint,
data,
params,
headers,
method,
};
const response = await httpSend(requestOptions, { feature: 'proxy', destType });
return response;
};

/**
* handles http request and sends the response in a simple format that is followed in transformer
*
Expand Down Expand Up @@ -392,6 +410,38 @@ const handleHttpRequest = async (requestType = 'post', ...httpArgs) => {
return { httpResponse, processedResponse };
};

/**
* depricating: handles proxying requests to destinations from server, expects requsts in "defaultRequestConfig"
* note: needed for test api
* @param {*} request
* @returns
*/
const proxyRequest = async (request, destType) => {
const { metadata } = request;
const { endpoint, data, method, params, headers } = prepareProxyRequest(request);
const requestOptions = {
url: endpoint,
data,
params,
headers,
method,
};
log.requestLog(`[${destType.toUpperCase()}] delivering data`, {
metadata,
requestDetails: {
body: data,
url: endpoint,
method,
},
});
const response = await httpSend(requestOptions, {
feature: 'proxy',
destType,
metadata,
});
return response;
};

module.exports = {
httpSend,
httpGET,
Expand Down
6 changes: 4 additions & 2 deletions src/adapters/utils/networkUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,11 @@ const processAxiosResponse = (clientResponse) => {
}
// non 2xx status handling for axios response
if (response) {
const { data, status } = response;
const { data, status, headers } = response;
return {
response: data || '',
status: status || 500,
...(isDefinedAndNotNullAndNotEmpty(headers) ? { headers } : {}),
};
}
// (edge case) response and code is not present
Expand All @@ -157,10 +158,11 @@ const processAxiosResponse = (clientResponse) => {
};
}
// success(2xx) axios response
const { data, status } = clientResponse.response;
const { data, status, headers } = clientResponse.response;
return {
sanpj2292 marked this conversation as resolved.
Show resolved Hide resolved
response: data || '',
status: status || 500,
...(isDefinedAndNotNullAndNotEmpty(headers) ? { headers } : {}),
};
};

Expand Down
3 changes: 2 additions & 1 deletion src/cdk/v2/destinations/gladly/procWorkflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ steps:
headers: $.getHeaders(.destination)
}
const endpoint = $.getEndpoint(.destination) + "?" + $.getQueryParams($.context.payload);
const rawResponse = await $.httpGET(endpoint,requestOptions)
const reqStats = {metadata:.metadata, module: 'router',feature: "transformation", destType:"gladly",requestMethod:"get",endpointPath:"/api/v1/customer-profiles"}
const rawResponse = await $.httpGET(endpoint,requestOptions, reqStats)
const processedResponse = $.processAxiosResponse(rawResponse)
processedResponse

Expand Down
6 changes: 4 additions & 2 deletions src/cdk/v2/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import {
isCdkV2Destination,
} from './utils';

import logger from '../../logger';

const defTags = {
[tags.TAG_NAMES.IMPLEMENTATION]: tags.IMPLEMENTATIONS.CDK_V2,
};
Expand Down Expand Up @@ -82,12 +84,12 @@ export async function processCdkV2Workflow(
destType: string,
parsedEvent: FixMe,
feature: string,
logger: FixMe,
requestMetadata: NonNullable<unknown> = {},
bindings: Record<string, FixMe> = {},
) {
krishna2020 marked this conversation as resolved.
Show resolved Hide resolved
try {
logger.debug(`Processing cdkV2 workflow`);
logger.debug(`Processing cdkV2 workflow`, { destType });

const workflowEngine = await getCachedWorkflowEngine(destType, feature, bindings);
return await executeWorkflow(workflowEngine, parsedEvent, requestMetadata);
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/bulkUpload.ts
krishna2020 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/* eslint-disable global-require, import/no-dynamic-require, @typescript-eslint/no-unused-vars */
import { structuredLogger as logger } from '@rudderstack/integrations-lib';
import { client as errNotificationClient } from '../util/errorNotifier';
import {
getDestFileUploadHandler,
getJobStatusHandler,
getPollStatusHandler,
} from '../util/fetchDestinationHandlers';
import { CatchErr, ContextBodySimple } from '../util/types';
import logger from '../logger';
// TODO: To be refactored and redisgned

const ERROR_MESSAGE_PROCESSOR_STRING = 'Error occurred while processing payload.';
Expand Down
14 changes: 6 additions & 8 deletions src/controllers/delivery.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
/* eslint-disable prefer-destructuring */
/* eslint-disable sonarjs/no-duplicate-string */
import {
isDefinedAndNotNullAndNotEmpty,
structuredLogger as logger,
} from '@rudderstack/integrations-lib';
import { isDefinedAndNotNullAndNotEmpty } from '@rudderstack/integrations-lib';
import { Context } from 'koa';
import { ServiceSelector } from '../helpers/serviceSelector';
import { DeliveryTestService } from '../services/delivertTest/deliveryTest';
Expand All @@ -19,12 +16,13 @@
import { FixMe } from '../util/types';
import tags from '../v0/util/tags';
import { ControllerUtility } from './util';
import logger from '../logger';

const NON_DETERMINABLE = 'Non-determinable';

export class DeliveryController {
public static async deliverToDestination(ctx: Context) {
logger.debug('Native(Delivery):: Request to transformer::', ctx.request.body);
logger.debug('Native(Delivery):: Request to transformer for delivery::', ctx.request.body);
let deliveryResponse: DeliveryV0Response;
const requestMetadata = MiscService.getRequestMetadata(ctx);
const deliveryRequest = ctx.request.body as ProxyV0Request;
Expand Down Expand Up @@ -54,12 +52,12 @@
ctx.body = { output: deliveryResponse };
ControllerUtility.deliveryPostProcess(ctx, deliveryResponse.status);

logger.debug('Native(Delivery):: Response from transformer::', ctx.body);
logger.debug('Native(Delivery):: Response from transformer after delivery::', ctx.body);
return ctx;
}

public static async deliverToDestinationV1(ctx: Context) {
logger.debug('Native(Delivery):: Request to transformer::', ctx.request.body);
logger.debug('Native(Delivery):: Request to transformer for delivery::', ctx.request.body);
let deliveryResponse: DeliveryV1Response;
const requestMetadata = MiscService.getRequestMetadata(ctx);
const deliveryRequest = ctx.request.body as ProxyV1Request;
Expand Down Expand Up @@ -116,7 +114,7 @@
);
ctx.body = { output: response };
ControllerUtility.postProcess(ctx);
logger.debug('Native(Delivery-Test):: Response from transformer::', ctx.body);
logger.debug('Native(Delivery-Test):: Response from transformer after delivery::', ctx.body);

Check warning on line 117 in src/controllers/delivery.ts

View check run for this annotation

Codecov / codecov/patch

src/controllers/delivery.ts#L117

Added line #L117 was not covered by tests
return ctx;
}
}
Loading
Loading