Skip to content

Commit

Permalink
chore(slack): Add Ignore Transaction Boundary in SDK Client for Tests (
Browse files Browse the repository at this point in the history
…#73582)

The old SDK client had some logic to ignore transaction boundaries when
using an RPC call to fetch the integration when running tests (the
function doesn't do anything in production).

https://github.com/getsentry/sentry/blob/master/src/sentry/incidents/serializers/alert_rule.py#L481-L488

This is required because in some parts of our code, we use the SDK
Client within a transaction such as here:

https://github.com/getsentry/sentry/blob/master/src/sentry/incidents/serializers/alert_rule.py#L481-L488

This is safe to do because the RPC call is a read operation.

Without this function, we run into 
```
E   AssertionError: remote service method to /api/0/internal/rpc/integration/get_integration/ called inside transaction!  Move service calls to outside of transactions.
```
when running tests that go through the above mentioned transaction code
path.
  • Loading branch information
iamrajjoshi authored Jul 1, 2024
1 parent b97339b commit 46e5215
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/sentry/integrations/slack/sdk_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from slack_sdk.errors import SlackApiError
from slack_sdk.web import SlackResponse

from sentry.db.postgres.transactions import in_test_hide_transaction_boundary
from sentry.integrations.base import disable_integration, is_response_error, is_response_success
from sentry.integrations.request_buffer import IntegrationRequestBuffer
from sentry.integrations.services.integration import integration_service
Expand Down Expand Up @@ -111,7 +112,14 @@ def __init__(self, integration_id: int):

integration: Integration | RpcIntegration | None
if SiloMode.get_current_mode() == SiloMode.REGION:
integration = integration_service.get_integration(integration_id=integration_id)
"""
# In order to send requests, SlackClient needs to fetch the integration
# to get access tokens which trips up rpc method/transaction
# boundary detection. Those boundaries are not relevant because
# this is a read operation.
"""
with in_test_hide_transaction_boundary():
integration = integration_service.get_integration(integration_id=integration_id)
else: # control or monolith (local)
integration = Integration.objects.filter(id=integration_id).first()

Expand Down

0 comments on commit 46e5215

Please sign in to comment.