@@ -13,7 +13,10 @@ import type {
1313 DocsParams ,
1414 OnboardingConfig ,
1515} from 'sentry/components/onboarding/gettingStartedDoc/types' ;
16- import { getUploadSourceMapsStep } from 'sentry/components/onboarding/gettingStartedDoc/utils' ;
16+ import {
17+ getAIRulesForCodeEditorStep ,
18+ getUploadSourceMapsStep ,
19+ } from 'sentry/components/onboarding/gettingStartedDoc/utils' ;
1720import {
1821 getCrashReportJavaScriptInstallStep ,
1922 getCrashReportModalConfigDescription ,
@@ -324,6 +327,141 @@ const getVerifyConfig = () => [
324327 } ,
325328] ;
326329
330+ const getAiRulesConfig = ( params : Params ) =>
331+ getAIRulesForCodeEditorStep ( {
332+ rules : `
333+ These examples should be used as guidance when configuring Sentry functionality within a project.
334+
335+ # Error / Exception Tracking
336+
337+ Use \`Sentry.captureException(error)\` to capture an exception and log the error in Sentry.
338+ Use this in try catch blocks or areas where exceptions are expected
339+
340+ # Tracing Examples
341+
342+ Spans should be created for meaningful actions within an applications like button clicks, API calls, and function calls
343+ Use the \`Sentry.startSpan\` function to create a span
344+ Child spans can exist within a parent span
345+
346+ ## Custom Span instrumentation in component actions
347+
348+ Name custom spans with meaningful names and operations.
349+ Attach attributes based on relevant information and metrics from the request
350+
351+ \`\`\`javascript
352+ function TestComponent() {
353+ const handleTestButtonClick = () => {
354+ // Create a transaction/span to measure performance
355+ Sentry.startSpan(
356+ {
357+ op: "ui.click",
358+ name: "Test Button Click",
359+ },
360+ (span) => {
361+ const value = "some config";
362+ const metric = "some metric";
363+
364+ // Metrics can be added to the span
365+ span.setAttribute("config", value);
366+ span.setAttribute("metric", metric);
367+
368+ doSomething();
369+ },
370+ );
371+ };
372+
373+ return (
374+ <button type="button" onClick={handleTestButtonClick}>
375+ Test Sentry
376+ </button>
377+ );
378+ }
379+ \`\`\`
380+
381+ ## Custom span instrumentation in API calls
382+
383+ Name custom spans with meaningful names and operations.
384+ Attach attributes based on relevant information and metrics from the request
385+
386+ \`\`\`javascript
387+ async function fetchUserData(userId) {
388+ return Sentry.startSpan(
389+ {
390+ op: "http.client",
391+ name: \`GET /api/users/\${userId}\`,
392+ },
393+ async () => {
394+ const response = await fetch(\`/api/users/\${userId}\`);
395+ const data = await response.json();
396+ return data;
397+ },
398+ );
399+ }
400+ \`\`\`
401+
402+ # Logs
403+
404+ Where logs are used, ensure Sentry is imported using \`import * as Sentry from "@sentry/browser"\`
405+ Enable logging in Sentry using \`Sentry.init({ _experiments: { enableLogs: true } })\`
406+ Reference the logger using \`const { logger } = Sentry\`
407+ Sentry offers a \`consoleLoggingIntegration\` that can be used to log specific console error types automatically without instrumenting the individual logger calls
408+
409+ ## Configuration
410+
411+ ### Baseline
412+
413+ \`\`\`javascript
414+ import * as Sentry from "@sentry/browser";
415+
416+ Sentry.init({
417+ dsn: "${ params . dsn . public } ",
418+
419+ _experiments: {
420+ enableLogs: true,
421+ },
422+ });
423+ \`\`\`
424+
425+ ### Logger Integration
426+
427+ \`\`\`javascript
428+ Sentry.init({
429+ dsn: "${ params . dsn . public } ",
430+ integrations: [
431+ // send console.log, console.error, and console.warn calls as logs to Sentry
432+ Sentry.consoleLoggingIntegration({ levels: ["log", "error", "warn"] }),
433+ ],
434+ });
435+ \`\`\`
436+
437+ ## Logger Examples
438+
439+ \`logger.fmt\` is a template literal function that should be used to bring variables into the structured logs.
440+
441+ \`\`\`javascript
442+ import * as Sentry from "@sentry/browser";
443+
444+ const { logger } = Sentry;
445+
446+ logger.trace("Starting database connection", { database: "users" });
447+ logger.debug(logger.fmt\`Cache miss for user: \${userId}\`);
448+ logger.info("Updated profile", { profileId: 345 });
449+ logger.warn("Rate limit reached for endpoint", {
450+ endpoint: "/api/results/",
451+ isEnterprise: false,
452+ });
453+ logger.error("Failed to process payment", {
454+ orderId: "order_123",
455+ amount: 99.99,
456+ });
457+ logger.fatal("Database connection pool exhausted", {
458+ database: "users",
459+ activeConnections: 100,
460+ });
461+ \`\`\`
462+ ` ,
463+ } ) ;
464+
327465const loaderScriptOnboarding : OnboardingConfig < PlatformOptions > = {
328466 introduction : ( ) =>
329467 tct ( "In this quick guide you'll use our [strong: Loader Script] to set up:" , {
@@ -406,6 +544,7 @@ const loaderScriptOnboarding: OnboardingConfig<PlatformOptions> = {
406544 }
407545 } ,
408546 } ,
547+ getAiRulesConfig ( params ) ,
409548 ] ,
410549 verify : getVerifyConfig ,
411550 nextSteps : ( ) => [
@@ -501,6 +640,7 @@ const packageManagerOnboarding: OnboardingConfig<PlatformOptions> = {
501640 guideLink : 'https://docs.sentry.io/platforms/javascript/sourcemaps/' ,
502641 ...params ,
503642 } ) ,
643+ getAiRulesConfig ( params ) ,
504644 ] ,
505645 verify : getVerifyConfig ,
506646 nextSteps : ( ) => [ ] ,
0 commit comments