-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
chore(integrations): log Jira issue.updated webhook payloads behind a flag #114822
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
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 |
|---|---|---|
|
|
@@ -10,11 +10,14 @@ | |
| from rest_framework.response import Response | ||
| from sentry_sdk import Scope | ||
|
|
||
| from sentry import features | ||
| from sentry.api.api_owners import ApiOwner | ||
| from sentry.api.api_publish_status import ApiPublishStatus | ||
| from sentry.api.base import cell_silo_endpoint | ||
| from sentry.integrations.services.integration import integration_service | ||
| from sentry.integrations.utils.atlassian_connect import get_integration_from_jwt | ||
| from sentry.integrations.utils.scope import bind_org_context_from_integration | ||
| from sentry.organizations.services.organization import organization_service | ||
| from sentry.ratelimits.config import RateLimitConfig | ||
| from sentry.shared_integrations.exceptions import ApiError | ||
| from sentry.types.ratelimit import RateLimit, RateLimitCategory | ||
|
|
@@ -24,6 +27,26 @@ | |
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
| PAYLOAD_LOGGING_FEATURE = "organizations:jira-issue-updated-payload-logging" | ||
|
|
||
|
|
||
| def _payload_logging_enabled(integration_id: int) -> bool: | ||
| """True if any org linked to this Jira integration has the | ||
| `jira-issue-updated-payload-logging` feature enabled. | ||
|
|
||
| A Jira integration can be shared by multiple Sentry orgs, and | ||
| `features.has` needs an `Organization`, so we have to walk the linked | ||
| `OrganizationIntegration` rows and look each org up. | ||
| """ | ||
| contexts = integration_service.organization_contexts(integration_id=integration_id) | ||
| for oi in contexts.organization_integrations: | ||
| org = organization_service.get_organization_by_id( | ||
| id=oi.organization_id, include_teams=False, include_projects=False | ||
| ) | ||
| if org and features.has(PAYLOAD_LOGGING_FEATURE, org.organization): | ||
| return True | ||
|
Contributor
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. Redundant RPC calls on every webhook requestMedium Severity
Reviewed by Cursor Bugbot for commit 7bfa989. Configure here. |
||
| return False | ||
|
|
||
|
|
||
| @cell_silo_endpoint | ||
| class JiraIssueUpdatedWebhook(JiraWebhookBase): | ||
|
|
@@ -75,6 +98,36 @@ | |
| sentry_sdk.set_tag("integration_id", rpc_integration.id) | ||
|
|
||
| data = request.data | ||
|
|
||
| # Temporary: when a linked org has the | ||
| # `jira-issue-updated-payload-logging` feature enabled, log the full | ||
| # webhook payload so we can see exactly what Jira sends us (especially | ||
| # for `project` changes, which we want to use to update the linked | ||
| # Jira issue link in Sentry). | ||
| if _payload_logging_enabled(rpc_integration.id): | ||
| issue = data.get("issue") or {} | ||
| fields = issue.get("fields") or {} | ||
| changelog_items = (data.get("changelog") or {}).get("items") or [] | ||
| payload_extra = { | ||
| "integration_id": rpc_integration.id, | ||
| "issue_key": issue.get("key"), | ||
| "issue_id": issue.get("id"), | ||
| "webhook_event": data.get("webhookEvent"), | ||
| "changed_fields": [item.get("field") for item in changelog_items], | ||
|
Check failure on line 116 in src/sentry/integrations/jira/webhooks/issue_updated.py
|
||
|
Comment on lines
+114
to
+116
Contributor
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. Full Jira webhook payload logged to durable operational sink The handler logs the entire Jira VerificationTraced the data flow: Identified by Warden |
||
| "project": fields.get("project"), | ||
| "payload": data, | ||
| } | ||
| logger.info("jira.issue-updated.payload", extra=payload_extra) | ||
| project_change = next( | ||
| (item for item in changelog_items if item.get("field") == "project"), | ||
| None, | ||
| ) | ||
| if project_change is not None: | ||
| logger.info( | ||
| "jira.issue-updated.project-changed", | ||
| extra={**payload_extra, "project_change": project_change}, | ||
| ) | ||
|
Contributor
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. Unprotected diagnostic code can break webhook processingMedium Severity The call to Additional Locations (1)Reviewed by Cursor Bugbot for commit 7bfa989. Configure here. |
||
|
|
||
| if not data.get("changelog"): | ||
| logger.info("jira.missing-changelog", extra={"integration_id": rpc_integration.id}) | ||
| return self.respond() | ||
|
|
||


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.
Bug: The function
_payload_logging_enabledintroduces an N+1 database query pattern in the Jiraissue.updatedwebhook handler, causing unnecessary latency on every request.Severity: MEDIUM
Suggested Fix
The
organization_idvalues are already available in thecontexts.organization_integrationsobject. Use these IDs directly for the feature flag check. Alternatively, fetch all required organization objects in a single batch query instead of making individual database calls in a loop.Prompt for AI Agent
Did we get this right? 👍 / 👎 to inform future reviews.