Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prebid Server Bid Adapter: Expose errors and server response times always #5866

Merged
merged 5 commits into from
Nov 17, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions modules/prebidServerBidAdapter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,27 @@ const OPEN_RTB_PROTOCOL = {
interpretResponse(response, bidderRequests) {
const bids = [];

// Should log all bidders server response times, not only if they had successful seatBid
const serverResponseTimeMs = utils.deepAccess(response, 'ext.responsetimemillis');
msm0504 marked this conversation as resolved.
Show resolved Hide resolved
if (serverResponseTimeMs) {
Object.keys(serverResponseTimeMs).forEach(bidder => {
let biddersReq = find(bidderRequests, bidderReq => bidderReq.bidderCode === bidder);
if (biddersReq) {
biddersReq.serverResponseTimeMs = serverResponseTimeMs[bidder];
}
});
}

// Attach any errors to a biddersRequest object
const bidderErrors = utils.deepAccess(response, 'ext.errors');
if (bidderErrors) {
Object.keys(bidderErrors).forEach(bidder => {
let biddersReq = find(bidderRequests, bidderReq => bidderReq.bidderCode === bidder);
if (biddersReq) {
biddersReq.serverErrors = bidderErrors[bidder];
}
});
}
if (response.seatbid) {
// a seatbid object contains a `bid` array and a `seat` string
response.seatbid.forEach(seatbid => {
Expand All @@ -698,6 +719,8 @@ const OPEN_RTB_PROTOCOL = {

bidObject.cpm = cpm;

// temporarily leaving attaching it to each bidResponse so no breaking change
// BUT: this is a flat map, so it should be only attached to bidderRequest, a the change above does
let serverResponseTimeMs = utils.deepAccess(response, ['ext', 'responsetimemillis', seatbid.seat].join('.'));
if (bidRequest && serverResponseTimeMs) {
bidRequest.serverResponseTimeMs = serverResponseTimeMs;
Expand Down
32 changes: 28 additions & 4 deletions modules/rubiconAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ const COOKIE_NAME = 'rpaSession';
const LAST_SEEN_EXPIRE_TIME = 1800000; // 30 mins
const END_EXPIRE_TIME = 21600000; // 6 hours

const pbsErrorMap = {
1: 'timeout-error',
2: 'input-error',
3: 'connect-error',
4: 'request-error',
999: 'generic-error'
}

let prebidGlobal = getGlobal();
const {
EVENTS: {
Expand Down Expand Up @@ -628,10 +636,22 @@ let rubiconAdapter = Object.assign({}, baseAdapter, {
bid.bidResponse = parseBidResponse(args, bid.bidResponse);
break;
case BIDDER_DONE:
const serverError = utils.deepAccess(args, 'serverErrors.0');
const serverResponseTimeMs = args.serverResponseTimeMs;
args.bids.forEach(bid => {
let cachedBid = cache.auctions[bid.auctionId].bids[bid.bidId || bid.requestId];
if (typeof bid.serverResponseTimeMs !== 'undefined') {
cachedBid.serverLatencyMillis = bid.serverResponseTimeMs;
} else if (serverResponseTimeMs && bid.source === 's2s') {
cachedBid.serverLatencyMillis = serverResponseTimeMs;
}
// if PBS said we had an error, and this bid has not been processed by BID_RESPONSE YET
if (serverError && (!cachedBid.status || ['no-bid', 'error'].indexOf(cachedBid.status) !== -1)) {
cachedBid.status = 'error';
cachedBid.error = {
code: pbsErrorMap[serverError.code] || pbsErrorMap[999],
description: serverError.message
}
}
if (!cachedBid.status) {
cachedBid.status = 'no-bid';
Expand Down Expand Up @@ -672,10 +692,14 @@ let rubiconAdapter = Object.assign({}, baseAdapter, {
args.forEach(badBid => {
let auctionCache = cache.auctions[badBid.auctionId];
let bid = auctionCache.bids[badBid.bidId || badBid.requestId];
bid.status = 'error';
bid.error = {
code: 'timeout-error'
};
// might be set already by bidder-done, so do not overwrite
if (bid.status !== 'error') {
bid.status = 'error';
bid.error = {
code: 'timeout-error',
message: 'marked by prebid.js as timeout' // will help us diff if timeout was set by PBS or PBJS
};
}
});
break;
}
Expand Down
1 change: 1 addition & 0 deletions test/spec/modules/rubiconAnalyticsAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ const MOCK = {
],
BIDDER_DONE: {
'bidderCode': 'rubicon',
'serverResponseTimeMs': 42,
'bids': [
BID,
Object.assign({}, BID2, {
Expand Down