Skip to content

feat: instrument command latency in Sentry#848

Open
ugcodrr wants to merge 5 commits into
mainfrom
observability/sentry-command-tracing
Open

feat: instrument command latency in Sentry#848
ugcodrr wants to merge 5 commits into
mainfrom
observability/sentry-command-tracing

Conversation

@ugcodrr
Copy link
Copy Markdown
Member

@ugcodrr ugcodrr commented May 12, 2026

Summary

  • add Sentry command transactions with command name/group/subcommand tags and memory usage data
  • normalize command/data/render/reply span names around command.total, command.execute, hypixel.fetch, redis.get, redis.write, redis.command, mongo.query, render.generate, png.encode, and discord.reply
  • centralize span lifecycle helpers in @statsify/logger so spans are finished consistently on success and failure
  • add explicit Mongoose query/aggregate instrumentation for API-side mongo.query spans
  • instrument Canvas#toBuffer("png") once in @statsify/rendering so all rendered command PNG encodes emit png.encode
  • sanitize Discord interaction/webhook route names before attaching them to discord.reply spans
  • keep Sentry Node profiling enabled for the API and Discord bot with configurable profilesSampleRate

Notes

  • Redis reads are grouped under redis.get; known writes use redis.write; unknown Redis commands fall back to redis.command with the concrete command name in span data.
  • Mongo spans are explicit now, while the existing Sentry Mongo integration remains in place.
  • The local checkout still has an unrelated untracked .DS_Store; it was not staged or pushed.

Verification

  • pnpm --filter @statsify/logger test:types
  • pnpm --filter @statsify/rendering test:types
  • pnpm --filter @statsify/api-client test:types
  • pnpm --filter @statsify/discord test:types
  • pnpm --filter api test:types
  • pnpm --filter discord-bot test:types
  • pnpm --filter @statsify/util test:types
  • pnpm --filter @statsify/logger lint
  • pnpm --filter @statsify/rendering lint
  • pnpm --filter @statsify/api-client lint
  • pnpm --filter @statsify/discord lint
  • pnpm --filter api lint
  • pnpm --filter discord-bot lint
  • pnpm --filter @statsify/util lint

@vercel
Copy link
Copy Markdown

vercel Bot commented May 12, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
statsify Skipped Skipped May 31, 2026 2:43am

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds standardized Sentry latency instrumentation across the API, Discord bot, rendering, Redis, Mongo/Mongoose, and outbound HTTP/Discord reply paths.

Changes:

  • Adds shared Sentry span helpers and memory usage tagging in @statsify/logger.
  • Instruments command execution, Discord replies, API/Hypixel fetches, Redis commands, Mongoose queries, JSX rendering, and PNG encoding.
  • Adds Sentry profiling configuration/dependencies and profilesSampleRate config support.

Reviewed changes

Copilot reviewed 24 out of 27 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
.gitmodules No-op formatting/newline change for private assets submodule URL.
config.schema.js Adds default sentry.profilesSampleRate.
pnpm-lock.yaml Updates lockfile for profiling/logger dependencies and transitive changes.
apps/api/package.json Adds Sentry profiling dependency.
apps/api/src/index.ts Enables profiling and Mongoose query instrumentation during API startup.
apps/api/src/hypixel/hypixel.service.ts Wraps Hypixel HTTP calls in Sentry spans.
apps/api/src/leaderboards/leaderboard.service.ts Replaces manual Redis spans with shared span helper.
apps/api/src/redis/redis.utils.ts Instruments Redis commands by wrapping sendCommand.
apps/api/src/sentry/index.ts Exports Mongoose instrumentation helper.
apps/api/src/sentry/mongoose.ts Adds explicit Mongoose query/aggregate span instrumentation.
apps/discord-bot/package.json Adds Sentry profiling dependency.
apps/discord-bot/src/index.ts Enables profiling and configurable trace/profile sampling.
apps/discord-bot/src/lib/command.listener.ts Starts command-level Sentry transactions with command metadata.
apps/discord-bot/src/commands/base.hypixel-command.ts Tags base Hypixel commands with an observability group.
apps/discord-bot/src/commands/ratios/ratios.command.tsx Tags ratios command with an observability group.
packages/api-client/package.json Adds logger dependency for shared span helpers.
packages/api-client/src/api.service.ts Wraps Statsify API requests in Sentry spans.
packages/discord/src/command/abstract-command.listener.ts Wraps command execution in spans and records memory usage.
packages/discord/src/command/command.interface.ts Adds command-level observability group option.
packages/discord/src/command/command.resolvable.ts Stores command metadata group on resolvables.
packages/discord/src/interaction/interaction.ts Instruments Discord REST replies with sanitized route names.
packages/discord/src/services/paginate.service.ts Formatting-only change around PNG buffer generation.
packages/logger/src/index.ts Adds shared Sentry span lifecycle helpers.
packages/rendering/package.json Adds logger dependency for rendering instrumentation.
packages/rendering/src/canvas.ts Instruments PNG canvas encoding globally.
packages/rendering/src/jsx/render.ts Uses shared helpers for JSX render spans.
packages/util/src/config.ts Adds profilesSampleRate to typed config.
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


const transaction = Sentry.startTransaction({ name: commandName, op: "command" });
const [name, ...subcommandParts] = commandName.split(" ");
const group = parentCommand.group ?? command.group ?? "unknown";
Comment on lines 161 to 164
if (err instanceof Message) {
await context.reply(err);
setSentryMemoryUsage(transaction);
transaction?.finish();
@ugcodrr ugcodrr marked this pull request as ready for review May 30, 2026 22:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants