Skip to content

Commit 4c458f3

Browse files
committed
wip: fix metaclass conflict error
- After splitting the worker, workflow, and activity into their own modules, I started to see workflow task error: TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases - Fix the above error by explicitly passing through "sentry_sdk" to the workflow sandbox in the worker options
1 parent 184922b commit 4c458f3

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

sentry/interceptor.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
)
1414

1515
with workflow.unsafe.imports_passed_through():
16-
from sentry_sdk import isolation_scope
16+
import sentry_sdk
1717

1818

1919
logger = logging.getLogger(__name__)
@@ -22,7 +22,7 @@
2222
class _SentryActivityInboundInterceptor(ActivityInboundInterceptor):
2323
async def execute_activity(self, input: ExecuteActivityInput) -> Any:
2424
# https://docs.sentry.io/platforms/python/troubleshooting/#addressing-concurrency-issues
25-
with isolation_scope() as scope:
25+
with sentry_sdk.isolation_scope() as scope:
2626
scope.set_tag("temporal.execution_type", "activity")
2727
scope.set_tag("module", input.fn.__module__ + "." + input.fn.__qualname__)
2828
activity_info = activity.info()
@@ -50,7 +50,7 @@ async def execute_activity(self, input: ExecuteActivityInput) -> Any:
5050
class _SentryWorkflowInterceptor(WorkflowInboundInterceptor):
5151
async def execute_workflow(self, input: ExecuteWorkflowInput) -> Any:
5252
# https://docs.sentry.io/platforms/python/troubleshooting/#addressing-concurrency-issues
53-
with isolation_scope() as scope:
53+
with sentry_sdk.isolation_scope() as scope:
5454
scope.set_tag("temporal.execution_type", "workflow")
5555
scope.set_tag(
5656
"module", input.run_fn.__module__ + "." + input.run_fn.__qualname__

sentry/worker.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
from sentry_sdk.types import Event, Hint
88
from temporalio.client import Client
99
from temporalio.worker import Worker
10+
from temporalio.worker.workflow_sandbox import (
11+
SandboxedWorkflowRunner,
12+
SandboxRestrictions,
13+
)
1014

1115
from sentry.activity import compose_greeting
1216
from sentry.interceptor import SentryInterceptor
@@ -27,7 +31,7 @@ def before_send(event: Event, hint: Hint) -> Event | None:
2731

2832
async def main():
2933
# Configure logging
30-
logging.basicConfig(level=logging.DEBUG)
34+
logging.basicConfig(level=logging.INFO)
3135

3236
# Initialize the Sentry SDK
3337
if sentry_dsn := os.environ.get("SENTRY_DSN"):
@@ -57,6 +61,11 @@ async def main():
5761
workflows=[GreetingWorkflow],
5862
activities=[compose_greeting],
5963
interceptors=[SentryInterceptor()], # Use SentryInterceptor for error reporting
64+
workflow_runner=SandboxedWorkflowRunner(
65+
restrictions=SandboxRestrictions.default.with_passthrough_modules(
66+
"sentry_sdk"
67+
)
68+
),
6069
):
6170
# Wait until interrupted
6271
print("Worker started, ctrl+c to exit")

0 commit comments

Comments
 (0)