Skip to content

Commit

Permalink
Re-work debug structure in response
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexBVolcy committed Oct 3, 2023
1 parent 5ffbc7a commit e725769
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
19 changes: 14 additions & 5 deletions endpoints/cookie_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions endpoints/cookie_sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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{}},
},
}
Expand Down

0 comments on commit e725769

Please sign in to comment.