npx skills add ...
npx skills add getsentry/sentry-for-cursor --skill sentry-setup-logging
npx skills add getsentry/sentry-for-cursor --skill sentry-setup-logging
Setup Sentry Logging in any project. Use this when asked to add Sentry logs, enable structured logging, setup console log capture, or integrate logging with Sentry. Supports JavaScript, TypeScript, Python, Ruby, React, Next.js, and other frameworks.
This skill helps configure Sentry's structured logging feature across multiple platforms and frameworks.
Invoke this skill when:
Sentry.logger or sentry_sdk.loggerBefore configuring, detect the project's platform:
Check for these files:
package.json - Read to identify framework and Sentry SDK version@sentry/nextjs, @sentry/react, @sentry/node, @sentry/browser, etc.Check for:
requirements.txt, pyproject.toml, setup.py, or Pipfilesentry-sdk version 2.35.0+ (required for logging)Check for:
Gemfile or *.gemspecsentry-ruby gem version 5.24.0+ (required for logging)Ask the user:
9.41.0+10.12.0+If version is below 9.41.0, inform user to upgrade:
Find the Sentry.init() call and add enableLogs: true.
Locate init files:
instrumentation-client.ts, sentry.server.config.ts, sentry.edge.config.tssrc/index.tsx, src/main.tsx, or dedicated sentry config fileModify init:
If user wants console log capture, add the integration:
Available console levels: debug, info, warn, error, log, assert, trace
If user wants to filter logs before sending:
Provide these examples to the user:
Pino Integration:
Winston Integration:
Consola Integration (SDK 10.12.0+):
sentry-sdk version 2.35.0+If version is below 2.35.0:
Find sentry_sdk.init() and add enable_logs=True.
Common locations:
settings.pyapp.py or __init__.pymain.pyModify init:
To capture Python's stdlib logging:
Available levels: logging.DEBUG, logging.INFO, logging.WARNING, logging.ERROR, logging.CRITICAL
sentry-ruby version 5.24.0+If version is below 5.24.0:
Then run bundle update sentry-ruby
Find Sentry.init block and add config.enable_logs = true.
Common locations:
config/initializers/sentry.rbModify init:
To capture Ruby's stdlib Logger:
instrumentation-client.ts, sentry.server.config.ts, sentry.edge.config.tsSentry.logger from @sentry/nextjsSentry.logger from @sentry/reactSentry.logger from @sentry/nodesettings.pyconfig/initializers/sentry.rb:logger patch for stdlib Logger captureAfter setup, provide these verification instructions:
Tell user to check their Sentry dashboard under Logs section to verify logs are arriving.
Solutions:
enableLogs: true (JS) or enable_logs=True (Python/Ruby) is setSolutions:
beforeSendLog / before_send_log to filterSolutions:
integrations arraylevels arraySolutions:
npm install @sentry/nextjs@latestpip install --upgrade sentry-sdkbundle update sentry-rubyProvide this checklist after setup:
| Platform | SDK Version | Enable Flag | Logger API |
|---|---|---|---|
| JavaScript | 9.41.0+ | enableLogs: true | Sentry.logger.* |
| Python | 2.35.0+ | enable_logs=True | sentry_sdk.logger.* |
| Ruby | 5.24.0+ | config.enable_logs = true | Sentry.logger.* |
| Log Level | JavaScript | Python | Ruby |
|---|---|---|---|
| Trace | trace() | trace() | trace() |
| Debug | debug() | debug() | debug() |
| Info | info() | info() | info() |
| Warning | warn() | warning() | warning() |
| Error | error() | error() | error() |
| Fatal | fatal() | fatal() | fatal() |
import * as Sentry from "@sentry/nextjs"; // or @sentry/react, @sentry/node, etc.
Sentry.init({
dsn: "YOUR_DSN_HERE",
// Enable structured logging
enableLogs: true,
// ... other existing config
});import * as Sentry from "@sentry/nextjs";
Sentry.init({
dsn: "YOUR_DSN_HERE",
enableLogs: true,
integrations: [
Sentry.consoleLoggingIntegration({
levels: ["log", "warn", "error"] // Customize as needed
}),
],
});Sentry.init({
dsn: "YOUR_DSN_HERE",
enableLogs: true,
beforeSendLog: (log) => {
// Drop info-level logs
if (log.level === "info") {
return null;
}
// Modify or pass through
return log;
},
});// Basic logging with attributes
Sentry.logger.info("User logged in", {
userId: "user_123",
method: "oauth",
});
Sentry.logger.error("Payment failed", {
orderId: "order_456",
amount: 99.99,
currency: "USD",
});
// Template literal formatting (creates searchable attributes)
Sentry.logger.info(
Sentry.logger.fmt`User '${user.name}' purchased '${product.name}'`
);
// All available log levels
Sentry.logger.trace("Detailed trace info");
Sentry.logger.debug("Debug information");
Sentry.logger.info("Informational message");
Sentry.logger.warn("Warning message");
Sentry.logger.error("Error occurred");
Sentry.logger.fatal("Fatal error - application cannot continue");import * as Sentry from "@sentry/node";
import pino from "pino";
Sentry.init({
dsn: "YOUR_DSN_HERE",
enableLogs: true,
integrations: [Sentry.pinoIntegration()],
});
const logger = pino();
logger.info("This goes to Sentry");import * as Sentry from "@sentry/node";
import winston from "winston";
Sentry.init({
dsn: "YOUR_DSN_HERE",
enableLogs: true,
});
const sentryTransport = Sentry.createSentryWinstonTransport();
const logger = winston.createLogger({
transports: [sentryTransport],
});import * as Sentry from "@sentry/node";
import { consola } from "consola";
Sentry.init({
dsn: "YOUR_DSN_HERE",
enableLogs: true,
});
const sentryReporter = Sentry.createConsolaReporter({
levels: ["error", "warn", "info"],
});
consola.addReporter(sentryReporter);pip show sentry-sdk | grep Versionpip install --upgrade sentry-sdkimport sentry_sdk
sentry_sdk.init(
dsn="YOUR_DSN_HERE",
# Enable structured logging
enable_logs=True,
# ... other existing config
)import logging
import sentry_sdk
from sentry_sdk.integrations.logging import LoggingIntegration
sentry_sdk.init(
dsn="YOUR_DSN_HERE",
enable_logs=True,
integrations=[
LoggingIntegration(
sentry_logs_level=logging.WARNING # Capture WARNING and above
)
],
)def before_send_log(log, hint):
# Drop info-level logs
if log["severity_text"] == "info":
return None
return log
sentry_sdk.init(
dsn="YOUR_DSN_HERE",
enable_logs=True,
before_send_log=before_send_log,
)from sentry_sdk import logger as sentry_logger
# Basic logging with placeholder syntax
sentry_logger.info("User logged in: {user_id}", user_id="user_123")
sentry_logger.error(
"Payment failed. Order: {order_id}. Amount: {amount}",
order_id="order_456",
amount=99.99
)
# Using attributes kwarg for additional context
sentry_logger.warning(
"Rate limit approaching",
attributes={
"endpoint": "/api/users",
"current_rate": 95,
"limit": 100,
}
)
# All available log levels
sentry_logger.trace("Detailed trace info")
sentry_logger.debug("Debug information")
sentry_logger.info("Informational message")
sentry_logger.warning("Warning message")
sentry_logger.error("Error occurred")
sentry_logger.fatal("Fatal error")import sentry_sdk
from sentry_sdk.integrations.loguru import LoguruIntegration, LoggingLevels
from loguru import logger
sentry_sdk.init(
dsn="YOUR_DSN_HERE",
enable_logs=True,
integrations=[
LoguruIntegration(
sentry_logs_level=LoggingLevels.WARNING.value
)
],
)
logger.warning("This goes to Sentry")bundle show sentry-ruby
# or
gem list sentry-ruby# In Gemfile
gem "sentry-ruby", ">= 5.24.0"Sentry.init do |config|
config.dsn = "YOUR_DSN_HERE"
# Enable structured logging
config.enable_logs = true
# ... other existing config
endSentry.init do |config|
config.dsn = "YOUR_DSN_HERE"
config.enable_logs = true
config.enabled_patches = [:logger]
end# Basic logging
Sentry.logger.info("User logged in")
# With named parameters (become searchable attributes)
Sentry.logger.debug("Cache miss for user %{user_id}", user_id: 123)
Sentry.logger.error(
"Payment failed. Order: %{order_id}. Amount: %{amount}",
order_id: "order_456",
amount: 99.99
)
# All available log levels
Sentry.logger.trace("Detailed trace info")
Sentry.logger.debug("Debug information")
Sentry.logger.info("Informational message")
Sentry.logger.warning("Warning message")
Sentry.logger.error("Error occurred")
Sentry.logger.fatal("Fatal error")// Add this temporarily to test
Sentry.logger.info("Sentry logging test", {
test: true,
timestamp: new Date().toISOString(),
});
console.log("Console capture test"); // If console integration enabledfrom sentry_sdk import logger as sentry_logger
sentry_logger.info("Sentry logging test", test=True)
import logging
logging.warning("Standard logging test") # If LoggingIntegration enabledSentry.logger.info("Sentry logging test")## Sentry Logging Setup Complete
### Configuration Applied:
- [ ] SDK version verified (meets minimum requirements)
- [ ] `enableLogs` / `enable_logs` added to Sentry.init()
- [ ] Console integration added (if requested)
- [ ] Log filtering configured (if requested)
- [ ] Third-party logger integration added (if applicable)
### Sample Code Provided:
- [ ] Structured logging examples for your platform
- [ ] Verification test code
### Next Steps:
1. Run your application
2. Trigger some test logs
3. Check Sentry dashboard > Logs section
4. Adjust log levels and filtering as needed