Skip to content
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

chore: Added the sentry to trace issues #3368

Merged
merged 1 commit into from
Dec 17, 2024
Merged

Conversation

devendrafyle
Copy link
Contributor

@devendrafyle devendrafyle commented Dec 17, 2024

Clickup

https://app.clickup.com/

Summary by CodeRabbit

  • New Features
    • Enhanced error handling for report submission and camera preview processes, including integration with Sentry for improved error tracking.
  • Bug Fixes
    • Improved robustness of error handling during report submissions and camera preview starts, capturing detailed contextual information for better diagnostics.

Copy link

coderabbitai bot commented Dec 17, 2024

Walkthrough

Whistle Listen up, coding universe! 💥 We've just supercharged our error handling like a true superstar! Two components - my-view-report and camera-preview - are now wielding the mighty Sentry for capturing those sneaky errors. We've transformed simple subscriptions into powerful error-tracking mechanisms that log every tiny detail, making our application as invincible as a Rajinikanth blockbuster!

Changes

File Change Summary
src/app/fyle/.../my-view-report.page.ts - Added Sentry import
- Enhanced submitReport method with structured error handling
src/app/shared/.../camera-preview.component.ts - Added Sentry import
- Improved startCameraPreview with detailed error logging

Sequence Diagram

sequenceDiagram
    participant User
    participant Component
    participant CameraService
    participant Sentry
    
    User->>Component: Trigger Action
    Component->>CameraService: Start Preview
    alt Preview Successful
        CameraService-->>Component: Success
    else Preview Fails
        CameraService-->>Component: Error
        Component->>Sentry: Log Detailed Error
        Sentry-->>Component: Acknowledgement
    end
Loading

Poem

🚀 In the realm of code, where errors hide,
Sentry stands guard, error's wild ride!
Logs dancing like a stylish fight,
Tracking bugs with all its might!
Rajini-style debugging, oh so bright! 💥

Drops mic 🎤

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added the size/M Medium PR label Dec 17, 2024
@devendrafyle devendrafyle requested review from bistaastha and Chethan-Fyle and removed request for arjunaj5 and Chethan-Fyle December 17, 2024 10:31
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🔭 Outside diff range comments (1)
src/app/shared/components/capture-receipt/camera-preview/camera-preview.component.ts (1)

Line range hint 85-113: Style-ah style-ah! Let's make this error handling even more powerful!

The error tracking is good, but we can make it better by structuring the error context more carefully.

Consider this enhancement:

 error: (error) => {
   Sentry.captureException(error, {
     extra: {
-      errorResponse: error,
+      errorType: error.name,
+      errorMessage: error.message,
       currentCameraState,
       cameraState: this.cameraState,
       navigationState: window.location.href,
       options: cameraPreviewOptions,
       platform: this.devicePlatform,
+      deviceCapabilities: {
+        hasCamera: 'mediaDevices' in navigator,
+        hasFlash: 'ImageCapture' in window
+      },
       timestamp: new Date().toISOString(),
     },
   });
 },
📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 160753f and 8ce86fa.

📒 Files selected for processing (2)
  • src/app/fyle/my-view-report/my-view-report.page.ts (2 hunks)
  • src/app/shared/components/capture-receipt/camera-preview/camera-preview.component.ts (3 hunks)
🔇 Additional comments (1)
src/app/shared/components/capture-receipt/camera-preview/camera-preview.component.ts (1)

8-8: Mind it! The Sentry import looks perfect!

The import statement is properly placed and follows Angular conventions.

@@ -37,6 +37,7 @@ import { ReportPermissions } from 'src/app/core/models/report-permissions.model'
import { ExtendedComment } from 'src/app/core/models/platform/v1/extended-comment.model';
import { Comment } from 'src/app/core/models/platform/v1/comment.model';
import { ExpenseTransactionStatus } from 'src/app/core/enums/platform/v1/expense-transaction-status.enum';
import * as Sentry from '@sentry/angular';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Kabali style! Let's make error handling consistent across the app!

While the import is correct, I notice we're implementing Sentry tracking in multiple components individually.

Consider creating a centralized error handling service:

// src/app/core/services/error-tracking.service.ts
import * as Sentry from '@sentry/angular';

@Injectable({
  providedIn: 'root'
})
export class ErrorTrackingService {
  captureError(error: Error, context: Record<string, unknown>) {
    Sentry.captureException(error, {
      extra: {
        errorType: error.name,
        errorMessage: error.message,
        timestamp: new Date().toISOString(),
        ...context
      }
    });
  }
}

Comment on lines +448 to +466
this.spenderReportsService.submit(this.reportId).subscribe({
next: () => {
this.router.navigate(['/', 'enterprise', 'my_reports']);
const message = `Report submitted successfully.`;
this.matSnackBar.openFromComponent(ToastMessageComponent, {
...this.snackbarProperties.setSnackbarProperties('success', { message }),
panelClass: ['msb-success-with-camera-icon'],
});
this.trackingService.showToastMessage({ ToastContent: message });
},
error: (error) => {
// Capture error with additional details in Sentry
Sentry.captureException(error, {
extra: {
reportId: this.reportId,
errorResponse: error,
},
});
},
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Mind it! The error handling needs more punch!

The Sentry integration is good, but we can make it more robust and user-friendly.

Consider these improvements:

 submitReport(): void {
   this.spenderReportsService.submit(this.reportId).subscribe({
     next: () => {
       this.router.navigate(['/', 'enterprise', 'my_reports']);
       const message = `Report submitted successfully.`;
       this.matSnackBar.openFromComponent(ToastMessageComponent, {
         ...this.snackbarProperties.setSnackbarProperties('success', { message }),
         panelClass: ['msb-success-with-camera-icon'],
       });
       this.trackingService.showToastMessage({ ToastContent: message });
     },
     error: (error) => {
+      const errorMessage = 'Failed to submit report. Please try again.';
+      this.matSnackBar.openFromComponent(ToastMessageComponent, {
+        ...this.snackbarProperties.setSnackbarProperties('error', { message: errorMessage }),
+        panelClass: ['msb-error'],
+      });
       Sentry.captureException(error, {
         extra: {
           reportId: this.reportId,
-          errorResponse: error,
+          errorType: error.name,
+          errorMessage: error.message,
+          userId: this.eou?.us?.id,
+          timestamp: new Date().toISOString()
         },
       });
+      // Retry submission after a delay if it's a network error
+      if (error.name === 'NetworkError') {
+        setTimeout(() => this.submitReport(), 5000);
+      }
     },
   });
 }

Committable suggestion skipped: line range outside the PR's diff.

Copy link

Unit Test Coverage % values
Statements 95.99% ( 19243 / 20046 )
Branches 91.11% ( 10654 / 11693 )
Functions 94.31% ( 5741 / 6087 )
Lines 96.03% ( 18374 / 19133 )

@devendrafyle devendrafyle merged commit e0573c6 into master Dec 17, 2024
10 checks passed
Copy link

sentry-io bot commented Dec 20, 2024

Suspect Issues

This pull request was deployed and Sentry observed the following issues:

  • ‼️ .error `` View Issue

    Did you find this useful? React with a 👍 or 👎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/M Medium PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants