Skip to content

Commit

Permalink
OTT-1902: Log bad request when loglevel is debug (#838)
Browse files Browse the repository at this point in the history
  • Loading branch information
ashishshinde-pubm authored Jul 10, 2024
1 parent a007d3d commit 31e0be3
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 6 deletions.
5 changes: 5 additions & 0 deletions modules/pubmatic/openwrap/beforevalidationhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ func (m OpenWrap) handleBeforeValidationHook(
if rCtx.IsCTVRequest {
m.metricEngine.RecordCTVInvalidReasonCount(getPubmaticErrorCode(openrtb3.NoBidReason(result.NbrCode)), rCtx.PubIDStr)
}
if glog.V(models.LogLevelDebug) {
bidRequest, _ := json.Marshal(payload.BidRequest)
glog.Infof("[bad_request] pubid:[%d] profid:[%d] endpoint:[%s] nbr:[%d] bidrequest:[%s]",
rCtx.PubID, rCtx.ProfileID, rCtx.Endpoint, result.NbrCode, string(bidRequest))
}
}
}()

Expand Down
11 changes: 8 additions & 3 deletions modules/pubmatic/openwrap/entrypointhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"time"

"github.com/buger/jsonparser"
"github.com/golang/glog"
"github.com/prebid/openrtb/v20/openrtb3"
"github.com/prebid/prebid-server/v2/config"
"github.com/prebid/prebid-server/v2/hooks/hookexecution"
Expand Down Expand Up @@ -48,10 +49,14 @@ func (m OpenWrap) handleEntrypointHook(
defer func() {
if result.Reject {
m.metricEngine.RecordBadRequests(endpoint, getPubmaticErrorCode(openrtb3.NoBidReason(result.NbrCode)))
} else {
result.ModuleContext = make(hookstage.ModuleContext)
result.ModuleContext["rctx"] = rCtx
if glog.V(models.LogLevelDebug) {
glog.Infof("[bad_request] pubid:[%d] profid:[%d] endpoint:[%s] nbr:[%d] query_params:[%s] body:[%s]",
rCtx.PubID, rCtx.ProfileID, rCtx.Endpoint, result.NbrCode, queryParams.Encode(), string(payload.Body))
}
return
}
result.ModuleContext = make(hookstage.ModuleContext)
result.ModuleContext["rctx"] = rCtx
}()

rCtx.Sshb = queryParams.Get("sshb")
Expand Down
2 changes: 1 addition & 1 deletion modules/pubmatic/openwrap/matchedimpression.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func getMatchedImpression(rctx models.RequestCtx) map[string]int {

syncer := syncerMap[syncerCode]
if syncer == nil {
glog.V(3).Infof("Invalid bidder code passed to ParseRequestCookies: %s ", partnerName)
glog.V(models.LogLevelDebug).Infof("Invalid bidder code passed to ParseRequestCookies: %s ", partnerName)
} else {
uid, _, _ := rctx.ParsedUidCookie.GetUID(syncer.Key())

Expand Down
3 changes: 2 additions & 1 deletion modules/pubmatic/openwrap/metrics/stats/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/alitto/pond"
"github.com/golang/glog"
"github.com/prebid/prebid-server/v2/modules/pubmatic/openwrap/models"
)

type HttpClient interface {
Expand Down Expand Up @@ -129,7 +130,7 @@ func (sc *Client) publishStatsToServer(statMap map[string]int) int {
return statusSetupFail
}

glog.V(3).Infof("[stats] nstats:[%d] data:[%s]", len(statMap), statJson)
glog.V(models.LogLevelDebug).Infof("[stats] nstats:[%d] data:[%s]", len(statMap), statJson)
req, err := http.NewRequest(http.MethodPost, sc.endpoint, bytes.NewBuffer(statJson))
if err != nil {
glog.Errorf("[stats_fail] Failed to form request to sent stats to server: %v", err)
Expand Down
7 changes: 7 additions & 0 deletions modules/pubmatic/openwrap/models/constants.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package models

import "github.com/golang/glog"

const (
PARTNER_ID = "partnerId"
ADAPTER_ID = "adapterId"
Expand Down Expand Up @@ -604,3 +606,8 @@ const (
MissingSignal = "missing"
InvalidSignal = "invalid"
)

// constants for log level
const (
LogLevelDebug glog.Level = 3
)
2 changes: 1 addition & 1 deletion modules/pubmatic/openwrap/unwrap/unwrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,6 @@ func (uw Unwrap) Unwrap(accountID, bidder string, bid *adapters.TypedBid, userAg
bid.Bid.AdM = string(respBody)
}

glog.V(3).Infof("[VAST_UNWRAPPER] pubid:[%v] bidder:[%v] impid:[%v] bidid:[%v] status_code:[%v] wrapper_cnt:[%v] httpRespCode= [%v] statsEnabled:[%v]",
glog.V(models.LogLevelDebug).Infof("[VAST_UNWRAPPER] pubid:[%v] bidder:[%v] impid:[%v] bidid:[%v] status_code:[%v] wrapper_cnt:[%v] httpRespCode= [%v] statsEnabled:[%v]",
accountID, bidder, bid.Bid.ImpID, bid.Bid.ID, respStatus, wrapperCnt, httpResp.Code, isStatsEnabled)
}

0 comments on commit 31e0be3

Please sign in to comment.