Skip to content

Commit

Permalink
fix: error logging (#12656)
Browse files Browse the repository at this point in the history
Co-authored-by: rufiange <[email protected]>
  • Loading branch information
sebastienrufiange and rufiange authored Jan 15, 2025
1 parent b5f9de7 commit 8ed14d8
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions modules/contxtfulBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
interpretResponse,
getUserSyncs as getUserSyncsLib,
} from '../libraries/teqblazeUtils/bidderUtils.js';
import {ortbConverter} from '../libraries/ortbConverter/converter.js';
import { ortbConverter } from '../libraries/ortbConverter/converter.js';

// Constants
const BIDDER_CODE = 'contxtful';
Expand Down Expand Up @@ -75,7 +75,7 @@ const extractParameters = (config) => {

// Construct the Payload towards the Bidding endpoint
const buildRequests = (validBidRequests = [], bidderRequest = {}) => {
const ortb2 = converter.toORTB({bidderRequest: bidderRequest, bidRequests: validBidRequests});
const ortb2 = converter.toORTB({ bidderRequest: bidderRequest, bidRequests: validBidRequests });

const bidRequests = [];
_each(validBidRequests, bidRequest => {
Expand All @@ -88,7 +88,7 @@ const buildRequests = (validBidRequests = [], bidderRequest = {}) => {
});
const config = pbjsConfig.getConfig();
config.pbjsVersion = PREBID_VERSION;
const {version, customer} = extractParameters(config)
const { version, customer } = extractParameters(config)
const adapterUrl = buildUrl({
protocol: 'https',
host: BIDDER_ENDPOINT,
Expand Down Expand Up @@ -151,6 +151,17 @@ const getSamplingRate = (bidderConfig, eventType) => {
return entry ? entry[1] : DEFAULT_SAMPLING_RATE;
};

const logBidderError = ({ error, bidderRequest }) => {
if (error) {
let jsonReason = {
message: error.reason?.message,
stack: error.reason?.stack,
};
error.reason = jsonReason;
}
logEvent('onBidderError', { error, bidderRequest });
};

// Handles the logging of events
const logEvent = (eventType, data) => {
try {
Expand All @@ -159,7 +170,7 @@ const logEvent = (eventType, data) => {

// Get Config
const bidderConfig = pbjsConfig.getConfig();
const {version, customer} = extractParameters(bidderConfig);
const { version, customer } = extractParameters(bidderConfig);

// Sampled monitoring
if (['onBidBillable', 'onAdRenderSucceeded'].includes(eventType)) {
Expand Down Expand Up @@ -206,12 +217,12 @@ export const spec = {
buildRequests,
interpretResponse,
getUserSyncs,
onBidWon: function(bid) { logEvent('onBidWon', bid); },
onBidBillable: function(bid) { logEvent('onBidBillable', bid); },
onAdRenderSucceeded: function(bid) { logEvent('onAdRenderSucceeded', bid); },
onSetTargeting: function(bid) { },
onTimeout: function(timeoutData) { logEvent('onTimeout', timeoutData); },
onBidderError: function({ error, bidderRequest }) { logEvent('onBidderError', { error, bidderRequest }); },
onBidWon: function (bid) { logEvent('onBidWon', bid); },
onBidBillable: function (bid) { logEvent('onBidBillable', bid); },
onAdRenderSucceeded: function (bid) { logEvent('onAdRenderSucceeded', bid); },
onSetTargeting: function (bid) { },
onTimeout: function (timeoutData) { logEvent('onTimeout', timeoutData); },
onBidderError: logBidderError,
};

registerBidder(spec);

0 comments on commit 8ed14d8

Please sign in to comment.