Files
managing-apps/src/Managing.Api/README-SENTRY.md
Oda 42a4cafd8d Add Sentry (#19)
* add sentry

* add sentry

* better log web3proxy

* Add managing and worker on sentry

* better log web3proxy
2025-04-22 20:49:02 +02:00

98 lines
2.9 KiB
Markdown

# Sentry Integration for Managing API
This document describes how Sentry is integrated into the Managing API for error monitoring and performance tracking.
## Setup
Sentry has been integrated into the Managing API using the official `Sentry.AspNetCore` package (version 5.5.1). The integration follows the recommended approach using `WebHost.UseSentry()` in Program.cs:
```csharp
// In Program.cs
builder.WebHost.UseSentry();
```
This approach automatically picks up Sentry configuration from appsettings.json and environment variables. It's the official recommended method for ASP.NET Core applications.
The integration captures:
- Unhandled exceptions
- HTTP request information
- Performance metrics
- Custom errors and events
- User information and PII (when SendDefaultPii is enabled)
## Configuration
Sentry is configured through `appsettings.json`. Here are the available settings:
```json
"Sentry": {
"Dsn": "YOUR_SENTRY_DSN",
"MinimumEventLevel": "Error",
"SendDefaultPii": false,
"MaxBreadcrumbs": 50,
"SampleRate": 1.0,
"TracesSampleRate": 0.2,
"Debug": false
}
```
### Required Settings
- `Dsn`: Your Sentry project's Data Source Name (required). This should be obtained from your Sentry project settings.
### Optional Settings
- `MinimumEventLevel`: Minimum log level that triggers an event to be sent to Sentry (default: Error)
- `SampleRate`: Percentage of errors to send to Sentry (1.0 = 100%)
- `TracesSampleRate`: Percentage of transactions to send to Sentry (0.2 = 20%)
- `Debug`: Enable debug mode for Sentry SDK (set to true in Development environment)
## Environment Configuration
Each environment can have specific Sentry settings:
- Development: Uses settings from `appsettings.Development.json` (sampling rate set to 100% for easy testing)
- Production: Uses settings from `appsettings.Production.json`
## Custom Error Tracking
You can manually track errors and events using the `SentrySdk` class:
```csharp
try
{
// Your code
}
catch (Exception ex)
{
SentrySdk.CaptureException(ex);
// Additional error handling
}
```
## Testing the Integration
A test endpoint has been added to verify Sentry integration:
```
GET /test-sentry
```
This endpoint throws and captures a test exception, confirming that events are being sent to Sentry.
## Deployment Considerations
When deploying to production:
1. Update the Sentry DSN in your production configuration
2. Consider setting appropriate sampling rates based on traffic volume
3. Ensure PII (Personally Identifiable Information) handling complies with your privacy policies
## Performance Impact
The Sentry SDK has minimal performance impact with default settings. If needed, you can adjust sampling rates to reduce the number of events sent to Sentry.
## Security
Sentry DSNs should be treated as secrets and not committed directly to source control. Use environment variables or secret management for production deployments.