From fdddf2ca2634cdf6dabe4fa0f51c6ce79098f8de Mon Sep 17 00:00:00 2001 From: Enno Gelhaus Date: Thu, 31 Jul 2025 22:53:02 +0200 Subject: [PATCH] Update copilot-instructions.md --- .github/copilot-instructions.md | 63 +++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md index 220e7bd7..fbd90264 100644 --- a/.github/copilot-instructions.md +++ b/.github/copilot-instructions.md @@ -49,5 +49,68 @@ --- +# Logs + +- Where logs are used, ensure Sentry is imported using `import * as Sentry from "@sentry/nextjs"` +- Enable logging in Sentry using `Sentry.init({ enableLogs: true })` +- Reference the logger using `const { logger } = Sentry` +- Sentry offers a `consoleLoggingIntegration` that can be used to log specific console error types automatically without instrumenting the individual logger calls + +## Configuration + +The Sentry initialization needs to be updated to enable the logs feature. + +### Baseline + +```javascript +import * as Sentry from "@sentry/nextjs"; + +Sentry.init({ + dsn: "https://examplePublicKey@o0.ingest.sentry.io/0", + + enableLogs: true, +}); +``` + +### Logger Integration + +```javascript +Sentry.init({ + dsn: "https://examplePublicKey@o0.ingest.sentry.io/0", + integrations: [ + // send console.log, console.error, and console.warn calls as logs to Sentry + Sentry.consoleLoggingIntegration({ levels: ["log", "error", "warn"] }), + ], +}); +``` + +## Logger Examples + +`logger.fmt` is a template literal function that should be used to bring variables into the structured logs. + +```javascript +import * as Sentry from "@sentry/nextjs"; + +const { logger } = Sentry; + +logger.trace("Starting database connection", { database: "users" }); +logger.debug(logger.fmt`Cache miss for user: ${userId}`); +logger.info("Updated profile", { profileId: 345 }); +logger.warn("Rate limit reached for endpoint", { + endpoint: "/api/results/", + isEnterprise: false, +}); +logger.error("Failed to process payment", { + orderId: "order_123", + amount: 99.99, +}); +logger.fatal("Database connection pool exhausted", { + database: "users", + activeConnections: 100, +}); +``` + +--- + For questions or unclear conventions, check the main README or ask for clarification in your PR description.