Repository navigation
feat(integrations): add Discord audit log integration - #9150
Open
afreenorbit wants to merge 2 commits into
Open
afreenorbit wants to merge 2 commits into
afreenorbit wants to merge 2 commits into
Conversation
Post project audit log events (feature, flag state and segment changes) to a Discord channel through a channel webhook URL. No bot or OAuth is needed, so it works the same on Flagsmith Cloud and self-hosted. - DiscordConfiguration: project-level, like Datadog, with the webhook URL in base_url (NoSSRFURLField) and validated as a Discord webhook URL - DiscordWrapper: one embed per event (log text, project, environment, author, timestamp), never pings anyone (allowed_mentions empty), and a structured discord.webhook.failed warning when Discord rejects a post - dashboard card, icon and docs page
afreenorbit
requested review from
matthewelwell and
talissoncosta
and removed request for
a team
November 27, 2026 18:26
|
@afreenorbit is attempting to deploy a commit to the Flagsmith Team on Vercel. A member of the Team first needs to authorize it. |
There was a problem hiding this comment.
4 issues found across 18 files
Reply to a comment to ask cubic a question or push back. It learns from your replies.
Re-trigger cubic
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="api/integrations/discord/views.py">
<violation number="1" location="api/integrations/discord/views.py:7">
P3: These assignment suppressions have no documented reason, contrary to the API typing guidance. Explain the base-class `None` placeholders or type the base attributes so mypy can check these assignments.</violation>
</file>
<file name="docs/docs/third-party-integrations/project-management/discord.md">
<violation number="1" location="docs/docs/third-party-integrations/project-management/discord.md:11">
P2: Self-hosted users won't see Discord in the Integrations list unless `integration_data` in the “Self Hosted Defaults” remote flag includes this entry. Document that prerequisite; otherwise the setup's Add Integration step cannot be completed.</violation>
<violation number="2" location="docs/docs/third-party-integrations/project-management/discord.md:41">
P2: When the task processor handles delivery, it—not necessarily the API—needs outbound access to `discord.com`. Say the process sending messages must have egress so deployments can configure the correct network boundary.</violation>
</file>
<file name="api/integrations/discord/serializers.py">
<violation number="1" location="api/integrations/discord/serializers.py:17">
P2: This field accepts webhook URLs longer than the model’s 200-character limit, so a matching oversized value passes validation and fails during persistence instead of returning a validation error. Set the serializer field’s `max_length` to 200.</violation>
</file>
- Catch requests.RequestException in DiscordWrapper._track_event and log discord.webhook.failed, so an unreachable Discord never fails the audited change when the postpone decorator is disabled - Limit base_url to 200 characters in the serializer, matching the model column, so an over-long URL is a 400 rather than a database error - Document why the viewset's attribute assignments ignore mypy - Docs: name the process that needs outbound access to discord.com, and explain what to do when the Discord card is missing on self-hosted
There was a problem hiding this comment.
0 issues found across 6 files (changes from recent commits).
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Requires human review: Auto-approval skipped because this PR is from an external contributor.
Re-trigger cubic
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Thanks for submitting a PR! Please check the boxes below:
docs/if required so people know about the feature.Changes
Adds a Discord integration that posts a project's audit log events (feature, flag state and segment changes) to a Discord channel. It is set up with a channel webhook URL, so there is no bot to install and no OAuth, and it works the same on Cloud and self-hosted. Many communities (dev tools, games, open-source projects) coordinate in Discord, and there is no Discord integration today.
It follows the existing Datadog integration closely:
api/integrations/discord/):DiscordConfigurationis project-level, one per project, with the webhook URL inbase_url(NoSSRFURLField). The serializer only accepts Discord webhook URLs (https://discord.com/api/webhooks/<id>/<token>, plus thecanary/ptb/discordapp.comvariants). A CRUD viewset is registered atprojects/<id>/integrations/discord/, with a named migration.DiscordWrappersends one embed per audit log record. The embed holds the log text as the title, plus the project, environment (when there is one), author and timestamp, clipped to Discord's embed limits. It setsallowed_mentions: {"parse": []}, so a flag or segment name containing@everyonenever pings anyone. When Discord rejects a post (a deleted webhook, rate limiting), it logs a structureddiscord.webhook.failedwarning and does not raise.send_audit_log_event_to_discordreceiver, the same as the Datadog one, so it only posts feature-related events.default-flags.tswith a single hidden field for the webhook URL, and the Discord logo (Simple Icons, CC0).third-party-integrations/project-management/discord.mdand a card on the integrations index.Notes for reviewers:
integration_datafrom the "Self Hosted Defaults" remote flag (frontend/env/project_selfhosted.js), so thedefault-flags.tsentry is only a fallback. Thediscordentry also needs adding to that flag for the card to appear on self-hosted instances. I checked this by pointingFLAGSMITH_ON_FLAGSMITH_API_URLat a local instance with the entry added.author_identifier.Happy to open an issue first, rename anything or move the docs page if you'd prefer it elsewhere.
How did you test this code?
Unit tests in
api/tests/unit/integrations/discord/:_track_event: posting to the webhook, and a rejected post, which is logged as a structureddiscord.webhook.failedevent, checked withpytest_structlog;The new tests plus the existing
tests/unit/audittests pass: 90 tests, with 100% coverage ofintegrations/discord.makemigrations --check --dry-runreports no changes.mypyandruff check/ruff formatare clean on the changed Python files, and Prettier and ESLint are clean on the docs and frontend files.End to end: I built the
oss-unifiedimage from this branch and ran it as a self-hosted stack against an existing database, and the migration applied. In the dashboard I went to Integrations → Discord, pasted a channel webhook URL and saved. Creating, toggling and deleting a feature then posted embeds to the channel.