From 7ab586c865319462d09242bce373637e0cc3feab Mon Sep 17 00:00:00 2001 From: Henry Heng Date: Fri, 17 Oct 2025 10:53:47 +0100 Subject: [PATCH] Chore/product id telemetry (#5329) * add telemetry for productId * updated multiple services (chatflows, buildChatflow, upsertVector) to use the new method for fetching product ID from subscriptions, improving consistency and error handling --- packages/server/src/StripeManager.ts | 7 +++++-- packages/server/src/services/chatflows/index.ts | 3 +-- packages/server/src/utils/buildChatflow.ts | 4 +--- packages/server/src/utils/upsertVector.ts | 4 +--- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/packages/server/src/StripeManager.ts b/packages/server/src/StripeManager.ts index 278370ea1..806349d97 100644 --- a/packages/server/src/StripeManager.ts +++ b/packages/server/src/StripeManager.ts @@ -38,6 +38,10 @@ export class StripeManager { } public async getProductIdFromSubscription(subscriptionId: string) { + if (!subscriptionId || subscriptionId.trim() === '') { + return '' + } + if (!this.stripe) { throw new Error('Stripe is not initialized') } @@ -62,8 +66,7 @@ export class StripeManager { return productId } catch (error) { - console.error('Error getting product ID from subscription:', error) - throw error + return '' } } diff --git a/packages/server/src/services/chatflows/index.ts b/packages/server/src/services/chatflows/index.ts index 4ff25b546..88e543356 100644 --- a/packages/server/src/services/chatflows/index.ts +++ b/packages/server/src/services/chatflows/index.ts @@ -293,8 +293,7 @@ const saveChatflow = async ( dbResponse = await appServer.AppDataSource.getRepository(ChatFlow).save(chatflow) } - const subscriptionDetails = await usageCacheManager.getSubscriptionDataFromCache(subscriptionId) - const productId = subscriptionDetails?.productId || '' + const productId = await appServer.identityManager.getProductIdFromSubscription(subscriptionId) await appServer.telemetry.sendTelemetry( 'chatflow_created', diff --git a/packages/server/src/utils/buildChatflow.ts b/packages/server/src/utils/buildChatflow.ts index 2a44e3206..7a57b67bb 100644 --- a/packages/server/src/utils/buildChatflow.ts +++ b/packages/server/src/utils/buildChatflow.ts @@ -1036,9 +1036,7 @@ export const utilBuildChatflow = async (req: Request, isInternal: boolean = fals const orgId = org.id organizationId = orgId const subscriptionId = org.subscriptionId as string - - const subscriptionDetails = await appServer.usageCacheManager.getSubscriptionDataFromCache(subscriptionId) - const productId = subscriptionDetails?.productId || '' + const productId = await appServer.identityManager.getProductIdFromSubscription(subscriptionId) await checkPredictions(orgId, subscriptionId, appServer.usageCacheManager) diff --git a/packages/server/src/utils/upsertVector.ts b/packages/server/src/utils/upsertVector.ts index 29ebcbe96..7e705cf5b 100644 --- a/packages/server/src/utils/upsertVector.ts +++ b/packages/server/src/utils/upsertVector.ts @@ -276,9 +276,7 @@ export const upsertVector = async (req: Request, isInternal: boolean = false) => const orgId = org.id const subscriptionId = org.subscriptionId as string - - const subscriptionDetails = await appServer.usageCacheManager.getSubscriptionDataFromCache(subscriptionId) - const productId = subscriptionDetails?.productId || '' + const productId = await appServer.identityManager.getProductIdFromSubscription(subscriptionId) const executeData: IExecuteFlowParams = { componentNodes: appServer.nodesPool.componentNodes,