Skip to content

Commit 9b0d0c9

Browse files
committed
Adding AI snippet to logs for nextjs, node, react
1 parent f8642e9 commit 9b0d0c9

File tree

4 files changed

+204
-0
lines changed

4 files changed

+204
-0
lines changed

docs/platforms/javascript/common/logs/index.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ notSupported:
1010
- javascript.capacitor
1111
---
1212

13+
<PlatformContent includePath="llm-rules-logs" />
14+
1315
<Include name="feature-stage-beta-logs.mdx" />
1416

1517
With Sentry Structured Logs, you can send text based log information from your applications to Sentry. Once in Sentry, these logs can be viewed alongside relevant errors, searched by text-string, or searched using their individual attributes.
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<Expandable title="Logger Rules for Cursor or Windsurf" copy={true}>
2+
3+
4+
````markdown {filename:rules.md}
5+
6+
# Logs
7+
8+
- Where logs are used, ensure Sentry is imported using `import * as Sentry from "@sentry/nextjs"`
9+
- Reference the logger using `const { logger } = Sentry`
10+
- Sentry initialization needs to be updated to include the `logger` integration.
11+
- Sentry offers a `consoleLoggingIntegration` that can be used to log specific console error types automatically without instrumenting the individual logger calls
12+
13+
## Configuration
14+
15+
The Sentry initialization needs to be updated to enable the logs feature.
16+
17+
### Baseline
18+
19+
```javascript
20+
import * as Sentry from "@sentry/nextjs";
21+
22+
Sentry.init({
23+
dsn: "https://[email protected]/0",
24+
25+
_experiments: {
26+
enableLogs: true,
27+
},
28+
29+
});
30+
```
31+
32+
### Logger Integration
33+
34+
```javascript
35+
Sentry.init({
36+
dsn: "https://[email protected]/0",
37+
integrations: [
38+
// send console.log, console.error, and console.warn calls as logs to Sentry
39+
Sentry.consoleLoggingIntegration({ levels: ["log", "error", "warn"] }),
40+
],
41+
});
42+
```
43+
44+
## Logger Examples
45+
46+
```javascript
47+
import * as Sentry from "@sentry/nextjs";
48+
49+
const { logger } = Sentry;
50+
51+
logger.trace("Starting database connection", { database: "users" });
52+
logger.debug("Cache miss for user", { userId: 123 });
53+
logger.info("Updated profile", { profileId: 345 });
54+
logger.warn("Rate limit reached for endpoint", {
55+
endpoint: "/api/results/",
56+
isEnterprise: false,
57+
});
58+
logger.error("Failed to process payment", {
59+
orderId: "order_123",
60+
amount: 99.99,
61+
});
62+
logger.fatal("Database connection pool exhausted", {
63+
database: "users",
64+
activeConnections: 100,
65+
});
66+
```
67+
````
68+
</Expandable>
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<Expandable title="Logger Rules for Cursor or Windsurf" copy={true}>
2+
3+
4+
````markdown {filename:rules.md}
5+
6+
# Logs
7+
8+
- Where logs are used, ensure Sentry is imported using `import * as Sentry from "@sentry/node"`
9+
- Reference the logger using `const { logger } = Sentry`
10+
- Sentry initialization needs to be updated to include the `logger` integration.
11+
- Sentry offers a `consoleLoggingIntegration` that can be used to log specific console error types automatically without instrumenting the individual logger calls
12+
13+
## Configuration
14+
15+
The Sentry initialization needs to be updated to enable the logs feature.
16+
17+
### Baseline
18+
19+
```javascript
20+
import * as Sentry from "@sentry/node";
21+
22+
Sentry.init({
23+
dsn: "https://[email protected]/0",
24+
25+
_experiments: {
26+
enableLogs: true,
27+
},
28+
29+
});
30+
```
31+
32+
### Logger Integration
33+
34+
```javascript
35+
Sentry.init({
36+
dsn: "https://[email protected]/0",
37+
integrations: [
38+
// send console.log, console.error, and console.warn calls as logs to Sentry
39+
Sentry.consoleLoggingIntegration({ levels: ["log", "error", "warn"] }),
40+
],
41+
});
42+
```
43+
44+
## Logger Examples
45+
46+
```javascript
47+
import * as Sentry from "@sentry/node";
48+
49+
const { logger } = Sentry;
50+
51+
logger.trace("Starting database connection", { database: "users" });
52+
logger.debug("Cache miss for user", { userId: 123 });
53+
logger.info("Updated profile", { profileId: 345 });
54+
logger.warn("Rate limit reached for endpoint", {
55+
endpoint: "/api/results/",
56+
isEnterprise: false,
57+
});
58+
logger.error("Failed to process payment", {
59+
orderId: "order_123",
60+
amount: 99.99,
61+
});
62+
logger.fatal("Database connection pool exhausted", {
63+
database: "users",
64+
activeConnections: 100,
65+
});
66+
```
67+
````
68+
</Expandable>
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<Expandable title="Logger Rules for Cursor or Windsurf" copy={true}>
2+
3+
4+
````markdown {filename:rules.md}
5+
6+
# Logs
7+
8+
- Where logs are used, ensure Sentry is imported using `import * as Sentry from "@sentry/react"`
9+
- Reference the logger using `const { logger } = Sentry`
10+
- Sentry initialization needs to be updated to include the `logger` integration.
11+
- Sentry offers a `consoleLoggingIntegration` that can be used to log specific console error types automatically without instrumenting the individual logger calls
12+
13+
## Configuration
14+
15+
The Sentry initialization needs to be updated to enable the logs feature.
16+
17+
### Baseline
18+
19+
```javascript
20+
Sentry.init({
21+
dsn: "https://[email protected]/0",
22+
23+
_experiments: {
24+
enableLogs: true,
25+
},
26+
27+
});
28+
```
29+
30+
### Logger Integration
31+
32+
```javascript
33+
Sentry.init({
34+
dsn: "https://[email protected]/0",
35+
integrations: [
36+
// send console.log, console.error, and console.warn calls as logs to Sentry
37+
Sentry.consoleLoggingIntegration({ levels: ["log", "error", "warn"] }),
38+
],
39+
});
40+
```
41+
42+
## Logger Examples
43+
44+
```javascript
45+
import * as Sentry from "@sentry/react";
46+
47+
const { logger } = Sentry;
48+
49+
logger.trace("Starting database connection", { database: "users" });
50+
logger.debug("Cache miss for user", { userId: 123 });
51+
logger.info("Updated profile", { profileId: 345 });
52+
logger.warn("Rate limit reached for endpoint", {
53+
endpoint: "/api/results/",
54+
isEnterprise: false,
55+
});
56+
logger.error("Failed to process payment", {
57+
orderId: "order_123",
58+
amount: 99.99,
59+
});
60+
logger.fatal("Database connection pool exhausted", {
61+
database: "users",
62+
activeConnections: 100,
63+
});
64+
```
65+
````
66+
</Expandable>

0 commit comments

Comments
 (0)