Skip to content

feat(integrations): add Discord audit log integration - #9150

Open
afreenorbit wants to merge 2 commits into
Flagsmith:mainfrom
afreenorbit:feat/discord-integration
Open

afreenorbit wants to merge 2 commits into
Flagsmith:mainfrom
afreenorbit:feat/discord-integration

Conversation

@afreenorbit

Copy link
Copy Markdown

Thanks for submitting a PR! Please check the boxes below:

  • I have read the Contributing Guide.
  • I have added information to docs/ if required so people know about the feature.
  • I have filled in the "Changes" section below.
  • I have filled in the "How did you test this code" section below.

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 (api/integrations/discord/): DiscordConfiguration is project-level, one per project, with the webhook URL in base_url (NoSSRFURLField). The serializer only accepts Discord webhook URLs (https://discord.com/api/webhooks/<id>/<token>, plus the canary/ptb/discordapp.com variants). A CRUD viewset is registered at projects/<id>/integrations/discord/, with a named migration.
  • Event: DiscordWrapper sends 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 sets allowed_mentions: {"parse": []}, so a flag or segment name containing @everyone never pings anyone. When Discord rejects a post (a deleted webhook, rate limiting), it logs a structured discord.webhook.failed warning and does not raise.
  • Signal: a send_audit_log_event_to_discord receiver, the same as the Datadog one, so it only posts feature-related events.
  • Dashboard: an integration card in default-flags.ts with a single hidden field for the webhook URL, and the Discord logo (Simple Icons, CC0).
  • Docs: third-party-integrations/project-management/discord.md and a card on the integrations index.

Notes for reviewers:

  1. Self-hosted dashboards read integration_data from the "Self Hosted Defaults" remote flag (frontend/env/project_selfhosted.js), so the default-flags.ts entry is only a fallback. The discord entry also needs adding to that flag for the card to appear on self-hosted instances. I checked this by pointing FLAGSMITH_ON_FLAGSMITH_API_URL at a local instance with the entry added.
  2. Deleting a feature posts one message per environment, because one audit record is written per environment. That matches the other audit log integrations.
  3. Changes made with an Admin API key show "By: system", which comes from 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/:

    • event data: the embed with project, environment and author; title clipping; and mention suppression;
    • _track_event: posting to the webhook, and a rejected post, which is logged as a structured discord.webhook.failed event, checked with pytest_structlog;
    • the signal receiver: it sends when a project config exists, does nothing without one, and ignores unrelated events;
    • the viewset: create, rejecting non-Discord URLs, one configuration per project, and delete then recreate.

    The new tests plus the existing tests/unit/audit tests pass: 90 tests, with 100% coverage of integrations/discord.

  • makemigrations --check --dry-run reports no changes. mypy and ruff check/ruff format are 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-unified image 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.

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
afreenorbit requested review from a team as code owners November 27, 2026 18:26
@afreenorbit
afreenorbit requested review from matthewelwell and talissoncosta and removed request for a team November 27, 2026 18:26
@vercel

vercel Bot commented Nov 27, 2026

Copy link
Copy Markdown

@afreenorbit is attempting to deploy a commit to the Flagsmith Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions Bot added front-end Issue related to the React Front End Dashboard api Issue related to the REST API docs Documentation updates labels Nov 27, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>

Comment thread api/integrations/discord/serializers.py Resolved
Comment thread api/integrations/discord/discord.py Resolved
Comment thread api/integrations/discord/views.py Resolved
- 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

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api Issue related to the REST API docs Documentation updates front-end Issue related to the React Front End Dashboard

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant