Skip to content

Commit

Permalink
Prebid Server Bid Adapter: Expose errors and server response times al…
Browse files Browse the repository at this point in the history
…ways (prebid#5866)

* Expose pbs reported errors
Expose serverLatencyMillis always

* clean up logic for other weird edge case

* review comment for make function

* not sure how parenthesis got there
  • Loading branch information
robertrmartinez authored and stsepelin committed May 28, 2021
1 parent 01d78eb commit 4a98d01
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
17 changes: 17 additions & 0 deletions modules/prebidServerBidAdapter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,18 @@ function addWurl(auctionId, adId, wurl) {
}
}

function getPbsResponseData(bidderRequests, response, pbsName, pbjsName) {
const bidderValues = utils.deepAccess(response, `ext.${pbsName}`);
if (bidderValues) {
Object.keys(bidderValues).forEach(bidder => {
let biddersReq = find(bidderRequests, bidderReq => bidderReq.bidderCode === bidder);
if (biddersReq) {
biddersReq[pbjsName] = bidderValues[bidder];
}
});
}
}

/**
* @param {string} auctionId
* @param {string} adId generated value set to bidObject.adId by bidderFactory Bid()
Expand Down Expand Up @@ -676,6 +688,9 @@ const OPEN_RTB_PROTOCOL = {
interpretResponse(response, bidderRequests) {
const bids = [];

[['errors', 'serverErrors'], ['responsetimemillis', 'serverResponseTimeMs']]
.forEach(info => getPbsResponseData(bidderRequests, response, info[0], info[1]))

if (response.seatbid) {
// a seatbid object contains a `bid` array and a `seat` string
response.seatbid.forEach(seatbid => {
Expand All @@ -698,6 +713,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 @@ -631,10 +639,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 @@ -675,10 +695,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 @@ -310,6 +310,7 @@ const MOCK = {
],
BIDDER_DONE: {
'bidderCode': 'rubicon',
'serverResponseTimeMs': 42,
'bids': [
BID,
Object.assign({}, BID2, {
Expand Down

0 comments on commit 4a98d01

Please sign in to comment.