diff --git a/packages/orchestrator/lib/clients/types.ts b/packages/orchestrator/lib/clients/types.ts index c228227be6..f2029780db 100644 --- a/packages/orchestrator/lib/clients/types.ts +++ b/packages/orchestrator/lib/clients/types.ts @@ -27,7 +27,7 @@ interface ActionArgs { environment_id: number; connection_id: string; }; - activityLogId: number; + activityLogId: string | number; input: JsonValue; } interface WebhookArgs { @@ -39,7 +39,7 @@ interface WebhookArgs { provider_config_key: string; environment_id: number; }; - activityLogId: number; + activityLogId: string | number; input: JsonValue; } @@ -52,7 +52,7 @@ interface PostConnectionArgs { environment_id: number; }; fileLocation: string; - activityLogId: number; + activityLogId: string | number; } export type SchedulesReturn = Result; export type VoidReturn = Result; diff --git a/packages/orchestrator/lib/clients/validate.ts b/packages/orchestrator/lib/clients/validate.ts index a41cbaa01b..be718d4384 100644 --- a/packages/orchestrator/lib/clients/validate.ts +++ b/packages/orchestrator/lib/clients/validate.ts @@ -27,7 +27,7 @@ export const syncArgsSchema = z.object({ export const actionArgsSchema = z.object({ type: z.literal('action'), actionName: z.string().min(1), - activityLogId: z.number().positive(), + activityLogId: z.union([z.number(), z.string()]), input: jsonSchema, ...commonSchemaArgsFields }); @@ -35,7 +35,7 @@ export const webhookArgsSchema = z.object({ type: z.literal('webhook'), webhookName: z.string().min(1), parentSyncName: z.string().min(1), - activityLogId: z.number().positive(), + activityLogId: z.union([z.number(), z.string()]), input: jsonSchema, ...commonSchemaArgsFields }); @@ -43,7 +43,7 @@ export const postConnectionArgsSchema = z.object({ type: z.literal('post-connection-script'), postConnectionName: z.string().min(1), fileLocation: z.string().min(1), - activityLogId: z.number().positive(), + activityLogId: z.union([z.number(), z.string()]), ...commonSchemaArgsFields }); diff --git a/packages/server/lib/controllers/account.controller.ts b/packages/server/lib/controllers/account.controller.ts index e83e709bb4..4912c57983 100644 --- a/packages/server/lib/controllers/account.controller.ts +++ b/packages/server/lib/controllers/account.controller.ts @@ -1,7 +1,6 @@ import type { Request, Response, NextFunction } from 'express'; -import type { LogLevel } from '@nangohq/shared'; import { isCloud } from '@nangohq/utils'; -import { accountService, userService, LogActionEnum, createActivityLogAndLogMessage } from '@nangohq/shared'; +import { accountService, userService } from '@nangohq/shared'; import type { LogContext } from '@nangohq/logs'; import { logContextGetter } from '@nangohq/logs'; import type { RequestLocals } from '../utils/express.js'; @@ -134,27 +133,8 @@ class AccountController { return; } - const log = { - level: 'info' as LogLevel, - success: true, - action: LogActionEnum.ACCOUNT, - start: Date.now(), - end: Date.now(), - timestamp: Date.now(), - connection_id: 'n/a', - provider: null, - provider_config_key: '', - environment_id: environment.id - }; - - const activityLogId = await createActivityLogAndLogMessage(log, { - level: 'info', - environment_id: environment.id, - timestamp: Date.now(), - content: `A Nango admin logged into another account for the following reason: "${login_reason}"` - }); logCtx = await logContextGetter.create( - { id: String(activityLogId), operation: { type: 'admin', action: 'impersonation' }, message: 'Admin logged into another account' }, + { operation: { type: 'admin', action: 'impersonation' }, message: 'Admin logged into another account' }, { account, environment, diff --git a/packages/server/lib/controllers/apiAuth.controller.ts b/packages/server/lib/controllers/apiAuth.controller.ts index 1091fe337a..3d52a5ebc8 100644 --- a/packages/server/lib/controllers/apiAuth.controller.ts +++ b/packages/server/lib/controllers/apiAuth.controller.ts @@ -1,17 +1,12 @@ import type { Request, Response, NextFunction } from 'express'; import tracer from 'dd-trace'; -import type { LogLevel, ApiKeyCredentials, BasicApiCredentials } from '@nangohq/shared'; +import type { ApiKeyCredentials, BasicApiCredentials } from '@nangohq/shared'; import { - createActivityLog, errorManager, analytics, AnalyticsTypes, - createActivityLogMessage, - updateSuccess as updateSuccessActivityLog, - updateProvider as updateProviderActivityLog, configService, connectionService, - createActivityLogMessageAndEnd, getConnectionConfig, hmacService, ErrorSourceEnum, @@ -34,25 +29,10 @@ class ApiAuthController { const connectionId = req.query['connection_id'] as string | undefined; const connectionConfig = req.query['params'] != null ? getConnectionConfig(req.query['params']) : {}; - const log = { - level: 'info' as LogLevel, - success: false, - action: LogActionEnum.AUTH, - start: Date.now(), - end: Date.now(), - timestamp: Date.now(), - connection_id: connectionId as string, - provider_config_key: providerConfigKey as string, - environment_id: environment.id - }; - - const activityLogId = await createActivityLog(log); - let logCtx: LogContext | undefined; try { logCtx = await logContextGetter.create( { - id: String(activityLogId), operation: { type: 'auth', action: 'create_connection' }, message: 'Create connection via API Key', expiresAt: defaultOperationExpiration.auth() @@ -77,13 +57,6 @@ class ApiAuthController { if (hmacEnabled) { const hmac = req.query['hmac'] as string | undefined; if (!hmac) { - await createActivityLogMessageAndEnd({ - level: 'error', - environment_id: environment.id, - activity_log_id: activityLogId as number, - timestamp: Date.now(), - content: 'Missing HMAC in query params' - }); await logCtx.error('Missing HMAC in query params'); await logCtx.failed(); @@ -93,13 +66,6 @@ class ApiAuthController { } const verified = await hmacService.verify(hmac, environment.id, providerConfigKey, connectionId); if (!verified) { - await createActivityLogMessageAndEnd({ - level: 'error', - environment_id: environment.id, - activity_log_id: activityLogId as number, - timestamp: Date.now(), - content: 'Invalid HMAC' - }); await logCtx.error('Invalid HMAC'); await logCtx.failed(); @@ -112,13 +78,6 @@ class ApiAuthController { const config = await configService.getProviderConfig(providerConfigKey, environment.id); if (config == null) { - await createActivityLogMessageAndEnd({ - level: 'error', - environment_id: environment.id, - activity_log_id: activityLogId as number, - content: `Error during API Key auth: config not found`, - timestamp: Date.now() - }); await logCtx.error('Unknown provider config'); await logCtx.failed(); @@ -130,13 +89,6 @@ class ApiAuthController { const template = configService.getTemplate(config.provider); if (template.auth_mode !== 'API_KEY') { - await createActivityLogMessageAndEnd({ - level: 'error', - environment_id: environment.id, - activity_log_id: activityLogId as number, - timestamp: Date.now(), - content: `Provider ${config.provider} does not support API key auth` - }); await logCtx.error('Provider does not support API key auth', { provider: config.provider }); await logCtx.failed(); @@ -145,7 +97,6 @@ class ApiAuthController { return; } - await updateProviderActivityLog(activityLogId as number, String(config.provider)); await logCtx.enrichOperation({ integrationId: config.id!, integrationName: config.unique_key, providerName: config.provider }); if (!req.body.apiKey) { @@ -173,13 +124,6 @@ class ApiAuthController { ); if (connectionResponse.isErr()) { - await createActivityLogMessageAndEnd({ - level: 'error', - environment_id: environment.id, - activity_log_id: activityLogId as number, - content: `The credentials provided were not valid for the ${config.provider} provider`, - timestamp: Date.now() - }); await logCtx.error('Provided credentials are invalid', { provider: config.provider }); await logCtx.failed(); @@ -188,18 +132,9 @@ class ApiAuthController { return; } - await createActivityLogMessage({ - level: 'info', - environment_id: environment.id, - activity_log_id: activityLogId as number, - content: `API key auth creation was successful`, - timestamp: Date.now() - }); await logCtx.info('API key auth creation was successful'); await logCtx.success(); - await updateSuccessActivityLog(activityLogId as number, true); - const [updatedConnection] = await connectionService.upsertApiConnection( connectionId, providerConfigKey, @@ -222,7 +157,6 @@ class ApiAuthController { }, config.provider, logContextGetter, - activityLogId, undefined, logCtx ); @@ -232,13 +166,6 @@ class ApiAuthController { } catch (err) { const prettyError = stringifyError(err, { pretty: true }); - await createActivityLogMessage({ - level: 'error', - environment_id: environment.id, - activity_log_id: activityLogId as number, - content: `Error during API key auth: ${prettyError}`, - timestamp: Date.now() - }); if (logCtx) { connectionCreationFailedHook( { @@ -253,7 +180,6 @@ class ApiAuthController { operation: 'unknown' }, 'unknown', - activityLogId, logCtx ); await logCtx.error('Error during API key auth', { error: err }); @@ -280,25 +206,11 @@ class ApiAuthController { const connectionId = req.query['connection_id'] as string | undefined; const connectionConfig = req.query['params'] != null ? getConnectionConfig(req.query['params']) : {}; - const log = { - level: 'info' as LogLevel, - success: false, - action: LogActionEnum.AUTH, - start: Date.now(), - end: Date.now(), - timestamp: Date.now(), - connection_id: connectionId as string, - provider_config_key: providerConfigKey as string, - environment_id: environment.id - }; - - const activityLogId = await createActivityLog(log); let logCtx: LogContext | undefined; try { logCtx = await logContextGetter.create( { - id: String(activityLogId), operation: { type: 'auth', action: 'create_connection' }, message: 'Create connection via Basic Auth', expiresAt: defaultOperationExpiration.auth() @@ -323,13 +235,6 @@ class ApiAuthController { if (hmacEnabled) { const hmac = req.query['hmac'] as string | undefined; if (!hmac) { - await createActivityLogMessageAndEnd({ - level: 'error', - environment_id: environment.id, - activity_log_id: activityLogId as number, - timestamp: Date.now(), - content: 'Missing HMAC in query params' - }); await logCtx.error('Missing HMAC in query params'); await logCtx.failed(); @@ -339,13 +244,6 @@ class ApiAuthController { } const verified = await hmacService.verify(hmac, environment.id, providerConfigKey, connectionId); if (!verified) { - await createActivityLogMessageAndEnd({ - level: 'error', - environment_id: environment.id, - activity_log_id: activityLogId as number, - timestamp: Date.now(), - content: 'Invalid HMAC' - }); await logCtx.error('Invalid HMAC'); await logCtx.failed(); @@ -359,13 +257,6 @@ class ApiAuthController { const config = await configService.getProviderConfig(providerConfigKey, environment.id); if (config == null) { - await createActivityLogMessageAndEnd({ - level: 'error', - environment_id: environment.id, - activity_log_id: activityLogId as number, - content: `Error during basic API auth: config not found`, - timestamp: Date.now() - }); await logCtx.error('Unknown provider config'); await logCtx.failed(); @@ -379,13 +270,6 @@ class ApiAuthController { const template = configService.getTemplate(config.provider); if (template.auth_mode !== 'BASIC') { - await createActivityLogMessageAndEnd({ - level: 'error', - environment_id: environment.id, - activity_log_id: activityLogId as number, - timestamp: Date.now(), - content: `Provider ${config.provider} does not support Basic API auth` - }); await logCtx.error('Provider does not support Basic API auth', { provider: config.provider }); await logCtx.failed(); @@ -412,13 +296,6 @@ class ApiAuthController { ); if (connectionResponse.isErr()) { - await createActivityLogMessageAndEnd({ - level: 'error', - environment_id: environment.id, - activity_log_id: activityLogId as number, - content: `The credentials provided were not valid for the ${config.provider} provider`, - timestamp: Date.now() - }); await logCtx.error('Provided credentials are invalid', { provider: config.provider }); await logCtx.failed(); @@ -427,17 +304,6 @@ class ApiAuthController { return; } - await updateProviderActivityLog(activityLogId as number, String(config.provider)); - - await createActivityLogMessage({ - level: 'info', - environment_id: environment.id, - activity_log_id: activityLogId as number, - content: `Basic API key auth creation was successful with the username ${username}`, - timestamp: Date.now() - }); - - await updateSuccessActivityLog(activityLogId as number, true); await logCtx.info('Basic API key auth creation was successful', { username }); await logCtx.success(); @@ -463,7 +329,6 @@ class ApiAuthController { }, config.provider, logContextGetter, - activityLogId, undefined, logCtx ); @@ -473,13 +338,6 @@ class ApiAuthController { } catch (err) { const prettyError = stringifyError(err, { pretty: true }); - await createActivityLogMessage({ - level: 'error', - environment_id: environment.id, - activity_log_id: activityLogId as number, - content: `Error during basic API auth: ${prettyError}`, - timestamp: Date.now() - }); if (logCtx) { connectionCreationFailedHook( { @@ -494,7 +352,6 @@ class ApiAuthController { operation: 'unknown' }, 'unknown', - activityLogId, logCtx ); await logCtx.error('Error during API key auth', { error: err }); diff --git a/packages/server/lib/controllers/appAuth.controller.ts b/packages/server/lib/controllers/appAuth.controller.ts index 62e81c28ba..eacd6dd366 100644 --- a/packages/server/lib/controllers/appAuth.controller.ts +++ b/packages/server/lib/controllers/appAuth.controller.ts @@ -213,7 +213,6 @@ class AppAuthController { operation: 'unknown' }, session.provider, - activityLogId, logCtx ); @@ -244,7 +243,6 @@ class AppAuthController { }, session.provider, logContextGetter, - activityLogId, undefined, logCtx ); @@ -306,7 +304,6 @@ class AppAuthController { operation: 'unknown' }, 'unknown', - activityLogId, logCtx ); diff --git a/packages/server/lib/controllers/appStoreAuth.controller.ts b/packages/server/lib/controllers/appStoreAuth.controller.ts index 4303236685..2f0e948f9f 100644 --- a/packages/server/lib/controllers/appStoreAuth.controller.ts +++ b/packages/server/lib/controllers/appStoreAuth.controller.ts @@ -183,7 +183,6 @@ class AppStoreAuthController { operation: 'unknown' }, config.provider, - activityLogId, logCtx ); @@ -225,7 +224,6 @@ class AppStoreAuthController { }, config.provider, logContextGetter, - activityLogId, undefined, logCtx ); @@ -255,7 +253,6 @@ class AppStoreAuthController { operation: 'unknown' }, 'unknown', - activityLogId, logCtx ); if (logCtx) { diff --git a/packages/server/lib/controllers/connection.controller.ts b/packages/server/lib/controllers/connection.controller.ts index 56534e712d..826a271695 100644 --- a/packages/server/lib/controllers/connection.controller.ts +++ b/packages/server/lib/controllers/connection.controller.ts @@ -404,8 +404,7 @@ class ConnectionController { operation: res.operation }, provider, - logContextGetter, - null + logContextGetter ); }; @@ -452,8 +451,7 @@ class ConnectionController { operation: res.operation }, provider, - logContextGetter, - null + logContextGetter ); }; @@ -494,8 +492,7 @@ class ConnectionController { operation: res.operation }, provider, - logContextGetter, - null + logContextGetter ); }; const [imported] = await connectionService.importApiAuthConnection( @@ -534,8 +531,7 @@ class ConnectionController { operation: res.operation }, provider, - logContextGetter, - null + logContextGetter ); }; @@ -620,8 +616,7 @@ class ConnectionController { operation: updatedConnection.operation || 'unknown' }, provider, - logContextGetter, - null + logContextGetter ); } diff --git a/packages/server/lib/controllers/oauth.controller.ts b/packages/server/lib/controllers/oauth.controller.ts index c0153b479d..58749ac5c1 100644 --- a/packages/server/lib/controllers/oauth.controller.ts +++ b/packages/server/lib/controllers/oauth.controller.ts @@ -558,7 +558,6 @@ class OAuthController { }, config.provider, logContextGetter, - activityLogId, undefined, logCtx ); @@ -588,7 +587,6 @@ class OAuthController { operation: 'unknown' }, 'unknown', - activityLogId, logCtx ); if (logCtx) { @@ -1220,7 +1218,6 @@ class OAuthController { operation: 'unknown' }, session.provider, - activityLogId, logCtx ); @@ -1386,7 +1383,6 @@ class OAuthController { operation: 'unknown' }, session.provider, - activityLogId, logCtx ); @@ -1510,7 +1506,6 @@ class OAuthController { }, session.provider, logContextGetter, - activityLogId, { initiateSync, runPostConnectionScript }, logCtx ); @@ -1529,7 +1524,6 @@ class OAuthController { }, config.provider, logContextGetter, - activityLogId, { initiateSync: true, runPostConnectionScript: false }, logCtx ); @@ -1603,7 +1597,6 @@ class OAuthController { operation: 'unknown' }, session.provider, - activityLogId, logCtx ); @@ -1653,7 +1646,6 @@ class OAuthController { operation: 'unknown' }, session.provider, - activityLogId, logCtx ); @@ -1717,7 +1709,6 @@ class OAuthController { }, session.provider, logContextGetter, - activityLogId, { initiateSync, runPostConnectionScript }, logCtx ); @@ -1772,7 +1763,6 @@ class OAuthController { operation: 'unknown' }, session.provider, - activityLogId, logCtx ); diff --git a/packages/server/lib/controllers/onboarding.controller.ts b/packages/server/lib/controllers/onboarding.controller.ts index ae46e59ad6..b306449d5a 100644 --- a/packages/server/lib/controllers/onboarding.controller.ts +++ b/packages/server/lib/controllers/onboarding.controller.ts @@ -453,7 +453,6 @@ class OnboardingController { connection, actionName: DEMO_ACTION_NAME, input: { title: req.body.title }, - activityLogId, environment_id: environment.id, logCtx }); diff --git a/packages/server/lib/controllers/sync.controller.ts b/packages/server/lib/controllers/sync.controller.ts index b8012559c5..3604312f34 100644 --- a/packages/server/lib/controllers/sync.controller.ts +++ b/packages/server/lib/controllers/sync.controller.ts @@ -473,7 +473,6 @@ class SyncController { connection, actionName: action_name, input, - activityLogId, environment_id: environmentId, logCtx }); diff --git a/packages/server/lib/controllers/unauth.controller.ts b/packages/server/lib/controllers/unauth.controller.ts index 2363ebcd7d..d5814f574b 100644 --- a/packages/server/lib/controllers/unauth.controller.ts +++ b/packages/server/lib/controllers/unauth.controller.ts @@ -168,7 +168,6 @@ class UnAuthController { }, config.provider, logContextGetter, - activityLogId, undefined, logCtx ); @@ -199,7 +198,6 @@ class UnAuthController { operation: 'unknown' }, 'unknown', - activityLogId, logCtx ); if (logCtx) { diff --git a/packages/server/lib/hooks/hooks.ts b/packages/server/lib/hooks/hooks.ts index 4a725cdc59..897e0e1c86 100644 --- a/packages/server/lib/hooks/hooks.ts +++ b/packages/server/lib/hooks/hooks.ts @@ -73,7 +73,6 @@ export const connectionCreated = async ( createdConnectionPayload: RecentlyCreatedConnection, provider: string, logContextGetter: LogContextGetter, - activityLogId: number | null, options: { initiateSync?: boolean; runPostConnectionScript?: boolean } = { initiateSync: true, runPostConnectionScript: true }, logCtx?: LogContext ): Promise => { @@ -99,17 +98,11 @@ export const connectionCreated = async ( operation: 'creation', provider, type: 'auth', - activityLogId, logCtx }); }; -export const connectionCreationFailed = async ( - failedConnectionPayload: RecentlyFailedConnection, - provider: string, - activityLogId: number | null, - logCtx?: LogContext -): Promise => { +export const connectionCreationFailed = async (failedConnectionPayload: RecentlyFailedConnection, provider: string, logCtx?: LogContext): Promise => { const { connection, environment, auth_mode, error } = failedConnectionPayload; if (error) { @@ -125,7 +118,6 @@ export const connectionCreationFailed = async ( operation: 'creation', provider, type: 'auth', - activityLogId, logCtx }); } @@ -155,7 +147,6 @@ export const connectionRefreshSuccess = async ({ export const connectionRefreshFailed = async ({ connection, - activityLogId, logCtx, authError, environment, @@ -167,14 +158,13 @@ export const connectionRefreshFailed = async ({ template: ProviderTemplate; config: IntegrationConfig; authError: { type: string; description: string }; - activityLogId: number; logCtx: LogContext; }): Promise => { await errorNotificationService.auth.create({ type: 'auth', action: 'token_refresh', connection_id: connection.id!, - activity_log_id: activityLogId, + activity_log_id: -1, log_id: logCtx.id, active: true }); @@ -191,13 +181,12 @@ export const connectionRefreshFailed = async ({ success: false, provider: config.provider, type: 'auth', - activityLogId, logCtx }); const slackNotificationService = new SlackService({ orchestratorClient: getOrchestratorClient(), logContextGetter }); - void slackNotificationService.reportFailure(connection, connection.connection_id, 'auth', activityLogId, environment.id, config.provider); + void slackNotificationService.reportFailure(connection, connection.connection_id, 'auth', logCtx.id, environment.id, config.provider); }; export const connectionTest = async ( diff --git a/packages/server/lib/webhook/github-app-oauth-webhook-routing.ts b/packages/server/lib/webhook/github-app-oauth-webhook-routing.ts index f06cbdc59f..2c80d39210 100644 --- a/packages/server/lib/webhook/github-app-oauth-webhook-routing.ts +++ b/packages/server/lib/webhook/github-app-oauth-webhook-routing.ts @@ -98,7 +98,6 @@ async function handleCreateWebhook(integration: ProviderConfig, body: any, logCo }, integration.provider, logContextGetter, - activityLogId, { initiateSync: true, runPostConnectionScript: false }, logCtx ); diff --git a/packages/shared/lib/clients/orchestrator.ts b/packages/shared/lib/clients/orchestrator.ts index b1a2e05434..c15cf41566 100644 --- a/packages/shared/lib/clients/orchestrator.ts +++ b/packages/shared/lib/clients/orchestrator.ts @@ -111,30 +111,18 @@ export class Orchestrator { connection, actionName, input, - activityLogId, environment_id, logCtx }: { connection: NangoConnection; actionName: string; input: object; - activityLogId: number; environment_id: number; logCtx: LogContext; }): Promise> { const startTime = Date.now(); const workflowId = `${SYNC_TASK_QUEUE}.ACTION:${actionName}.${connection.connection_id}.${uuid()}`; try { - await createActivityLogMessage({ - level: 'info', - environment_id, - activity_log_id: activityLogId, - content: `Starting action workflow ${workflowId} in the task queue: ${SYNC_TASK_QUEUE}`, - params: { - input: JSON.stringify(input, null, 2) - }, - timestamp: Date.now() - }); await logCtx.info(`Starting action workflow ${workflowId} in the task queue: ${SYNC_TASK_QUEUE}`, { input }); let res: Result; @@ -166,7 +154,7 @@ export class Orchestrator { provider_config_key: connection.provider_config_key, environment_id: connection.environment_id }, - activityLogId, + activityLogId: logCtx.id, input: parsedInput }; const actionResult = await this.client.executeAction({ @@ -207,7 +195,7 @@ export class Orchestrator { environment_id: connection.environment_id }, input, - activityLogId + activityLogId: logCtx.id } ] }); @@ -238,14 +226,6 @@ export class Orchestrator { const content = `The action workflow ${workflowId} was successfully run. A truncated response is: ${JSON.stringify(res.value, null, 2)?.slice(0, 100)}`; - await createActivityLogMessageAndEnd({ - level: 'info', - environment_id, - activity_log_id: activityLogId, - timestamp: Date.now(), - content - }); - await updateSuccessActivityLog(activityLogId, true); await logCtx.info(content); await telemetry.log( @@ -268,13 +248,6 @@ export class Orchestrator { const content = `The action workflow ${workflowId} failed with error: ${err}`; - await createActivityLogMessageAndEnd({ - level: 'error', - environment_id, - activity_log_id: activityLogId, - timestamp: Date.now(), - content - }); await logCtx.error(content); errorManager.report(err, { diff --git a/packages/shared/lib/services/notification/slack.service.ts b/packages/shared/lib/services/notification/slack.service.ts index 5b29b41a97..0f3a5309ff 100644 --- a/packages/shared/lib/services/notification/slack.service.ts +++ b/packages/shared/lib/services/notification/slack.service.ts @@ -125,7 +125,6 @@ export class SlackService { */ private async sendDuplicateNotificationToNangoAdmins( payload: NotificationPayload, - activityLogId: number, environment_id: number, logCtx: LogContext, // TODO: we should not reuse this ctx id?: number, @@ -152,7 +151,6 @@ export class SlackService { connection: nangoAdminConnection, actionName: this.actionName, input: payload, - activityLogId, environment_id: nangoAdminConnection?.environment_id, logCtx }); @@ -202,7 +200,7 @@ export class SlackService { * 3) Send a duplicate notification to the Nango Admins * 4) Add an activity log entry for the notification to the admin account */ - async reportFailure(nangoConnection: NangoConnection, name: string, type: string, originalActivityLogId: number, environment_id: number, provider: string) { + async reportFailure(nangoConnection: NangoConnection, name: string, type: string, originalActivityLogId: string, environment_id: number, provider: string) { const slackNotificationsEnabled = await environmentService.getSlackNotificationsEnabled(nangoConnection.environment_id); if (!slackNotificationsEnabled) { @@ -262,13 +260,6 @@ export class SlackService { ); if (!success || !slackNotificationStatus) { - await createActivityLogMessage({ - level: 'error', - environment_id, - activity_log_id: activityLogId as number, - content: `Failed looking up the slack notification using the slack notification service. The error was: ${error}`, - timestamp: Date.now() - }); await logCtx.error('Failed looking up the slack notification using the slack notification service', { error }); await logCtx.failed(); @@ -295,7 +286,6 @@ export class SlackService { connection: slackConnection as NangoConnection, actionName: this.actionName, input: payload, - activityLogId: activityLogId as number, environment_id, logCtx }); @@ -306,7 +296,6 @@ export class SlackService { await this.sendDuplicateNotificationToNangoAdmins( payload, - originalActivityLogId, environment_id, logCtx, slackNotificationStatus.id, @@ -361,7 +350,7 @@ export class SlackService { nangoConnection: NangoConnection, syncName: string, type: string, - originalActivityLogId: number | null, + originalActivityLogId: string | null, environment_id: number, provider: string, slack_timestamp: string, @@ -429,23 +418,8 @@ export class SlackService { return; } - const log = { - level: 'info' as LogLevel, - success: false, - action: LogActionEnum.ACTION, - start: Date.now(), - end: Date.now(), - timestamp: Date.now(), - connection_id: slackConnection?.connection_id, - provider_config_key: slackConnection?.provider_config_key, - provider: this.integrationKey, - environment_id: slackConnection?.environment_id, - operation_name: this.actionName - }; - - const activityLogId = await createActivityLog(log); const logCtx = await this.logContextGetter.create( - { id: String(activityLogId), operation: { type: 'action' }, message: 'Start action' }, + { operation: { type: 'action' }, message: 'Start action' }, { account, environment: { id: environment_id, name: envName }, @@ -459,27 +433,16 @@ export class SlackService { connection: slackConnection as NangoConnection, actionName: this.actionName, input: payload, - activityLogId: activityLogId as number, environment_id, logCtx }); - await this.sendDuplicateNotificationToNangoAdmins(payload, activityLogId as number, environment_id, logCtx, undefined, admin_slack_timestamp); + await this.sendDuplicateNotificationToNangoAdmins(payload, environment_id, logCtx, undefined, admin_slack_timestamp); const content = actionResponse.isOk() ? `The action ${this.actionName} was successfully triggered for the ${type} ${syncName} for environment ${slackConnection?.environment_id} for account ${account.uuid}.` : `The action ${this.actionName} failed to trigger for the ${type} ${syncName} with the error: ${actionResponse.error.message} for environment ${slackConnection?.environment_id} for account ${account.uuid}.`; - await createActivityLogMessage({ - level: actionResponse.isOk() ? 'info' : 'error', - activity_log_id: activityLogId as number, - environment_id: slackConnection?.environment_id, - timestamp: Date.now(), - content, - params: payload as unknown as Record - }); - - await updateSuccessActivityLog(activityLogId as number, actionResponse.isOk()); if (actionResponse.isOk()) { await logCtx.info(content, payload); await logCtx.success(); @@ -616,7 +579,7 @@ export class SlackService { nangoConnection: NangoConnection, name: string, type: string, - originalActivityLogId: number | null, + originalActivityLogId: string | null, environment_id: number, provider: string ): Promise { @@ -689,7 +652,7 @@ export class SlackService { type }: { envName: string; - originalActivityLogId: number | null; + originalActivityLogId: string | null; name: string; date: Date; type: string; @@ -733,7 +696,7 @@ export class SlackService { flowType: string; name: string; envName: string; - originalActivityLogId: number | null; + originalActivityLogId: string | null; date: Date; resolved: boolean; }): string { diff --git a/packages/shared/lib/services/sync/run.service.ts b/packages/shared/lib/services/sync/run.service.ts index 08eefbac32..f862af72b1 100644 --- a/packages/shared/lib/services/sync/run.service.ts +++ b/packages/shared/lib/services/sync/run.service.ts @@ -84,7 +84,13 @@ export type SyncRunConfig = { temporalContext?: Context; } & ( - | { writeToDb: true; activityLogId: number; logCtx: LogContext; slackService: SlackService; sendSyncWebhook: (params: SendSyncParams) => Promise } + | { + writeToDb: true; + activityLogId: string | number; + logCtx: LogContext; + slackService: SlackService; + sendSyncWebhook: (params: SendSyncParams) => Promise; + } | { writeToDb: false } ); @@ -120,7 +126,7 @@ export default class SyncRun { syncId?: string; syncJobId?: number; - activityLogId?: number; + activityLogId?: string | number; provider?: string; loadLocation?: string; fileLocation?: string; @@ -480,7 +486,7 @@ export default class SyncRun { syncId: (this.syncId as string) || `${this.syncName}-${this.nangoConnection.environment_id}-${this.nangoConnection.provider_config_key}-${this.nangoConnection.connection_id}`, - activityLogId: this.activityLogId, + activityLogId: this.activityLogId as unknown as number, nangoProps, integrationData: syncData, environmentId: this.nangoConnection.environment_id, @@ -550,7 +556,7 @@ export default class SyncRun { this.nangoConnection, this.syncName, this.syncType, - this.activityLogId as number, + this.activityLogId as unknown as string, this.nangoConnection.environment_id, this.provider as string ); @@ -677,7 +683,7 @@ export default class SyncRun { if (index === numberOfModels - 1) { await updateSyncJobStatus(this.syncJobId, SyncStatus.SUCCESS); - await updateSuccessActivityLog(this.activityLogId, true); + await updateSuccessActivityLog(this.activityLogId as unknown as number, true); // set the last sync date to when the sync started in case // the sync is long running to make sure we wouldn't miss @@ -688,7 +694,7 @@ export default class SyncRun { this.nangoConnection, this.syncName, this.determineExecutionType(), - this.activityLogId, + this.activityLogId as unknown as string, this.nangoConnection.environment_id, this.provider as string ); @@ -778,7 +784,6 @@ export default class SyncRun { success: true, responseResults: results, operation: this.syncType === 'INITIAL' ? 'INITIAL' : 'INCREMENTAL', - activityLogId: this.activityLogId, logCtx: this.logCtx }); } @@ -787,7 +792,7 @@ export default class SyncRun { await createActivityLogMessageAndEnd({ level: 'info', environment_id: this.nangoConnection.environment_id, - activity_log_id: this.activityLogId, + activity_log_id: this.activityLogId as unknown as number, timestamp: Date.now(), content }); @@ -796,7 +801,7 @@ export default class SyncRun { await createActivityLogMessage({ level: 'info', environment_id: this.nangoConnection.environment_id, - activity_log_id: this.activityLogId, + activity_log_id: this.activityLogId as unknown as number, timestamp: Date.now(), content }); @@ -872,7 +877,7 @@ export default class SyncRun { this.nangoConnection, this.syncName, this.determineExecutionType(), - this.activityLogId as number, + this.activityLogId as unknown as string, this.nangoConnection.environment_id, this.provider as string ); @@ -911,18 +916,17 @@ export default class SyncRun { error, now: syncStartDate, operation: this.syncType === 'INITIAL' ? 'INITIAL' : 'INCREMENTAL', - activityLogId: this.activityLogId, logCtx: this.logCtx }); } - await updateSuccessActivityLog(this.activityLogId, false); + await updateSuccessActivityLog(this.activityLogId as unknown as number, false); await updateSyncJobStatus(this.syncJobId, SyncStatus.STOPPED); await createActivityLogMessageAndEnd({ level: 'error', environment_id: this.nangoConnection.environment_id, - activity_log_id: this.activityLogId, + activity_log_id: this.activityLogId as unknown as number, timestamp: Date.now(), content }); @@ -972,7 +976,7 @@ export default class SyncRun { type: 'sync', sync_id: this.syncId, connection_id: this.nangoConnection.id, - activity_log_id: this.activityLogId, + activity_log_id: this.activityLogId as unknown as number, log_id: this.logCtx?.id, active: true }); diff --git a/packages/webhooks/lib/auth.ts b/packages/webhooks/lib/auth.ts index 2b193464a5..cb7f283477 100644 --- a/packages/webhooks/lib/auth.ts +++ b/packages/webhooks/lib/auth.ts @@ -23,7 +23,6 @@ export const sendAuth = async ({ operation, provider, type, - activityLogId, logCtx }: { connection: Connection | Pick; @@ -35,7 +34,6 @@ export const sendAuth = async ({ operation: AuthOperationType; provider: string; type: WebhookTypes; - activityLogId: number | null; logCtx?: LogContext | undefined; } & ({ success: true } | { success: false; error: ErrorPayload })): Promise => { if (!webhookSettings) { @@ -82,7 +80,6 @@ export const sendAuth = async ({ webhooks, body: success ? successBody : errorBody, webhookType: type, - activityLogId, environment, logCtx }); diff --git a/packages/webhooks/lib/auth.unit.test.ts b/packages/webhooks/lib/auth.unit.test.ts index 2facb33d43..6389520568 100644 --- a/packages/webhooks/lib/auth.unit.test.ts +++ b/packages/webhooks/lib/auth.unit.test.ts @@ -51,7 +51,6 @@ describe('Webhooks: auth notification tests', () => { type: 'auth', auth_mode: 'OAUTH2', operation: 'creation', - activityLogId: 1, logCtx }); expect(spy).not.toHaveBeenCalled(); @@ -77,7 +76,6 @@ describe('Webhooks: auth notification tests', () => { type: 'auth', auth_mode: 'OAUTH2', operation: 'creation', - activityLogId: 1, logCtx }); expect(spy).toHaveBeenCalledTimes(1); @@ -104,7 +102,6 @@ describe('Webhooks: auth notification tests', () => { type: 'auth', auth_mode: 'OAUTH2', operation: 'creation', - activityLogId: 1, logCtx }); expect(spy).toHaveBeenCalledTimes(1); @@ -129,7 +126,6 @@ describe('Webhooks: auth notification tests', () => { type: 'auth', auth_mode: 'OAUTH2', operation: 'creation', - activityLogId: 1, logCtx }); expect(spy).toHaveBeenCalledTimes(2); @@ -159,7 +155,6 @@ describe('Webhooks: auth notification tests', () => { type: 'auth', auth_mode: 'OAUTH2', operation: 'creation', - activityLogId: 1, logCtx }); expect(spy).toHaveBeenCalledTimes(1); @@ -180,7 +175,6 @@ describe('Webhooks: auth notification tests', () => { on_auth_creation: false }, provider: 'hubspot', - activityLogId: 1, type: 'auth', auth_mode: 'OAUTH2', operation: 'creation', @@ -207,7 +201,6 @@ describe('Webhooks: auth notification tests', () => { on_auth_refresh_error: true }, provider: 'hubspot', - activityLogId: 1, type: 'auth', auth_mode: 'OAUTH2', operation: 'refresh', @@ -233,7 +226,6 @@ describe('Webhooks: auth notification tests', () => { on_auth_refresh_error: true }, provider: 'hubspot', - activityLogId: 1, type: 'auth', auth_mode: 'OAUTH2', operation: 'refresh', @@ -258,7 +250,6 @@ describe('Webhooks: auth notification tests', () => { on_auth_refresh_error: false }, provider: 'hubspot', - activityLogId: 1, type: 'auth', auth_mode: 'OAUTH2', operation: 'refresh', @@ -284,7 +275,6 @@ describe('Webhooks: auth notification tests', () => { on_auth_refresh_error: true }, provider: 'hubspot', - activityLogId: 1, type: 'auth', auth_mode: 'OAUTH2', operation: 'refresh', diff --git a/packages/webhooks/lib/forward.ts b/packages/webhooks/lib/forward.ts index 0ae902ca60..4fcf351f22 100644 --- a/packages/webhooks/lib/forward.ts +++ b/packages/webhooks/lib/forward.ts @@ -59,7 +59,6 @@ export const forwardWebhook = async ({ webhooks, body: payload, webhookType: 'forward', - activityLogId: null, environment, logCtx }); @@ -78,7 +77,6 @@ export const forwardWebhook = async ({ connectionId }, webhookType: 'forward', - activityLogId: null, environment, logCtx, incomingHeaders: webhookOriginalHeaders diff --git a/packages/webhooks/lib/forward.unit.test.ts b/packages/webhooks/lib/forward.unit.test.ts index 30ca239827..9b67cb4a54 100644 --- a/packages/webhooks/lib/forward.unit.test.ts +++ b/packages/webhooks/lib/forward.unit.test.ts @@ -50,7 +50,6 @@ describe('Webhooks: forward notification tests', () => { type: 'auth', auth_mode: 'OAUTH2', operation: 'creation', - activityLogId: 1, logCtx }); expect(spy).not.toHaveBeenCalled(); @@ -75,7 +74,6 @@ describe('Webhooks: forward notification tests', () => { type: 'auth', auth_mode: 'OAUTH2', operation: 'creation', - activityLogId: 1, logCtx }); expect(spy).toHaveBeenCalledTimes(1); @@ -101,7 +99,6 @@ describe('Webhooks: forward notification tests', () => { type: 'auth', auth_mode: 'OAUTH2', operation: 'creation', - activityLogId: 1, logCtx }); expect(spy).toHaveBeenCalledTimes(1); @@ -123,7 +120,6 @@ describe('Webhooks: forward notification tests', () => { type: 'auth', auth_mode: 'OAUTH2', operation: 'creation', - activityLogId: 1, logCtx }); expect(spy).toHaveBeenCalledTimes(2); diff --git a/packages/webhooks/lib/sync.ts b/packages/webhooks/lib/sync.ts index f4584b5852..a44f596f17 100644 --- a/packages/webhooks/lib/sync.ts +++ b/packages/webhooks/lib/sync.ts @@ -27,7 +27,6 @@ export const sendSync = async ({ success, operation, error, - activityLogId, logCtx }: { connection: Connection | Pick; @@ -40,7 +39,6 @@ export const sendSync = async ({ error?: ErrorPayload; responseResults?: SyncResult; success: boolean; - activityLogId: number | null; logCtx?: LogContext | undefined; } & ({ success: true; responseResults: SyncResult } | { success: false; error: ErrorPayload })): Promise => { if (!webhookSettings) { @@ -110,7 +108,6 @@ export const sendSync = async ({ webhooks, body: success ? successBody : errorBody, webhookType: 'sync', - activityLogId, endingMessage: success ? endingMessage : '', environment, logCtx diff --git a/packages/webhooks/lib/sync.unit.test.ts b/packages/webhooks/lib/sync.unit.test.ts index 850b1a5851..95be8f4ac1 100644 --- a/packages/webhooks/lib/sync.unit.test.ts +++ b/packages/webhooks/lib/sync.unit.test.ts @@ -49,7 +49,6 @@ describe('Webhooks: sync notification tests', () => { success: true, operation: 'INCREMENTAL', now: new Date(), - activityLogId: 1, logCtx }); expect(spy).not.toHaveBeenCalled(); @@ -67,7 +66,6 @@ describe('Webhooks: sync notification tests', () => { success: true, operation: 'INCREMENTAL', now: new Date(), - activityLogId: 1, logCtx, webhookSettings: { ...webhookSettings, @@ -92,7 +90,6 @@ describe('Webhooks: sync notification tests', () => { operation: 'INCREMENTAL', success: true, now: new Date(), - activityLogId: 1, logCtx, webhookSettings: { ...webhookSettings, @@ -116,7 +113,6 @@ describe('Webhooks: sync notification tests', () => { operation: 'INCREMENTAL', success: true, now: new Date(), - activityLogId: 1, logCtx, webhookSettings: { ...webhookSettings, @@ -140,7 +136,6 @@ describe('Webhooks: sync notification tests', () => { operation: 'INCREMENTAL', success: true, now: new Date(), - activityLogId: 1, logCtx, webhookSettings: { ...webhookSettings, @@ -163,7 +158,6 @@ describe('Webhooks: sync notification tests', () => { responseResults, operation: 'INCREMENTAL', now: new Date(), - activityLogId: 1, logCtx, success: true, webhookSettings: { @@ -188,7 +182,6 @@ describe('Webhooks: sync notification tests', () => { operation: 'INCREMENTAL', now: new Date(), success: true, - activityLogId: 1, logCtx, webhookSettings: { ...webhookSettings, @@ -217,7 +210,6 @@ describe('Webhooks: sync notification tests', () => { operation: 'INCREMENTAL', now, success: true, - activityLogId: 1, logCtx, webhookSettings: webhookSettings, environment: { @@ -281,7 +273,6 @@ describe('Webhooks: sync notification tests', () => { error, operation: 'INCREMENTAL', now: new Date(), - activityLogId: 1, logCtx, webhookSettings: { ...webhookSettings, @@ -309,7 +300,6 @@ describe('Webhooks: sync notification tests', () => { error, operation: 'INCREMENTAL', now: new Date(), - activityLogId: 1, logCtx, webhookSettings: { ...webhookSettings, diff --git a/packages/webhooks/lib/utils.ts b/packages/webhooks/lib/utils.ts index 69d6bfd8e6..9ed4d59b90 100644 --- a/packages/webhooks/lib/utils.ts +++ b/packages/webhooks/lib/utils.ts @@ -25,20 +25,13 @@ export const NON_FORWARDABLE_HEADERS = [ 'server' ]; -export const retry = async ( - activityLogId: number | null, - logCtx?: LogContext | null | undefined, - error?: AxiosError, - attemptNumber?: number -): Promise => { +export const retry = async (logCtx?: LogContext | null | undefined, error?: AxiosError, attemptNumber?: number): Promise => { if (error?.response && (error?.response?.status < 200 || error?.response?.status >= 300)) { const content = `Webhook response received an ${ error?.response?.status || error?.code } error, retrying with exponential backoffs for ${attemptNumber} out of ${RETRY_ATTEMPTS} times`; - if (activityLogId) { - await logCtx?.error(content); - } + await logCtx?.error(content); return true; } @@ -115,7 +108,6 @@ export const deliver = async ({ webhooks, body, webhookType, - activityLogId, logCtx, environment, endingMessage = '', @@ -124,7 +116,6 @@ export const deliver = async ({ webhooks: { url: string; type: string }[]; body: unknown; webhookType: WebhookTypes; - activityLogId: number | null; environment: Environment; logCtx?: LogContext | undefined; endingMessage?: string; @@ -145,7 +136,7 @@ export const deliver = async ({ () => { return axios.post(url, body, { headers }); }, - { numOfAttempts: RETRY_ATTEMPTS, retry: retry.bind(this, activityLogId, logCtx) } + { numOfAttempts: RETRY_ATTEMPTS, retry: retry.bind(this, logCtx) } ); if (logCtx) { @@ -163,11 +154,7 @@ export const deliver = async ({ } } } catch (err) { - if (activityLogId) { - await logCtx?.error(`${webhookType} webhook failed to send to the ${type} to ${url}`, { - error: err - }); - } + await logCtx?.error(`${webhookType} webhook failed to send to the ${type} to ${url}`, { error: err }); success = false; }