-
-
Notifications
You must be signed in to change notification settings - Fork 75
feat: Add option to NextJS for creating sentry rules LLM file #997
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
codyde
wants to merge
17
commits into
master
Choose a base branch
from
add-sentryrules-llm-option
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 9 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
5f48d14
Adding step to NextJS wizard for Senty Rules
codyde 6fa06d9
Correcting rules template
codyde b11fd70
running yarn prettier fix
codyde 433e3bc
Adding failure state to copy and paste content
codyde 6cc176f
Adding e2e tests for nextjs
codyde 5ea8d07
Reran linting fixes
codyde fd8e178
Update e2e-tests/tests/nextjs-14.test.ts
codyde 63426ee
Update src/nextjs/templates.ts
codyde 5677867
Update src/nextjs/templates.ts
codyde 5e11cc3
Update src/nextjs/templates.ts
codyde d591f08
Update src/nextjs/nextjs-wizard.ts
codyde 82e1f7b
Merge branch 'master' into add-sentryrules-llm-option
codyde c188318
Fixing issue in nextjs 14 tests for sentryrules
codyde 6fa044c
Prettier on nextjs
codyde db6c39d
Fixing test run
codyde a750f7d
feat: Complete AI rules implementation with IDE-specific support
codyde 1eed0ea
Updating cursor configuraiton file location
codyde File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -711,3 +711,139 @@ | |
) | ||
} | ||
`; | ||
|
||
export function getAiRulesFileContent(): string { | ||
return `These examples should be used as guidance when configuring Sentry functionality within a project. | ||
# Exception Catching | ||
- 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 | ||
Lms24 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
# Tracing Examples | ||
- Spans should be created for meaningful actions within an applications like button clicks, API calls, and function calls | ||
- Ensure you are creating custom spans with meaningful names and operations | ||
codyde marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
- Span names should be parameterized. For example, when get a user by an id, name the span \`fetch /users/:id\` instead of \`fetch /users/1234\` | ||
- Use the \`Sentry.startSpan\` function to create a span | ||
- Child spans can exist within a parent span | ||
## Custom Span instrumentation in component actions | ||
- The \`name\` and \`op\` properties should be meaninful for the activities in the call. | ||
- Attach attribute 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" | ||
}, (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 | ||
codyde marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
- The \`name\` and \`op\` properties should be meaninful for the activities in the call. | ||
- Attach attributes based on relevant information and metrics from the request | ||
\`\`\`javascript | ||
async function fetchUserData(userId) { | ||
return Sentry.startSpan( | ||
{ | ||
name: \'fetch /api/users/:userId', | ||
codyde marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
}, | ||
async () => { | ||
try { | ||
const response = await fetch(\`/api/users/\${userId}\`); | ||
const data = await response.json(); | ||
return data; | ||
} | ||
); | ||
} | ||
\`\`\` | ||
# Logs | ||
- Where logs are used, ensure Sentry is imported using \`import * as Sentry from "@sentry/nextjs"\`. | ||
- Enable logging in Sentry using \`Sentry.init({ _experiments: { 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 | ||
- In NextJS the client side Sentry initialization is in \`instrumentation-client.ts\`, the server initialization is in \`sentry.edge.config.ts\` and the edge initialization is in \`sentry.server.config.ts\` | ||
- Initialization does not need to be repeated in other files, it only needs to happen the files mentioned above. You should use \`import * as Sentry from "@sentry/nextjs"\` to reference Sentry functionality | ||
### 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 | ||
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, | ||
}); | ||
\`\`\` | ||
`; | ||
} | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.