diff --git a/endpoints/cookie_sync.go b/endpoints/cookie_sync.go index e07c88405a3..4facf172ea5 100644 --- a/endpoints/cookie_sync.go +++ b/endpoints/cookie_sync.go @@ -429,16 +429,20 @@ func (c *cookieSyncEndpoint) handleResponse(w http.ResponseWriter, tf usersync.S if debug { biddersSeen := make(map[string]struct{}) - var debugMessages []string + var debugInfo []cookieSyncResponseDebug for _, bidderEval := range biddersEvaluated { + var debug cookieSyncResponseDebug + debug.Bidder = bidderEval.Bidder if bidderEval.Status == usersync.StatusDuplicate && biddersSeen[bidderEval.Bidder] == struct{}{} { - debugMessages = append(debugMessages, getDebugMessage(bidderEval.Status)+" synced as "+bidderEval.SyncerKey) + debug.Error = getDebugMessage(bidderEval.Status) + " synced as " + bidderEval.SyncerKey + debugInfo = append(debugInfo, debug) } else if bidderEval.Status != usersync.StatusOK { - debugMessages = append(debugMessages, getDebugMessage(bidderEval.Status)+": "+bidderEval.Bidder) + debug.Error = getDebugMessage(bidderEval.Status) + debugInfo = append(debugInfo, debug) } biddersSeen[bidderEval.Bidder] = struct{}{} } - response.Debug = debugMessages + response.Debug = debugInfo } c.pbsAnalytics.LogCookieSyncObject(&analytics.CookieSyncObject{ @@ -515,7 +519,7 @@ type cookieSyncRequestFilter struct { type cookieSyncResponse struct { Status string `json:"status"` BidderStatus []cookieSyncResponseBidder `json:"bidder_status"` - Debug []string `json:"debug"` + Debug []cookieSyncResponseDebug `json:"debug"` } type cookieSyncResponseBidder struct { @@ -530,6 +534,11 @@ type cookieSyncResponseSync struct { SupportCORS bool `json:"supportCORS,omitempty"` } +type cookieSyncResponseDebug struct { + Bidder string `json:"bidder"` + Error string `json:"error,omitempty"` +} + type usersyncPrivacyConfig struct { gdprConfig config.GDPR gdprPermissionsBuilder gdpr.PermissionsBuilder diff --git a/endpoints/cookie_sync_test.go b/endpoints/cookie_sync_test.go index 554737b4edf..102ec34fa2b 100644 --- a/endpoints/cookie_sync_test.go +++ b/endpoints/cookie_sync_test.go @@ -262,7 +262,7 @@ func TestCookieSyncHandle(t *testing.T) { expectedStatusCode: 200, expectedBody: `{"status":"ok","bidder_status":[` + `{"bidder":"a","no_cookie":true,"usersync":{"url":"aURL","type":"redirect","supportCORS":true}}` + - `],"debug":["Already in sync: a"]}` + "\n", + `],"debug":[{"bidder":"a","error":"Already in sync"}]}` + "\n", setMetricsExpectations: func(m *metrics.MetricsEngineMock) { m.On("RecordCookieSync", metrics.CookieSyncOK).Once() m.On("RecordSyncerRequest", "aSyncer", metrics.SyncerCookieSyncAlreadySynced).Once() @@ -1711,7 +1711,7 @@ func TestCookieSyncHandleResponse(t *testing.T) { givenCookieHasSyncs: true, givenDebug: true, givenSyncersChosen: []usersync.SyncerChoice{}, - expectedJSON: `{"status":"ok","bidder_status":[],"debug":["Already in sync: Bidder1","Unsupported bidder: Bidder2","No sync config: Bidder3","Rejected by privacy: Bidder4","Type not supported: Bidder5","Status blocked by user opt out: Bidder6","Duplicate bidder synced as syncerB"]}` + "\n", + expectedJSON: `{"status":"ok","bidder_status":[],"debug":[{"bidder":"Bidder1","error":"Already in sync"},{"bidder":"Bidder2","error":"Unsupported bidder"},{"bidder":"Bidder3","error":"No sync config"},{"bidder":"Bidder4","error":"Rejected by privacy"},{"bidder":"Bidder5","error":"Type not supported"},{"bidder":"Bidder6","error":"Status blocked by user opt out"},{"bidder":"BidderA","error":"Duplicate bidder synced as syncerB"}]}` + "\n", expectedAnalytics: analytics.CookieSyncObject{Status: 200, BidderStatus: []*analytics.CookieSyncBidder{}}, }, }