Skip to content
This repository was archived by the owner on Dec 22, 2022. It is now read-only.

Commit bfb2124

Browse files
authored
Extra logging for timeout notifications (prebid#1349)
1 parent 8b53c33 commit bfb2124

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed

exchange/bidder.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,20 @@ func (bidder *bidderAdapter) doTimeoutNotification(timeoutBidder adapters.Timeou
389389
}
390390
} else {
391391
bidder.me.RecordTimeoutNotice(false)
392+
if bidder.DebugConfig.TimeoutNotification.Log {
393+
msg := fmt.Sprintf("TimeoutNotification: Failed to make timeout request: method(%s), uri(%s), error(%s)", toReq.Method, toReq.Uri, err.Error())
394+
util.LogRandomSample(msg, glog.Warningf, bidder.DebugConfig.TimeoutNotification.SamplingRate)
395+
}
396+
}
397+
} else if bidder.DebugConfig.TimeoutNotification.Log {
398+
reqJSON, err := json.Marshal(req)
399+
var msg string
400+
if err == nil {
401+
msg = fmt.Sprintf("TimeoutNotification: Failed to generate timeout request: error(%s), bidder request(%s)", errL[0].Error(), string(reqJSON))
402+
} else {
403+
msg = fmt.Sprintf("TimeoutNotification: Failed to generate timeout request: error(%s), bidder request marshal failed(%s)", errL[0].Error(), err.Error())
392404
}
405+
util.LogRandomSample(msg, glog.Warningf, bidder.DebugConfig.TimeoutNotification.SamplingRate)
393406
}
394407

395408
}

exchange/bidder_test.go

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,6 +1229,64 @@ func TestSetAssetTypes(t *testing.T) {
12291229
}
12301230
}
12311231

1232+
func TestTimeoutNotificationOff(t *testing.T) {
1233+
respBody := "{\"bid\":false}"
1234+
respStatus := 200
1235+
server := httptest.NewServer(mockHandler(respStatus, "getBody", respBody))
1236+
defer server.Close()
1237+
1238+
bidderImpl := &notifingBidder{
1239+
notiRequest: adapters.RequestData{
1240+
Method: "GET",
1241+
Uri: server.URL + "/notify/me",
1242+
Body: nil,
1243+
Headers: http.Header{},
1244+
},
1245+
}
1246+
bidder := &bidderAdapter{
1247+
Bidder: bidderImpl,
1248+
Client: server.Client(),
1249+
DebugConfig: config.Debug{},
1250+
me: &metricsConfig.DummyMetricsEngine{},
1251+
}
1252+
if tb, ok := bidder.Bidder.(adapters.TimeoutBidder); !ok {
1253+
t.Error("Failed to cast bidder to a TimeoutBidder")
1254+
} else {
1255+
bidder.doTimeoutNotification(tb, &adapters.RequestData{})
1256+
}
1257+
}
1258+
1259+
func TestTimeoutNotificationOn(t *testing.T) {
1260+
respBody := "{\"bid\":false}"
1261+
respStatus := 200
1262+
server := httptest.NewServer(mockHandler(respStatus, "getBody", respBody))
1263+
defer server.Close()
1264+
1265+
bidderImpl := &notifingBidder{
1266+
notiRequest: adapters.RequestData{
1267+
Method: "GET",
1268+
Uri: server.URL + "/notify/me",
1269+
Body: nil,
1270+
Headers: http.Header{},
1271+
},
1272+
}
1273+
bidder := &bidderAdapter{
1274+
Bidder: bidderImpl,
1275+
Client: server.Client(),
1276+
DebugConfig: config.Debug{
1277+
TimeoutNotification: config.TimeoutNotification{
1278+
Log: true,
1279+
},
1280+
},
1281+
me: &metricsConfig.DummyMetricsEngine{},
1282+
}
1283+
if tb, ok := bidder.Bidder.(adapters.TimeoutBidder); !ok {
1284+
t.Error("Failed to cast bidder to a TimeoutBidder")
1285+
} else {
1286+
bidder.doTimeoutNotification(tb, &adapters.RequestData{})
1287+
}
1288+
}
1289+
12321290
type goodSingleBidder struct {
12331291
bidRequest *openrtb.BidRequest
12341292
httpRequest *adapters.RequestData
@@ -1302,3 +1360,19 @@ func (bidder *bidRejector) MakeBids(internalRequest *openrtb.BidRequest, externa
13021360
bidder.httpResponse = response
13031361
return nil, []error{errors.New("Can't make a response.")}
13041362
}
1363+
1364+
type notifingBidder struct {
1365+
notiRequest adapters.RequestData
1366+
}
1367+
1368+
func (bidder *notifingBidder) MakeRequests(request *openrtb.BidRequest, reqInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) {
1369+
return nil, nil
1370+
}
1371+
1372+
func (bidder *notifingBidder) MakeBids(internalRequest *openrtb.BidRequest, externalRequest *adapters.RequestData, response *adapters.ResponseData) (*adapters.BidderResponse, []error) {
1373+
return nil, nil
1374+
}
1375+
1376+
func (bidder *notifingBidder) MakeTimeoutNotification(req *adapters.RequestData) (*adapters.RequestData, []error) {
1377+
return &bidder.notiRequest, nil
1378+
}

0 commit comments

Comments
 (0)