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.

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

@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)

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

Configuration

Refer to the documentation for detailed configuration options and advanced usage.

Contributing

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

License

This library is licensed under the MIT 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.1.tar.gz.

File metadata

File hashes

Hashes for opentelemetry-instrumentation-discordpy-0.1.1.tar.gz
Algorithm Hash digest
SHA256 105c85574cfb1f8472f92b374e1372d93fae568ed42f3a80d9768b40b0e0e599
MD5 f29d3303fbb8435e473b2b56bb64cd3d
BLAKE2b-256 90e9027b42c29bf5a45ee7ada4f59a790c7ed82319efa0b2112cd39b6af283f3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opentelemetry_instrumentation_discordpy-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 de6e1ccd3eaea0e1765397886b60ec2bf86f992f0c3ea663f8a24554d118fd9e
MD5 f4dd5e5c8bb18226aeda0a8e5e6f8341
BLAKE2b-256 a65c64ceac737838e9c2eb37f7b67c44ee8c56e8a82d8147d078510975e869f3

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