Skip to content

opentelemetry-instrumentation-discord-py: add prefix and app command tracing#4842

Open
nikitagrover19 wants to merge 3 commits into
open-telemetry:mainfrom
nikitagrover19:ng/discord-py-instrumentation
Open

opentelemetry-instrumentation-discord-py: add prefix and app command tracing#4842
nikitagrover19 wants to merge 3 commits into
open-telemetry:mainfrom
nikitagrover19:ng/discord-py-instrumentation

Conversation

@nikitagrover19

Copy link
Copy Markdown

Instruments discord.py prefix commands and app commands via BaseInstrumentor, wrapping Bot.invoke and CommandTree._call.

Relates to #4492

Description

Adds a new opentelemetry-instrumentation-discord-py package. Every prefix
command invocation produces a span named discord.command, and every
app/slash command produces discord.app_command. Both carry
discord.command.name, discord.guild.id, discord.channel.id, and
discord.user.id as attributes. Errors during command execution are
recorded on the span with Status(ERROR).

Package name is opentelemetry-instrumentation-discord-py (not
-discordpy) since that name is already taken on PyPI by an unrelated
project.

This is a draft to get early feedback on the approach before going
further — cc @laggron42 @xrmx. Scope follows what we discussed on the
issue: prefix commands and app commands only, no span-linking across
interactions (dropped per feedback on the issue). Changelog entry still
to be added.

Type of change

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

  • Unit tests added covering prefix command spans, app command spans, and
    error status recording (3 tests, all passing).
  • Verified against a real discord.py 2.4.0+ install (not just mocked) to
    confirm the wrapt patch targets (Bot.invoke, CommandTree._call) and
    the Context/Interaction attributes used are correct against the
    actual library.
  • pylint --rcfile .pylintrc: 10.00/10

Does This PR Require a Core Repo Change?

  • No.

Checklist:

See contributing.md for styleguide, changelog guidelines, and more.

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

@linux-foundation-easycla

linux-foundation-easycla Bot commented Jul 20, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: nikitagrover19 / name: Nikita Grover (8dda0a8)

Instruments discord.py prefix commands and app commands via
BaseInstrumentor, wrapping Bot.invoke and CommandTree._call.

Relates to open-telemetry#4492
@nikitagrover19
nikitagrover19 force-pushed the ng/discord-py-instrumentation branch from e23df50 to 8dda0a8 Compare July 20, 2026 08:19
- Docs stub now matches the official _template/autodoc_entry.rst
  (includes README content before the automodule directive)
- Add .changelog/4842.added towncrier fragment
- Regenerate bootstrap_gen.py to register discord.py for
  auto-instrumentation
@nikitagrover19 nikitagrover19 changed the title Add discord.py instrumentation opentelemetry-instrumentation-discord-py: add prefix and app command tracing Jul 20, 2026
Per CONTRIBUTING.md guidance, async tests should inherit
IsolatedAsyncioTestCase rather than being manually driven via
asyncio.run(), which can lead to tests passing without properly
exercising the async code path.
@nikitagrover19
nikitagrover19 marked this pull request as ready for review July 20, 2026 08:49
@nikitagrover19
nikitagrover19 requested a review from a team as a code owner July 20, 2026 08:49
@nikitagrover19

nikitagrover19 commented Jul 20, 2026

Copy link
Copy Markdown
Author

Marking this ready for review. Summary of what's been done since
opening as a draft:

  • Fixed PR title to follow package-name-prefix convention
  • Added changelog fragment (.changelog/4842.added)
  • Fixed docs stub to match the official _template/autodoc_entry.rst
  • Regenerated bootstrap_gen.py to register discord.py
  • Rewrote tests to use IsolatedAsyncioTestCase per the async test
    isolation guidance in CONTRIBUTING.md

pylint: 10.00/10, all tests passing, CLA signed.

@laggron42 @xrmx would appreciate a review whenever you have time.

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

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant