System Logs
Relevant source files
The following files were used as context for generating this wiki page:
System Logs record every interaction between the Resend Go SDK and the Resend API. The logging system allows developers to monitor request methods, targeted endpoints, and response statuses to facilitate debugging and audit trails.
The logging module provides structured data for each API call, capturing metadata such as timestamps and user agents alongside optional request and response bodies. Developers use this feature to track the lifecycle of resources, such as verifying when an email was sent or checking the status of domain verification requests.
Sources: logs.go:1-7, examples/logs.go:17-26
Data Architecture
The logging system centers around the Log data structure. This structure represents a single atomic event in the API interaction history.
The Log Entity
The Log struct defines the schema for all logged events. It includes unique identifiers and specific network metadata.
| Field | Type | Description |
|---|---|---|
Id | string | The unique identifier for the log entry. |
Object | string | The type of object (typically "log"). |
CreatedAt | string | ISO 8601 timestamp of when the event occurred. |
Method | string | The HTTP method used (e.g., POST, GET). |
Endpoint | string | The API path targeted by the request. |
ResponseStatus | int | The HTTP status code returned by the server. |
UserAgent | *string | The client string identifying the SDK version. |
RequestBody | any | The raw JSON sent in the request (optional). |
ResponseBody | any | The raw JSON received in the response (optional). |
Sources: logs.go:9-19, logs_test.go:19-30
Structure Relationships
The following class diagram illustrates the relationship between individual log entries and the paginated response structure used when listing multiple logs.
The diagram shows that a ListLogsResponse contains a slice of Log objects and a boolean flag indicating if additional records exist.
Sources: logs.go:9-25
Service Operations
The LogsSvc interface defines the operations available for interacting with system logs. The implementation LogsSvcImpl executes these operations by performing HTTP GET requests against the /logs endpoint.
Sources: logs.go:27-37
Retrieving Single Logs
You retrieve a specific log entry by providing its unique ID. This operation is useful for deep inspection of a specific failed request or verifying the payload of a successful transaction.
The sequence diagram demonstrates the flow of a single log retrieval request from the application through the SDK to the Resend API.
Sources: logs.go:40-57, examples/logs.go:17-26
Listing and Pagination
The SDK supports listing logs with cursor-based pagination. You control the result set using ListOptions, which accepts a Limit for the number of records and an After or Before cursor for navigation.
Sources: logs.go:61-75, examples/logs.go:36-57
Pagination Flow
- Fetch the first page using a specific
Limit. - Check the
HasMoreboolean in the response. - If
HasMoreis true, extract theIdof the last item in theDataslice. - Request the next page using the extracted ID as the
Afterparameter.
Sources: examples/logs.go:44-57, examples/with_pagination.go:19-33
The flowchart describes the iterative process of navigating through paginated log data.
Sources: examples/logs.go:44-57
Implementation Details
The log service utilizes the internal client's NewRequest and Perform methods to communicate with the API. It constructs paths dynamically, such as logs/ appended with the log ID for retrieval or logs with a query string for listing.
Error Handling
The service returns specific errors if request creation fails, such as ErrFailedToCreateLogsGetRequest or ErrFailedToCreateLogsListRequest.
Sources: logs.go:44-46, logs.go:65-67
Code Example: Log Retrieval
// Retrieve a single log entry
log, err := client.Logs.GetWithContext(ctx, "log_123abc")
if err != nil {
panic(err)
}
fmt.Printf("Endpoint: %s %s\n", log.Method, log.Endpoint)
fmt.Printf("Response status: %d\n", log.ResponseStatus)
Sources: examples/logs.go:17-26
Summary
System Logs in the Resend Go SDK provide a comprehensive interface for auditing API activity. By implementing the LogsSvc, the SDK enables developers to retrieve detailed metadata for individual requests and navigate large histories through structured pagination. This system ensures transparency in how the SDK interacts with the remote Resend environment.
Sources: logs.go:27-33, examples/logs.go:9-15