The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
track serverless functions executions (#7963)
Ana Sofia Marin Alexandre29bd4e5f2d89
diff --git a/packages/twenty-server/src/engine/metadata-modules/serverless-function/serverless-function.module.ts b/packages/twenty-server/src/engine/metadata-modules/serverless-function/serverless-function.module.tsindex df5ef68aaa6..d289f9c0866 100644--- a/packages/twenty-server/src/engine/metadata-modules/serverless-function/serverless-function.module.ts+++ b/packages/twenty-server/src/engine/metadata-modules/serverless-function/serverless-function.module.ts@@ -3,6 +3,7 @@ import { TypeOrmModule } from '@nestjs/typeorm';import { NestjsQueryTypeOrmModule } from '@ptc-org/nestjs-query-typeorm';+import { AnalyticsModule } from 'src/engine/core-modules/analytics/analytics.module';import { FeatureFlagEntity } from 'src/engine/core-modules/feature-flag/feature-flag.entity';import { FileUploadModule } from 'src/engine/core-modules/file/file-upload/file-upload.module';import { FileModule } from 'src/engine/core-modules/file/file.module';@@ -18,6 +19,7 @@ import { ServerlessFunctionService } from 'src/engine/metadata-modules/serverlesTypeOrmModule.forFeature([FeatureFlagEntity], 'core'),FileModule,ThrottlerModule,+ AnalyticsModule,],providers: [ServerlessFunctionService, ServerlessFunctionResolver],exports: [ServerlessFunctionService],diff --git a/packages/twenty-server/src/engine/metadata-modules/serverless-function/serverless-function.service.ts b/packages/twenty-server/src/engine/metadata-modules/serverless-function/serverless-function.service.tsindex 2e69781ac06..aa5ef6279cd 100644--- a/packages/twenty-server/src/engine/metadata-modules/serverless-function/serverless-function.service.ts+++ b/packages/twenty-server/src/engine/metadata-modules/serverless-function/serverless-function.service.ts@@ -9,6 +9,7 @@ import { Repository } from 'typeorm';import { FileStorageExceptionCode } from 'src/engine/core-modules/file-storage/interfaces/file-storage-exception';import { ServerlessExecuteResult } from 'src/engine/core-modules/serverless/drivers/interfaces/serverless-driver.interface';+import { AnalyticsService } from 'src/engine/core-modules/analytics/analytics.service';import { EnvironmentService } from 'src/engine/core-modules/environment/environment.service';import { FileStorageService } from 'src/engine/core-modules/file-storage/file-storage.service';import { readFileContent } from 'src/engine/core-modules/file-storage/utils/read-file-content';@@ -41,6 +42,7 @@ export class ServerlessFunctionService {private readonly serverlessFunctionRepository: Repository<ServerlessFunctionEntity>,private readonly throttlerService: ThrottlerService,private readonly environmentService: EnvironmentService,+ private readonly analyticsService: AnalyticsService,) {}async findManyServerlessFunctions(where) {@@ -115,7 +117,31 @@ export class ServerlessFunctionService {);}- return this.serverlessService.execute(functionToExecute, payload, version);+ const resultServerlessFunction = await this.serverlessService.execute(+ functionToExecute,+ payload,+ version,+ );+ const eventInput = {+ action: 'serverlessFunction.executed',+ payload: {+ duration: resultServerlessFunction.duration,+ status: resultServerlessFunction.status,+ ...(resultServerlessFunction.error && {+ errorType: resultServerlessFunction.error.errorType,+ }),+ functionId: functionToExecute.id,+ functionName: functionToExecute.name,+ },+ };++ this.analyticsService.create(+ eventInput,+ 'serverless-function',+ workspaceId,+ );++ return resultServerlessFunction;}async publishOneServerlessFunction(id: string, workspaceId: string) {