Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/platforms/javascript/common/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

<PlatformSection noGuides>

<PlatformContent includePath="llm-rules-platform" />

<Alert title="Using a framework?">

Check out the other SDKs we support in the left-hand dropdown.
Expand Down
2 changes: 2 additions & 0 deletions docs/platforms/javascript/common/logs/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ notSupported:
- javascript.capacitor
---

<PlatformContent includePath="llm-rules-logs" />

<Include name="feature-stage-beta-logs.mdx" />

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.
Expand Down
2 changes: 2 additions & 0 deletions docs/platforms/javascript/guides/nextjs/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ categories:
- server-node
---

<PlatformContent includePath="llm-rules-platform" />

<PlatformContent includePath="getting-started-prerequisites" />

## Step 1: Install
Expand Down
2 changes: 2 additions & 0 deletions docs/platforms/javascript/guides/node/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ categories:

<PlatformContent includePath="getting-started-primer" />

<PlatformContent includePath="llm-rules-platform" />

<PlatformContent includePath="getting-started-node" />
2 changes: 2 additions & 0 deletions docs/platforms/javascript/guides/react/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ categories:
- browser
---

<PlatformContent includePath="llm-rules-platform" />

<PlatformContent includePath="getting-started-prerequisites" />

## Step 1: Install
Expand Down
68 changes: 68 additions & 0 deletions platform-includes/llm-rules-logs/javascript.nextjs.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<Expandable title="Logger Rules for Cursor or Windsurf" copy={true}>


````markdown {filename:rules.md}

# Logs

- Where logs are used, ensure Sentry is imported using `import * as Sentry from "@sentry/nextjs"`
- Reference the logger using `const { logger } = Sentry`
- Sentry initialization needs to be updated to include the `logger` integration.
- 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://[email protected]/0",

_experiments: {
enableLogs: true,
},

});
```

### Logger Integration

```javascript
Sentry.init({
dsn: "https://[email protected]/0",
integrations: [
// send console.log, console.error, and console.warn calls as logs to Sentry
Sentry.consoleLoggingIntegration({ levels: ["log", "error", "warn"] }),
],
});
```

## Logger Examples

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

const { logger } = Sentry;

logger.trace("Starting database connection", { database: "users" });
logger.debug("Cache miss for user", { userId: 123 });
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,
});
```
````
</Expandable>
68 changes: 68 additions & 0 deletions platform-includes/llm-rules-logs/javascript.node.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<Expandable title="Logger Rules for Cursor or Windsurf" copy={true}>


````markdown {filename:rules.md}

# Logs

- Where logs are used, ensure Sentry is imported using `import * as Sentry from "@sentry/node"`
- Reference the logger using `const { logger } = Sentry`
- Sentry initialization needs to be updated to include the `logger` integration.
- 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/node";

Sentry.init({
dsn: "https://[email protected]/0",

_experiments: {
enableLogs: true,
},

});
```

### Logger Integration

```javascript
Sentry.init({
dsn: "https://[email protected]/0",
integrations: [
// send console.log, console.error, and console.warn calls as logs to Sentry
Sentry.consoleLoggingIntegration({ levels: ["log", "error", "warn"] }),
],
});
```

## Logger Examples

```javascript
import * as Sentry from "@sentry/node";

const { logger } = Sentry;

logger.trace("Starting database connection", { database: "users" });
logger.debug("Cache miss for user", { userId: 123 });
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,
});
```
````
</Expandable>
66 changes: 66 additions & 0 deletions platform-includes/llm-rules-logs/javascript.react.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<Expandable title="Logger Rules for Cursor or Windsurf" copy={true}>


````markdown {filename:rules.md}

# Logs

- Where logs are used, ensure Sentry is imported using `import * as Sentry from "@sentry/react"`
- Reference the logger using `const { logger } = Sentry`
- Sentry initialization needs to be updated to include the `logger` integration.
- 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
Sentry.init({
dsn: "https://[email protected]/0",

_experiments: {
enableLogs: true,
},

});
```

### Logger Integration

```javascript
Sentry.init({
dsn: "https://[email protected]/0",
integrations: [
// send console.log, console.error, and console.warn calls as logs to Sentry
Sentry.consoleLoggingIntegration({ levels: ["log", "error", "warn"] }),
],
});
```

## Logger Examples

```javascript
import * as Sentry from "@sentry/react";

const { logger } = Sentry;

logger.trace("Starting database connection", { database: "users" });
logger.debug("Cache miss for user", { userId: 123 });
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,
});
```
````
</Expandable>
144 changes: 144 additions & 0 deletions platform-includes/llm-rules-platform/_default.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
<Expandable title="AI Rules for Cursor or Windsurf" copy={true}>

Sentry provides a set of rules you can use to help your LLM use Sentry correctly. Copy this file and add it to your projects rules configuration.

````markdown {filename:rules.md}

These examples should be used as guidance when configuring Sentry functionlaity within a project.

# Error / Exception Tracking

- Use `Sentry.captureException(error)` to capture an exception and log the error in Sentry.
- Use this in try catch blocks or areas where exceptions are expected

# Logs

- Where logs are used, ensure Sentry is imported using `import * as Sentry from "@sentry/browser"`
- Reference the logger using `const { logger } = Sentry`
- Sentry initialization needs to be updated to include the `logger` integration.
- Sentry offers a `consoleLoggingIntegration` that can be used to log specific console error types automatically without instrumenting the individual logger calls

## Configuration

### Baseline

```javascript
import * as Sentry from "@sentry/browser";

Sentry.init({
dsn: "https://[email protected]/0",

_experiments: {
enableLogs: true,
},

});
```

### Logger Integration

```javascript
Sentry.init({
dsn: "https://[email protected]/0",
integrations: [
// send console.log, console.error, and console.warn calls as logs to Sentry
Sentry.consoleLoggingIntegration({ levels: ["log", "error", "warn"] }),
],
});
```

## Logger Examples

```javascript
import * as Sentry from "@sentry/browser";

const { logger } = Sentry;

logger.trace("Starting database connection", { database: "users" });
logger.debug("Cache miss for user", { userId: 123 });
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,
});
```

# Tracing Examples

- Spans should be created for meaningful actions within an applications like button clicks, API calls, and function calls
- Use the `Sentry.startSpan` function to create a span
- Child spans can exist within a parent span

## Custom Span instrumentation in component actions

- Name custom spans with meaningful names and operations.
- Attach attributes based on relevant information and metrics from the request

```javascript
function TestComponent() {
const handleTestButtonClick = () => {
// Create a transaction/span to measure performance
Sentry.startSpan({
op: "ui.click",
name: "Test Button Click"
}, async (span) => {

const value = "some config"
const metric = "some metric"

// Metrics can be added to the span
span.setAttribute("config", value)
span.setAttribute("metric", metric)

doSomething();
});
};

return (
<button
type="button"
onClick={handleTestButtonClick}
>
Test Sentry
</button>
);
}
```

## Custom span instrumentation in API calls

- Name custom spans with meaningful names and operations.
- Attach attributes based on relevant information and metrics from the request

```javascript
async function fetchUserData(userId) {
return Sentry.startSpan(
{
op: "http.client",
name: `GET /api/users/${userId}`,
},
async () => {
try {
const response = await fetch(`/api/users/${userId}`);
const data = await response.json();
return data;
} catch (error) {
// Capture error with the current span
Sentry.captureException(error);
throw error;
}
}
);
}
```
````

</Expandable>
Loading
Loading