Index of every page on this site: llms.txt
All skills
andrelandgraf avatar

/sentry-best-practices

@4449331
Run it yourself

Capture exceptions, attach user/context, add spans and breadcrumbs, and log via the Sentry SDK. Use when instrumenting errors, performance, or context in app code.

Use this Skill: https://skilld.dev/gh/andrelandgraf/fullstackrecipes/sentry-best-practices

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

SKILL.md

≈47 tokens for metadata: the name and description. ≈553 when used: this file.

Description uses 2.3% of example budget

Before choosing a Skill, your Agent reads its name and description. All available Skills share that space.

  • A shorter description leaves more room for other Skills. This entry exceeds our 1% size suggestion.

In our Claude Code example, all Skill names and descriptions share 8,000 characters. This Skill uses ≈187 characters, or 2.3%.

The 1% threshold is a size suggestion. Longer descriptions can still fit.

Your model, settings, and other Skills decide how much text your Agent can read.

Example settings and source

The example uses a 200k-token context and default Claude Code settings. The count includes the name, description, separators, and when_to_use when present. Codex also counts local file paths.

Skit's source and limits: Codex 0.160.1, Claude Code 2.1.292.

Sentry Best Practices

Capture exceptions, add context, trace performance, and log with Sentry.

Prerequisites

Complete these setup recipes first:

  • Sentry Setup

Capturing Exceptions

Capture errors that are handled but still worth tracking.

import * as Sentry from "@sentry/nextjs";

try {
  await riskyOperation();
} catch (err) {
  Sentry.captureException(err);
}

Adding Context

setUser persists for the session. Attach tags (indexed, filterable) and extra (arbitrary detail) per exception.

import * as Sentry from "@sentry/nextjs";

Sentry.setUser({ id: session.user.id, email: session.user.email });

Sentry.captureException(err, {
  tags: { feature: "checkout", plan: "pro" },
  extra: { orderId: "order_123", items: cart.items },
});

Clear the user on sign out.

Sentry.setUser(null);

Performance Tracing

Wrap meaningful operations in startSpan. The sync form receives the span for attributes.

import * as Sentry from "@sentry/nextjs";

const users = await Sentry.startSpan(
  { op: "http.client", name: "GET /api/users" },
  async () => (await fetch("/api/users")).json(),
);

Sentry.startSpan({ op: "ui.click", name: "Submit Button Click" }, (span) => {
  span.setAttribute("form", "checkout");
  processSubmit();
});

Breadcrumbs

Console logs, fetches, and UI clicks are captured automatically. Add manual breadcrumbs for custom events.

import * as Sentry from "@sentry/nextjs";

Sentry.addBreadcrumb({
  category: "auth",
  message: "User signed in",
  level: "info",
});

Sentry Logger

Structured logs surface in the Logs tab.

import * as Sentry from "@sentry/nextjs";

const { logger } = Sentry;

logger.info("Payment processed", { orderId: "123", amount: 99.99 });
logger.warn("Rate limit approaching", { current: 90, max: 100 });
logger.error("Payment failed", { orderId: "123", reason: "declined" });

References

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No alerts5mo3 checks · Risk SAFE
  • Gen Agent Trust Hub5mo

    This skill provides documentation and code examples for integrating Sentry into Next.js applications for error tracking and performance monitoring. It follows standard developer practices for application instrumentation.

  • Socket5mo

    No alerts

  • Snyk5mo

    Risk: LOW · No issues

Signed by skilld at 4449331. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 3 weeks ago.

Steadyupdated 6 months ago

README badge

README badge for andrelandgraf/fullstackrecipes/sentry-best-practices