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
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.2.tar.gz.

File metadata

File hashes

Hashes for opentelemetry-instrumentation-discordpy-0.1.2.tar.gz
Algorithm Hash digest
SHA256 724236dd2049a204da2d43c9bf016b0dd819255525148bf7fd0cc54dceee4fdf
MD5 5626d3d33ca2eeea9fbe33c34d8e4f09
BLAKE2b-256 a7377caf2caffb57361b6b37b17a3b0afff3b776dc8421a91ce2f3189e129ecc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opentelemetry_instrumentation_discordpy-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1fe20997d1f81b2cffe5bbb61bca844b3f221b5e34ae449720056295d19872d0
MD5 540f19563a071306c144af673b5af977
BLAKE2b-256 e8e99f00f573cdf7dac00f679cffe32189b75dceeecd103af26673c8d9d83807

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