Skip to content

Commit 32bf030

Browse files
authored
Chore/Add telemetry for productId (#5188)
add telemetry for productId
1 parent 099cf48 commit 32bf030

File tree

7 files changed

+49
-24
lines changed

7 files changed

+49
-24
lines changed

packages/server/src/Interface.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,7 @@ export interface IExecuteFlowParams extends IPredictionQueueAppServer {
395395
orgId: string
396396
workspaceId: string
397397
subscriptionId: string
398+
productId: string
398399
baseURL: string
399400
isInternal: boolean
400401
isEvaluation?: boolean

packages/server/src/enterprise/services/user.service.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,18 @@ export class UserService {
9797
data.updatedBy = data.id
9898
}
9999

100-
return queryRunner.manager.create(User, data)
100+
const userObj = queryRunner.manager.create(User, data)
101+
102+
this.telemetry.sendTelemetry(
103+
TelemetryEventType.USER_CREATED,
104+
{
105+
userId: userObj.id,
106+
createdBy: userObj.createdBy
107+
},
108+
userObj.id
109+
)
110+
111+
return userObj
101112
}
102113

103114
public async saveUser(data: Partial<User>, queryRunner: QueryRunner) {
@@ -120,15 +131,6 @@ export class UserService {
120131
await queryRunner.release()
121132
}
122133

123-
this.telemetry.sendTelemetry(
124-
TelemetryEventType.USER_CREATED,
125-
{
126-
userId: newUser.id,
127-
createdBy: newUser.createdBy
128-
},
129-
newUser.id
130-
)
131-
132134
return newUser
133135
}
134136

packages/server/src/services/chatflows/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,12 +292,18 @@ const saveChatflow = async (
292292
const chatflow = appServer.AppDataSource.getRepository(ChatFlow).create(newChatFlow)
293293
dbResponse = await appServer.AppDataSource.getRepository(ChatFlow).save(chatflow)
294294
}
295+
296+
const subscriptionDetails = await usageCacheManager.getSubscriptionDataFromCache(subscriptionId)
297+
const productId = subscriptionDetails?.productId || ''
298+
295299
await appServer.telemetry.sendTelemetry(
296300
'chatflow_created',
297301
{
298302
version: await getAppVersion(),
299303
chatflowId: dbResponse.id,
300-
flowGraph: getTelemetryFlowObj(JSON.parse(dbResponse.flowData)?.nodes, JSON.parse(dbResponse.flowData)?.edges)
304+
flowGraph: getTelemetryFlowObj(JSON.parse(dbResponse.flowData)?.nodes, JSON.parse(dbResponse.flowData)?.edges),
305+
productId,
306+
subscriptionId
301307
},
302308
orgId
303309
)

packages/server/src/utils/buildAgentflow.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ interface IExecuteNodeParams {
133133
orgId: string
134134
workspaceId: string
135135
subscriptionId: string
136+
productId: string
136137
}
137138

138139
interface IExecuteAgentFlowParams extends Omit<IExecuteFlowParams, 'incomingInput'> {
@@ -838,7 +839,8 @@ const executeNode = async ({
838839
iterationContext,
839840
orgId,
840841
workspaceId,
841-
subscriptionId
842+
subscriptionId,
843+
productId
842844
}: IExecuteNodeParams): Promise<{
843845
result: any
844846
shouldStop?: boolean
@@ -1060,7 +1062,8 @@ const executeNode = async ({
10601062
},
10611063
orgId,
10621064
workspaceId,
1063-
subscriptionId
1065+
subscriptionId,
1066+
productId
10641067
})
10651068

10661069
// Store the result
@@ -1287,7 +1290,8 @@ export const executeAgentFlow = async ({
12871290
isTool = false,
12881291
orgId,
12891292
workspaceId,
1290-
subscriptionId
1293+
subscriptionId,
1294+
productId
12911295
}: IExecuteAgentFlowParams) => {
12921296
logger.debug('\n🚀 Starting flow execution')
12931297

@@ -1754,7 +1758,8 @@ export const executeAgentFlow = async ({
17541758
iterationContext,
17551759
orgId,
17561760
workspaceId,
1757-
subscriptionId
1761+
subscriptionId,
1762+
productId
17581763
})
17591764

17601765
if (executionResult.agentFlowExecutedData) {
@@ -2020,7 +2025,9 @@ export const executeAgentFlow = async ({
20202025
chatflowId: chatflowid,
20212026
chatId,
20222027
type: evaluationRunId ? ChatType.EVALUATION : isInternal ? ChatType.INTERNAL : ChatType.EXTERNAL,
2023-
flowGraph: getTelemetryFlowObj(nodes, edges)
2028+
flowGraph: getTelemetryFlowObj(nodes, edges),
2029+
productId,
2030+
subscriptionId
20242031
},
20252032
orgId
20262033
)

packages/server/src/utils/buildChatflow.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,8 @@ export const executeFlow = async ({
249249
isTool,
250250
orgId,
251251
workspaceId,
252-
subscriptionId
252+
subscriptionId,
253+
productId
253254
}: IExecuteFlowParams) => {
254255
// Ensure incomingInput has all required properties with default values
255256
incomingInput = {
@@ -421,7 +422,8 @@ export const executeFlow = async ({
421422
isTool,
422423
orgId,
423424
workspaceId,
424-
subscriptionId
425+
subscriptionId,
426+
productId
425427
})
426428
}
427429

@@ -812,7 +814,9 @@ export const executeFlow = async ({
812814
chatflowId: chatflowid,
813815
chatId,
814816
type: isEvaluation ? ChatType.EVALUATION : isInternal ? ChatType.INTERNAL : ChatType.EXTERNAL,
815-
flowGraph: getTelemetryFlowObj(nodes, edges)
817+
flowGraph: getTelemetryFlowObj(nodes, edges),
818+
productId,
819+
subscriptionId
816820
},
817821
orgId
818822
)
@@ -954,6 +958,9 @@ export const utilBuildChatflow = async (req: Request, isInternal: boolean = fals
954958
organizationId = orgId
955959
const subscriptionId = org.subscriptionId as string
956960

961+
const subscriptionDetails = await appServer.usageCacheManager.getSubscriptionDataFromCache(subscriptionId)
962+
const productId = subscriptionDetails?.productId || ''
963+
957964
await checkPredictions(orgId, subscriptionId, appServer.usageCacheManager)
958965

959966
const executeData: IExecuteFlowParams = {
@@ -974,7 +981,8 @@ export const utilBuildChatflow = async (req: Request, isInternal: boolean = fals
974981
usageCacheManager: appServer.usageCacheManager,
975982
orgId,
976983
workspaceId,
977-
subscriptionId
984+
subscriptionId,
985+
productId
978986
}
979987

980988
if (process.env.MODE === MODE.QUEUE) {

packages/server/src/utils/upsertVector.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,9 @@ export const upsertVector = async (req: Request, isInternal: boolean = false) =>
277277
const orgId = org.id
278278
const subscriptionId = org.subscriptionId as string
279279

280+
const subscriptionDetails = await appServer.usageCacheManager.getSubscriptionDataFromCache(subscriptionId)
281+
const productId = subscriptionDetails?.productId || ''
282+
280283
const executeData: IExecuteFlowParams = {
281284
componentNodes: appServer.nodesPool.componentNodes,
282285
incomingInput,
@@ -293,7 +296,8 @@ export const upsertVector = async (req: Request, isInternal: boolean = false) =>
293296
isUpsert: true,
294297
orgId,
295298
workspaceId,
296-
subscriptionId
299+
subscriptionId,
300+
productId
297301
}
298302

299303
if (process.env.MODE === MODE.QUEUE) {

packages/ui/src/ui-component/dialog/ViewMessagesDialog.jsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,6 @@ const ViewMessagesDialog = ({ show, dialogProps, onCancel }) => {
185185
const closeSnackbar = (...args) => dispatch(closeSnackbarAction(...args))
186186

187187
const [chatlogs, setChatLogs] = useState([])
188-
const [allChatlogs, setAllChatLogs] = useState([])
189188
const [chatMessages, setChatMessages] = useState([])
190189
const [stats, setStats] = useState({})
191190
const [selectedMessageIndex, setSelectedMessageIndex] = useState(0)
@@ -758,7 +757,6 @@ const ViewMessagesDialog = ({ show, dialogProps, onCancel }) => {
758757
if (getChatmessageApi.data) {
759758
getStoragePathFromServer.request()
760759

761-
setAllChatLogs(getChatmessageApi.data)
762760
const chatPK = processChatLogs(getChatmessageApi.data)
763761
setSelectedMessageIndex(0)
764762
if (chatPK) {
@@ -794,7 +792,6 @@ const ViewMessagesDialog = ({ show, dialogProps, onCancel }) => {
794792

795793
return () => {
796794
setChatLogs([])
797-
setAllChatLogs([])
798795
setChatMessages([])
799796
setChatTypeFilter(['INTERNAL', 'EXTERNAL'])
800797
setFeedbackTypeFilter([])

0 commit comments

Comments
 (0)