refactor: migrate jikan relations logs to observability
This commit is contained in:
@@ -4,11 +4,12 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"mal/internal/observability"
|
||||||
|
|
||||||
"mal/integrations/watchorder"
|
"mal/integrations/watchorder"
|
||||||
|
|
||||||
"golang.org/x/sync/errgroup"
|
"golang.org/x/sync/errgroup"
|
||||||
@@ -62,21 +63,44 @@ func (c *Client) getWatchOrder(ctx context.Context, id int) (watchorder.WatchOrd
|
|||||||
return watchorder.WatchOrderResult{}, watchorder.ErrWatchOrderNotFound
|
return watchorder.WatchOrderResult{}, watchorder.ErrWatchOrderNotFound
|
||||||
}
|
}
|
||||||
if errors.Is(err, watchorder.ErrWatchOrderMarkupNotFound) {
|
if errors.Is(err, watchorder.ErrWatchOrderMarkupNotFound) {
|
||||||
log.Printf("relations: watch-order markup missing for %d (%s): %v", id, watchOrderURL, err)
|
observability.Warn(
|
||||||
|
"relations_watch_order_markup_missing",
|
||||||
|
"jikan",
|
||||||
|
"",
|
||||||
|
map[string]any{
|
||||||
|
"anime_id": id,
|
||||||
|
"url": watchOrderURL,
|
||||||
|
},
|
||||||
|
err,
|
||||||
|
)
|
||||||
} else if errors.As(err, &statusError) {
|
} else if errors.As(err, &statusError) {
|
||||||
log.Printf(
|
observability.Warn(
|
||||||
"relations: watch-order http error for %d (%s): status=%d server=%q cf_ray=%q location=%q content_type=%q body=%q",
|
"relations_watch_order_http_error",
|
||||||
id,
|
"jikan",
|
||||||
watchOrderURL,
|
"",
|
||||||
statusError.StatusCode,
|
map[string]any{
|
||||||
statusError.Server,
|
"anime_id": id,
|
||||||
statusError.CFRay,
|
"url": watchOrderURL,
|
||||||
statusError.Location,
|
"status": statusError.StatusCode,
|
||||||
statusError.ContentType,
|
"server": statusError.Server,
|
||||||
statusError.BodyPreview,
|
"cf_ray": statusError.CFRay,
|
||||||
|
"location": statusError.Location,
|
||||||
|
"content_type": statusError.ContentType,
|
||||||
|
"body_preview": statusError.BodyPreview,
|
||||||
|
},
|
||||||
|
err,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
log.Printf("relations: watch-order fetch failed for %d (%s): %v", id, watchOrderURL, err)
|
observability.Warn(
|
||||||
|
"relations_watch_order_fetch_failed",
|
||||||
|
"jikan",
|
||||||
|
"",
|
||||||
|
map[string]any{
|
||||||
|
"anime_id": id,
|
||||||
|
"url": watchOrderURL,
|
||||||
|
},
|
||||||
|
err,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
return watchorder.WatchOrderResult{}, err
|
return watchorder.WatchOrderResult{}, err
|
||||||
}
|
}
|
||||||
@@ -107,7 +131,15 @@ func (c *Client) GetFullRelations(ctx context.Context, id int) ([]RelationEntry,
|
|||||||
if errors.Is(err, watchorder.ErrWatchOrderNotFound) {
|
if errors.Is(err, watchorder.ErrWatchOrderNotFound) {
|
||||||
return c.currentOnlyRelation(ctx, id)
|
return c.currentOnlyRelation(ctx, id)
|
||||||
}
|
}
|
||||||
log.Printf("relations: using current-only fallback for %d: %v", id, err)
|
observability.Warn(
|
||||||
|
"relations_watch_order_fallback_current_only",
|
||||||
|
"jikan",
|
||||||
|
"",
|
||||||
|
map[string]any{
|
||||||
|
"anime_id": id,
|
||||||
|
},
|
||||||
|
err,
|
||||||
|
)
|
||||||
return c.currentOnlyRelation(ctx, id)
|
return c.currentOnlyRelation(ctx, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user