Metrics, Usage & Logs
Relevant source files
The following files were used as context for generating this wiki page:
The Metrics, Usage & Logs system provides telemetry, quota tracking, and request auditing for the Resend account. It enables developers to monitor email performance through aggregated metrics, track real-time account usage against plan limits, and retrieve historical API request logs.
Sources: IResend.cs:188-202, IResend.cs:1184-1212
Email Metrics
The Metrics system aggregates email delivery and engagement data for specific reporting periods. You retrieve these metrics via the EmailMetricsAsync method, which supports filtering and grouping by various dimensions such as domains or individual emails.
Metric Request Flow
The diagram below illustrates the flow of a metrics request from the client to the API.
The application provides a query object to the client, which performs a GET request to the /emails/metrics endpoint and returns a structured metrics object.
Sources: ResendClient.Usage.cs:15-30, EmailController.cs:228-250
Metric Types and Structures
Email performance is categorized into specific event types. These are represented by the MetricType enum.
| Metric Type | Description |
|---|---|
Received | Number of emails accepted for sending. |
Delivered | Number of emails reaching the recipient's server. |
Opened | Number of emails opened by recipients. |
Clicked | Number of link clicks within emails. |
Bounced | Total number of email bounces. |
Suppressed | Emails blocked instead of being sent. |
ComplaintRate | Fraction of delivered emails marked as spam. |
Sources: MetricType.cs:10-109
The metrics response structure is defined by the EmailMetrics class:
The EmailMetrics class holds the aggregate totals and a list of data points if dimensions are requested.
Sources: EmailMetrics.cs:8-47
Account Usage
The Usage system tracks the volume of emails sent within the current billing cycle against the account's plan limit. The UsageAsync method retrieves a snapshot of these values.
Usage Data Model
The Usage class defines the properties returned by the account usage endpoint.
| Field | Type | Description |
|---|---|---|
Sent | long | Total number of emails sent in the current period. |
Limit | long | Maximum number of emails allowed in the period. |
Sources: Usage.cs:8-22
The client requests account-level usage data to determine remaining quota availability.
Sources: ResendClient.Usage.cs:33-40, IResend.cs:1205-1212
API Request Logs
The Logs system provides an audit trail of API interactions. This includes both high-level lists of requests and detailed information for specific logs, including request and response bodies when available.
Logging Operations
The IResend interface provides two primary methods for interacting with logs:
- LogListAsync: Retrieves a paginated list of API request logs.
- LogRetrieveAsync: Retrieves detailed information for a single log entry using its unique identifier.
Sources: IResend.cs:1184-1200, ResendClient.Logs.cs:12-42
Log Data Relationships
Logs are retrieved as part of a paginated result set, where each entry identifies the HTTP method, path, and result status of an API call.
Sources: ResendClient.Logs.cs:15-20, IResend.cs:1193
Conclusion
The Metrics, Usage & Logs module integrates account health monitoring with granular email performance tracking. By utilizing the EmailMetrics and Usage structures, you can build dashboards that monitor delivery efficiency and ensure account operations remain within plan boundaries. Request logs further support troubleshooting by providing a historical record of API transactions.
Sources: EmailMetrics.cs:8-12, Usage.cs:8-12, ResendClient.Logs.cs:12-15