From 553ea7d3e70b7bccabda43d1cdee2e1dda22f4cf Mon Sep 17 00:00:00 2001 From: Chuck Driesler Date: Tue, 11 Feb 2025 16:06:14 +0000 Subject: [PATCH] chore(automate): mixpanel metrics by function id and type (#3960) * chore(automate): mixpanel metrics for function id and type * chore(automate): catch test env --- packages/server/modules/automate/index.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/server/modules/automate/index.ts b/packages/server/modules/automate/index.ts index 5fa95234f..00e95e55a 100644 --- a/packages/server/modules/automate/index.ts +++ b/packages/server/modules/automate/index.ts @@ -16,7 +16,10 @@ import { } from '@/modules/automate/repositories/automations' import { isNonNullable, Scopes, throwUncoveredError } from '@speckle/shared' import { registerOrUpdateScopeFactory } from '@/modules/shared/repositories/scopes' -import { triggerAutomationRun } from '@/modules/automate/clients/executionEngine' +import { + getFunction, + triggerAutomationRun +} from '@/modules/automate/clients/executionEngine' import logStreamRest from '@/modules/automate/rest/logStream' import { getEncryptionKeyPairFor, @@ -25,7 +28,7 @@ import { import { buildDecryptor } from '@/modules/shared/utils/libsodium' import { getUserEmailFromAutomationRunFactory } from '@/modules/automate/services/tracking' import authGithubAppRest from '@/modules/automate/rest/authGithubApp' -import { getFeatureFlags } from '@/modules/shared/helpers/envHelper' +import { getFeatureFlags, isTestEnv } from '@/modules/shared/helpers/envHelper' import { TokenScopeData } from '@/modules/shared/domain/rolesAndScopes/types' import { db } from '@/db/knex' import { ProjectSubscriptions, publish } from '@/modules/shared/utils/subscriptions' @@ -285,6 +288,10 @@ const initializeEventListeners = () => { return } + const fn = isTestEnv() + ? null + : await getFunction({ functionId: functionRun.functionId }) + const userEmail = await getUserEmailFromAutomationRunFactory({ getFullAutomationRevisionMetadata: getFullAutomationRevisionMetadataFactory({ db: projectDb @@ -300,6 +307,9 @@ const initializeEventListeners = () => { automationRevisionId: automationWithRevision.id, automationName: automationWithRevision.name, runId: run.id, + functionId: fn?.functionId, + functionName: fn?.functionName, + functionType: fn?.isFeatured ? 'public' : 'private', functionRunId: functionRun.id, status: functionRun.status, durationInSeconds: functionRun.elapsed / 1000,