Update copilot-instructions.md
This commit is contained in:
parent
f7899681a5
commit
fdddf2ca26
|
|
@ -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.
|
For questions or unclear conventions, check the main README or ask for clarification in your PR description.
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue