improved logging for debug
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -33,7 +34,10 @@ func NewOpenFIGI(c *http.Client, apiKey string) *OpenFIGI {
|
||||
// Rate limits as per https://www.openfigi.com/api/documentation#rate-limits
|
||||
limiter := rate.NewLimiter(rate.Every(time.Minute), 25)
|
||||
if len(apiKey) > 0 {
|
||||
slog.Debug("OpenFIGI client: created with API Key rate limits")
|
||||
limiter = rate.NewLimiter(rate.Every(time.Second*6), 25)
|
||||
} else {
|
||||
slog.Debug("OpenFIGI client: created with puplic rate limits")
|
||||
}
|
||||
|
||||
return &OpenFIGI{
|
||||
@@ -48,10 +52,16 @@ func (of *OpenFIGI) SecurityTypeByISIN(ctx context.Context, isin string) (string
|
||||
of.mu.RLock()
|
||||
if secType, ok := of.securityTypeCache[isin]; ok {
|
||||
of.mu.RUnlock()
|
||||
slog.Debug("OpenFIGI client: SecurityTypeByISIN cache hit",
|
||||
slog.String("isin", isin),
|
||||
slog.String("security_type", secType))
|
||||
return secType, nil
|
||||
}
|
||||
of.mu.RUnlock()
|
||||
|
||||
slog.Debug("OpenFIGI client: SecurityTypeByISIN cache miss",
|
||||
slog.String("isin", isin))
|
||||
|
||||
of.mu.Lock()
|
||||
defer of.mu.Unlock()
|
||||
|
||||
@@ -85,6 +95,10 @@ func (of *OpenFIGI) SecurityTypeByISIN(ctx context.Context, isin string) (string
|
||||
req.Header.Add(OpenFIGIAPIKeyHeader, of.apiKey)
|
||||
}
|
||||
|
||||
if !of.mappingLimiter.Allow() {
|
||||
slog.Debug("OpenFIGI client: mapping limiter waiting for rate limiter capacity")
|
||||
}
|
||||
|
||||
err = of.mappingLimiter.Wait(ctx)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("wait for mapping request capacity: %w", err)
|
||||
@@ -123,6 +137,10 @@ func (of *OpenFIGI) SecurityTypeByISIN(ctx context.Context, isin string) (string
|
||||
|
||||
of.securityTypeCache[isin] = secType
|
||||
|
||||
slog.Debug("OpenFIGI client: SecurityTypeByISIN cached mapping",
|
||||
slog.String("isin", isin),
|
||||
slog.String("security_type", secType))
|
||||
|
||||
return secType, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user