-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
track serverless functions executions #7963
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR Summary
This pull request implements analytics tracking for serverless function executions, sending results to a Tinybird event data source.
- Added AnalyticsModule to ServerlessFunctionModule imports in
packages/twenty-server/src/engine/metadata-modules/serverless-function/serverless-function.module.ts
- Integrated AnalyticsService in
packages/twenty-server/src/engine/metadata-modules/serverless-function/serverless-function.service.ts
to create events after function execution - Implemented event payload structure including duration, status, error type, function ID, and name
- Requires ANALYTICS_ENABLED set to true and TINYBIRD_INGEST_TOKEN configured in .env file for testing
2 file(s) reviewed, 2 comment(s)
Edit PR Review Bot Settings | Greptile
this.analyticsService.create( | ||
eventInput, | ||
'serverless-function', | ||
workspaceId, | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Ensure that the 'serverless-function' string is defined as a constant to avoid typos
this.analyticsService.create( | |
eventInput, | |
'serverless-function', | |
workspaceId, | |
); | |
const ANALYTICS_SERVICE_NAME = 'serverless-function'; | |
this.analyticsService.create( | |
eventInput, | |
ANALYTICS_SERVICE_NAME, | |
workspaceId, | |
); |
...(resultServerlessFunction.error && { | ||
errorType: resultServerlessFunction.error.errorType, | ||
}), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Use optional chaining for error property access
...(resultServerlessFunction.error && { | |
errorType: resultServerlessFunction.error.errorType, | |
}), | |
...(resultServerlessFunction.error?.errorType ? { | |
errorType: resultServerlessFunction.error.errorType, | |
} : {}), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change name to serverlessFunction.executed as discussed :). Otherwise all good for me!
Solves:
https://github.com/twentyhq/private-issues/issues/74
TLDR
When a serverless function is executed, the result is send to tinybird event data source.
In order to test:
What is the structure of the payload of a serverless function event?
Here are two examples of the payload:
{"duration":37,"status":"SUCCESS","functionId":"a9fd87c0-af86-4e17-be3a-a6d3d961678a","functionName":"testingFunction"}
{"duration":34,"status":"ERROR","errorType":"ReferenceError","functionId":"a9fd87c0-af86-4e17-be3a-a6d3d961678a","functionName":"testingFunction"}
Possible improvments