From 712d8f9fcc998f5daa406d574d45e16abc977f89 Mon Sep 17 00:00:00 2001 From: Deluan Date: Tue, 31 Jan 2023 09:37:09 -0500 Subject: [PATCH] Add trace logs to calls to external services --- core/agents/lastfm/client.go | 1 + core/agents/listenbrainz/client.go | 1 + core/agents/spotify/client.go | 1 + log/log.go | 3 +++ 4 files changed, 6 insertions(+) diff --git a/core/agents/lastfm/client.go b/core/agents/lastfm/client.go index d8b76d3c..a993ddc5 100644 --- a/core/agents/lastfm/client.go +++ b/core/agents/lastfm/client.go @@ -191,6 +191,7 @@ func (c *client) makeRequest(ctx context.Context, method string, params url.Valu req, _ := http.NewRequestWithContext(ctx, method, apiBaseUrl, nil) req.URL.RawQuery = params.Encode() + log.Trace(ctx, fmt.Sprintf("Sending Last.fm %s request", req.Method), "url", req.URL) resp, err := c.hc.Do(req) if err != nil { return nil, err diff --git a/core/agents/listenbrainz/client.go b/core/agents/listenbrainz/client.go index 3e48462f..8ed4d169 100644 --- a/core/agents/listenbrainz/client.go +++ b/core/agents/listenbrainz/client.go @@ -151,6 +151,7 @@ func (c *client) makeRequest(ctx context.Context, method string, endpoint string req.Header.Add("Authorization", fmt.Sprintf("Token %s", r.ApiKey)) } + log.Trace(ctx, fmt.Sprintf("Sending ListenBrainz %s request", req.Method), "url", req.URL) resp, err := c.hc.Do(req) if err != nil { return nil, err diff --git a/core/agents/spotify/client.go b/core/agents/spotify/client.go index 0ac310f6..25b1f9ed 100644 --- a/core/agents/spotify/client.go +++ b/core/agents/spotify/client.go @@ -87,6 +87,7 @@ func (c *client) authorize(ctx context.Context) (string, error) { } func (c *client) makeRequest(req *http.Request, response interface{}) error { + log.Trace(req.Context(), fmt.Sprintf("Sending Spotify %s request", req.Method), "url", req.URL) resp, err := c.hc.Do(req) if err != nil { return err diff --git a/log/log.go b/log/log.go index a0a9fd3c..d20fa8e3 100644 --- a/log/log.go +++ b/log/log.go @@ -37,6 +37,9 @@ var redacted = &Hook{ "([^\\w]s=)[^&]+", "([^\\w]p=)[^&]+", "([^\\w]jwt=)[^&]+", + + // External services query params + "([^\\w]api_key=)[\\w]+", }, }