Skip to content

Commit

Permalink
fix(logs.v1): remove auth, slack, activities, etc. (#2400)
Browse files Browse the repository at this point in the history
## Describe your changes

Contributes to
https://linear.app/nango/issue/NAN-585/stop-writing-from-v1

- Remove from oauth, activities, slack
It's bigger than usual because at this point it's more or less all
linked together. And I saw some error regarding inserting activity_log
with a string so that means I have missed a place already and don't want
to keep this longer.
NB: There will still be at least 2 more PRs
  • Loading branch information
bodinsamuel committed Jun 25, 2024
1 parent 9701cff commit 0c80bfd
Show file tree
Hide file tree
Showing 21 changed files with 44 additions and 1,253 deletions.
59 changes: 4 additions & 55 deletions packages/jobs/lib/activities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import {
LogActionEnum,
SyncRunService,
environmentService,
createActivityLogMessage,
createActivityLogAndLogMessage,
ErrorSourceEnum,
errorManager,
telemetry,
Expand Down Expand Up @@ -201,31 +199,11 @@ export async function scheduleAndRouteSync(args: ContinuousSyncArgs): Promise<bo
});
} catch (err) {
const prettyError = stringifyError(err, { pretty: true });
const log = {
level: 'info' as LogLevel,
success: false,
action: LogActionEnum.SYNC,
start: Date.now(),
end: Date.now(),
timestamp: Date.now(),
connection_id: nangoConnection?.connection_id,
provider_config_key: nangoConnection?.provider_config_key,
provider: '',
session_id: '',
environment_id: environmentId,
operation_name: syncName
};
const content = `The continuous sync failed to run because of a failure to obtain the provider config for ${syncName} with the following error: ${prettyError}`;
const activityLogId = await createActivityLogAndLogMessage(log, {
level: 'error',
environment_id: environmentId,
timestamp: Date.now(),
content
});

const { account, environment } = (await environmentService.getAccountAndEnvironment({ environmentId: nangoConnection.environment_id }))!;
const logCtx = await logContextGetter.create(
{ id: String(activityLogId), operation: { type: 'sync', action: 'run' }, message: 'Sync' },
{ operation: { type: 'sync', action: 'run' }, message: 'Sync' },
{
account,
environment,
Expand Down Expand Up @@ -322,13 +300,6 @@ export async function syncProvider({
);

if (debug) {
await createActivityLogMessage({
level: 'info',
environment_id: nangoConnection?.environment_id,
activity_log_id: activityLogId,
timestamp: Date.now(),
content: `Starting sync ${syncType} for ${syncName} with syncId ${syncId} and syncJobId ${syncJobId} with execution id of ${temporalContext.info.workflowExecution.workflowId} for attempt #${temporalContext.info.attempt}`
});
await logCtx.info('Starting sync', {
syncType,
syncName,
Expand Down Expand Up @@ -363,28 +334,8 @@ export async function syncProvider({
return result.response;
} catch (err) {
const prettyError = stringifyError(err, { pretty: true });
const log = {
level: 'info' as LogLevel,
success: false,
action,
start: Date.now(),
end: Date.now(),
timestamp: Date.now(),
connection_id: nangoConnection?.connection_id,
provider_config_key: nangoConnection?.provider_config_key,
provider: providerConfig.provider,
session_id: syncJobId ? syncJobId?.toString() : '',
environment_id: nangoConnection?.environment_id,
operation_name: syncName
};
const content = `The ${syncType} sync failed to run because of a failure to create the job and run the sync with the error: ${prettyError}`;

await createActivityLogAndLogMessage(log, {
level: 'error',
environment_id: nangoConnection?.environment_id,
timestamp: Date.now(),
content
});
const content = `The ${syncType} sync failed to run because of a failure to create the job and run the sync with the error: ${prettyError}`;
if (logCtx) {
await logCtx.error('Failed to create the job', { error: err });
await logCtx.failed();
Expand Down Expand Up @@ -570,17 +521,15 @@ export async function reportFailure(

export async function cancelActivity(workflowArguments: InitialSyncArgs | ContinuousSyncArgs): Promise<void> {
try {
const { syncId, nangoConnection } = workflowArguments;

const environmentId = nangoConnection?.environment_id;
const { syncId } = workflowArguments;

if ('syncJobId' in workflowArguments) {
await updateSyncJobStatus(workflowArguments.syncJobId, SyncStatus.STOPPED);
} else {
await updateLatestJobSyncStatus(workflowArguments.syncId, SyncStatus.STOPPED);
}

await integrationService.cancelScript(syncId, environmentId);
await integrationService.cancelScript(syncId);
} catch (e) {
const content = `The sync "${workflowArguments.syncName}" with sync id ${workflowArguments.syncId} failed to cancel with the following error: ${e instanceof Error ? e.message : stringifyError(e)}`;
errorManager.report(content, {
Expand Down
13 changes: 1 addition & 12 deletions packages/jobs/lib/crons/autoIdleDemo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import {
ErrorSourceEnum,
SyncCommand,
createActivityLog,
createActivityLogMessageAndEnd,
errorManager,
updateSuccess as updateSuccessActivityLog,
updateScheduleStatus,
findPausableDemoSyncs,
SpanTypes,
Expand Down Expand Up @@ -94,21 +92,12 @@ export async function exec(): Promise<void> {
continue;
}

const resDb = await updateScheduleStatus(sync.schedule_id, SyncCommand.PAUSE, activityLogId, sync.environment_id, logCtx);
const resDb = await updateScheduleStatus(sync.schedule_id, SyncCommand.PAUSE, logCtx);
if (resDb.isErr()) {
await logCtx.failed();
continue;
}

await createActivityLogMessageAndEnd({
level: 'info',
environment_id: sync.environment_id,
activity_log_id: activityLogId,
timestamp: Date.now(),
content: `Demo sync was automatically paused after being idle for a day`
});
await updateSuccessActivityLog(activityLogId, true);

await logCtx.info('Demo sync was automatically paused after being idle for a day');
await logCtx.success();
}
Expand Down
40 changes: 6 additions & 34 deletions packages/jobs/lib/integration.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Context } from '@temporalio/activity';
import type { IntegrationServiceInterface, RunScriptOptions, ServiceResponse } from '@nangohq/shared';
import { integrationFilesAreRemote, isCloud, isProd, getLogger, stringifyError } from '@nangohq/utils';
import { createActivityLogMessage, localFileService, remoteFileService, NangoError, formatScriptError } from '@nangohq/shared';
import { localFileService, remoteFileService, NangoError, formatScriptError } from '@nangohq/shared';
import type { Runner } from './runner/runner.js';
import { getOrStartRunner, getRunnerId } from './runner/runner.js';
import tracer from 'dd-trace';
Expand All @@ -24,7 +24,7 @@ class IntegrationService implements IntegrationServiceInterface {
this.sendHeartbeat();
}

async cancelScript(syncId: string, environmentId: number): Promise<void> {
async cancelScript(syncId: string): Promise<void> {
const scriptObject = this.runningScripts.get(syncId);

if (!scriptObject) {
Expand All @@ -40,14 +40,7 @@ class IntegrationService implements IntegrationServiceInterface {
if (res.isOk()) {
this.runningScripts.set(syncId, { ...scriptObject, cancelled: true });
} else {
if (activityLogId && environmentId) {
await createActivityLogMessage({
level: 'error',
environment_id: environmentId,
activity_log_id: activityLogId,
content: `Failed to cancel script`,
timestamp: Date.now()
});
if (activityLogId) {
const logCtx = logContextGetter.getStateLess({ id: String(activityLogId) });
await logCtx.error('Failed to cancel script');
}
Expand Down Expand Up @@ -87,14 +80,7 @@ class IntegrationService implements IntegrationServiceInterface {
if (!script) {
const content = `Unable to find integration file for ${syncName}`;

if (activityLogId && writeToDb) {
await createActivityLogMessage({
level: 'error',
environment_id: environmentId,
activity_log_id: activityLogId,
content,
timestamp: Date.now()
});
if (writeToDb) {
await logCtx?.error(content);
}

Expand Down Expand Up @@ -172,14 +158,7 @@ class IntegrationService implements IntegrationServiceInterface {
}
const { success, error, response } = formatScriptError(err, errorType, syncName);

if (activityLogId && writeToDb) {
await createActivityLogMessage({
level: 'error',
environment_id: environmentId,
activity_log_id: activityLogId,
content: error.message,
timestamp: Date.now()
});
if (writeToDb) {
await logCtx?.error(error.message, { error });
}
return { success, error, response };
Expand All @@ -191,14 +170,7 @@ class IntegrationService implements IntegrationServiceInterface {
const errorMessage = stringifyError(err, { pretty: true });
const content = `There was an error running integration '${syncName}': ${errorMessage}`;

if (activityLogId && writeToDb) {
await createActivityLogMessage({
level: 'error',
environment_id: environmentId,
activity_log_id: activityLogId,
content,
timestamp: Date.now()
});
if (writeToDb) {
await logCtx?.error(content, { error: err });
}

Expand Down
31 changes: 1 addition & 30 deletions packages/jobs/lib/processor/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import type { LogLevel } from '@nangohq/shared';
import {
configService,
createActivityLog,
createActivityLogAndLogMessage,
createActivityLogMessage,
createSyncJob,
environmentService,
errorManager,
Expand Down Expand Up @@ -52,7 +50,7 @@ export async function handler(task: OrchestratorTask): Promise<Result<JsonValue>
async function abort(task: OrchestratorTask): Promise<Result<void>> {
try {
if (task.isSync()) {
await integrationService.cancelScript(task.syncId, task.connection.environment_id);
await integrationService.cancelScript(task.syncId);
return Ok(undefined);
}
return Err(`Failed to cancel. Task type not supported`);
Expand Down Expand Up @@ -128,13 +126,6 @@ async function sync(task: TaskSync): Promise<Result<JsonValue>> {
);

if (task.debug) {
await createActivityLogMessage({
level: 'info',
environment_id: task.connection.environment_id,
activity_log_id: activityLogId,
timestamp: Date.now(),
content: `Starting sync ${syncType} for ${task.syncName} with syncId ${task.syncId} and syncJobId ${syncJob.id} with execution id ${task.id} and attempt ${task.attempt}`
});
await logCtx.info('Starting sync', {
syncType: syncType,
syncName: task.syncName,
Expand Down Expand Up @@ -175,28 +166,8 @@ async function sync(task: TaskSync): Promise<Result<JsonValue>> {
return Ok(res.data);
} catch (err) {
const prettyError = stringifyError(err, { pretty: true });
const log = {
level: 'info' as LogLevel,
success: false,
action: lastSyncDate ? LogActionEnum.FULL_SYNC : LogActionEnum.SYNC,
start: Date.now(),
end: Date.now(),
timestamp: Date.now(),
connection_id: task.connection.connection_id,
provider_config_key: task.connection.provider_config_key,
provider: providerConfig.provider,
session_id: syncJob.id.toString(),
environment_id: task.connection.environment_id,
operation_name: task.syncName
};
const content = `The ${syncType} sync failed to run: ${prettyError}`;

await createActivityLogAndLogMessage(log, {
level: 'error',
environment_id: task.connection.environment_id,
timestamp: Date.now(),
content
});
if (logCtx) {
await logCtx.error(content, { error: err });
await logCtx.failed();
Expand Down
Loading

0 comments on commit 0c80bfd

Please sign in to comment.