Skip to main content

OpenTelemetry instrumentation for discord.py bots

Project description

OpenTelemetry Instrumentation for Discord.py

This library provides OpenTelemetry instrumentation for bots built with discord.py, making it easy to collect traces, metrics, and logs to analyze the performance and reliability of your Discord bots.

Features

  • Automatic instrumentation for common discord.py events and activities.
  • Decorators for manual instrumentation of bot commands and event handlers.
  • Easy integration with OpenTelemetry's ecosystem for observability and monitoring.

Features Overview

The OpenTelemetry Instrumentation for Discord.py is designed to enhance the observability of your Discord bots, providing detailed insights into their operations and interactions. Here are the key features currently implemented:

  • Automatic Tracing: Automatically instruments your bot to trace key Discord events and activities, ensuring comprehensive visibility with minimal setup.

  • Manual Tracing Support: Offers decorators and utilities for manual instrumentation, allowing you to tailor tracing to your bot's specific needs and workflows.

  • send_message Instrumentation: Traces calls to send_message, providing insights into message sending operations, including execution times and potential bottlenecks.

  • edit_message Instrumentation: Captures detailed information about edit_message operations, enabling you to track how message edits affect bot performance and user interactions.

  • on_message Event Tracing: Automatically traces the on_message event, offering visibility into message processing and the bot's responsiveness to user messages.

These features are designed to give developers and operators comprehensive insights into the behavior and performance of their Discord bots, facilitating better monitoring, troubleshooting, and optimization.

Do note, this build is currently in alpha so the above featureset is quite small. I will do more to edit it as I get time.

Installation

Install this package with pip:

pip install opentelemetry-instrumentation-discordpy

Usage

Automatic Instrumentation

To automatically instrument your Discord bot, simply initialize the instrumentation at the start of your bot's code:

from opentelemetry_instrumentation_discordpy import DiscordPyInstrumentor
DiscordPyInstrumentor().instrument()

Manual Instrumentation

For more fine-grained control, use the provided decorators to instrument specific commands or event handlers:

from opentelemetry_instrumentation_discordpy import trace
from opentelemetry_instrumentation_discordpy.decorators import trace as otel_trace

@trace()
async def on_message(message):
    if message.author == bot.user:
        return

    tracer = trace.get_tracer(__name__)
    with tracer.start_as_current_span("on_message_event"):
        print(f"Message from {message.author}: {message.content}") # replace with logic you'd like the bot to trace
        # Ensure the bot can still process commands
        await bot.process_commands(message)

# option 1 for tracing
@bot.command(name='echo', help='Replies with the same message it receives.')
async def echo(ctx, *, message: str):
    tracer = trace.get_tracer(__name__)
    with tracer.start_as_current_span("echo_command"):
        await ctx.send(message)

#option 2 for tracing
@bot.command(name='echo', help='Replies with the same message it receives.')
@otel_trace()
async def echo(ctx, *, message: str):
    await ctx.send(message)

For a basic practical example of setting up a bot with OpenTelemetry instrumentation, see the basic bot example.

For a more advanceced practical example of setting up a bot with OpenTelemetry instrumentation, see the advanced bot example.

Configuration

Refer to the documentation for detailed configuration options and advanced usage. (This is WIP)

Contributing

Contributions are welcome! See CONTRIBUTING.md for how to get started.

License

This library is licensed under the BSD License.

Support

If you encounter any issues or have questions, please file an issue on GitHub.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file opentelemetry-instrumentation-discordpy-0.1.4.tar.gz.

File metadata

File hashes

Hashes for opentelemetry-instrumentation-discordpy-0.1.4.tar.gz
Algorithm Hash digest
SHA256 f90eb75d70ba97ebd874936dceb5e0885e3a2197bff7a4b9d5c16f19329c9fc4
MD5 5b2c0c408b7f12e9f9d63791f3dbc9d6
BLAKE2b-256 4494627402c2d2c414bda727e88d27bffe67023f823ca3b3329378a9bda06727

See more details on using hashes here.

File details

Details for the file opentelemetry_instrumentation_discordpy-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for opentelemetry_instrumentation_discordpy-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 6e33aa400b8adbd664c9ce3f9b4baa624d9caf08a2d6b4c92e91a72c31d8f6af
MD5 b63d5609ae82b7f21bd8d4ba3d69133c
BLAKE2b-256 483e89d694d2bf61dc7ae96ce82031bd1fee1bafa00c2a9671e52d62c30af14f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page