Repository navigation
Conversation
| // LogLevel represents the logging level | ||
| type LogLevel string | ||
|
|
||
| const ( |
There was a problem hiding this comment.
Use iota to have a standard ENUM in go like proto
There was a problem hiding this comment.
I'm keeping the string-based approach because it's more appropriate for a public library API. String constants provide better debugging experience (you see "DEBUG" instead of 0), are JSON-serializable, and follow the pattern used by Go's standard log/slog package. iota is great for internal enums, but for public APIs that users interact with, strings are more ergonomic and stable.
| FlushInterval time.Duration | ||
| MaxBatchSize int | ||
| MaxRetries int | ||
| Adapters struct { |
There was a problem hiding this comment.
this makes instantiation a headache, have a flat or totally new struct to own Adapters.
|
Do not use interface{} for any |
| func NewClient(config ClientConfig) *Client { | ||
| // Validate required fields | ||
| if config.APIKey == "" { | ||
| panic("apiKey must be provided in config") |
|
|
||
| if attempt < d.config.MaxRetries { | ||
| backoff := time.Duration(math.Pow(2, float64(attempt))) * time.Second | ||
| jitter := time.Duration(rand.Intn(1000)) * time.Millisecond |
There was a problem hiding this comment.
No magic numbers (make them configurable)
| } | ||
|
|
||
| if attempt < d.config.MaxRetries { | ||
| backoff := time.Duration(math.Pow(2, float64(attempt))) * time.Second |
| d.loggerAdapter.Warn("HTTP request failed with error: %v", err) | ||
| } else { | ||
| lastErr = &HTTPError{Status: resp.Status} | ||
| d.loggerAdapter.Warn("HTTP request failed with status: %d", resp.Status) |
There was a problem hiding this comment.
Since it's a negative situation, I think warning is better
| ) | ||
|
|
||
| // Queue represents a thread-safe FIFO queue for Event items. | ||
| type Queue struct { |
There was a problem hiding this comment.
I expect the queue to have a limit. You don't have all the RAMs in the world 😆
There was a problem hiding this comment.
The max batch size covers this.
| batchSize := min(d.config.MaxBatchSize, d.queue.Len()) | ||
| batch := make([]Event, 0, batchSize) | ||
| for i := 0; i < batchSize; i++ { | ||
| if event, ok := d.queue.Dequeue(); ok { |
There was a problem hiding this comment.
This looks slow, use builtIn slice instead, you can easily batch it using x[:batchSize] for example
| if !d.timerStarted { | ||
| d.ticker = time.NewTicker(d.config.FlushInterval) | ||
| d.timerStarted = true | ||
| d.wg.Add(1) |
There was a problem hiding this comment.
use 1.25 and wg.go() instead of add and go
| if config.FlushInterval == 0 { | ||
| config.FlushInterval = 5 * time.Second | ||
| } | ||
| if config.MaxBatchSize == 0 { |
No description provided.