-
Notifications
You must be signed in to change notification settings - Fork 1.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
feat(temporal): Added posthog client to temporal to enable exceptions capture #26583
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from typing import Any, Optional | ||
from posthoganalytics.client import Client | ||
from temporalio.worker import ( | ||
ActivityInboundInterceptor, | ||
ExecuteActivityInput, | ||
ExecuteWorkflowInput, | ||
Interceptor, | ||
WorkflowInboundInterceptor, | ||
WorkflowInterceptorClassInput, | ||
) | ||
|
||
|
||
class _PostHogClientActivityInboundInterceptor(ActivityInboundInterceptor): | ||
async def execute_activity(self, input: ExecuteActivityInput) -> Any: | ||
ph_client = Client(api_key="sTMFPsFhdP1Ssg", enable_exception_autocapture=True) | ||
|
||
activity_result = await super().execute_activity(input) | ||
|
||
ph_client.flush() | ||
|
||
return activity_result | ||
|
||
|
||
class _PostHogClientWorkflowInterceptor(WorkflowInboundInterceptor): | ||
async def execute_workflow(self, input: ExecuteWorkflowInput) -> Any: | ||
ph_client = Client(api_key="sTMFPsFhdP1Ssg", enable_exception_autocapture=True) | ||
|
||
workflow_result = await super().execute_workflow(input) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't we wrap this call in a |
||
|
||
ph_client.flush() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this call blocking? Should we send it to a thread with |
||
|
||
return workflow_result | ||
|
||
|
||
class PostHogClientInterceptor(Interceptor): | ||
"""PostHog Interceptor class which will report workflow & activity exceptions to PostHog""" | ||
|
||
def intercept_activity(self, next: ActivityInboundInterceptor) -> ActivityInboundInterceptor: | ||
"""Implementation of | ||
:py:meth:`temporalio.worker.Interceptor.intercept_activity`. | ||
""" | ||
return _PostHogClientActivityInboundInterceptor(super().intercept_activity(next)) | ||
|
||
def workflow_interceptor_class( | ||
self, input: WorkflowInterceptorClassInput | ||
) -> Optional[type[WorkflowInboundInterceptor]]: | ||
return _PostHogClientWorkflowInterceptor |
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.
Out of curiosity, is this api key public?