Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,14 @@ To maintain consistency in the project's code, please:

- Do not discard errors. You should implement appropriate error handling, such as gracefully falling back to a default behavior or bubbling up an error.

## Swapping Global Dependencies

Logger is a global side-effectful dependency that sometimes needs to be swapped to modify the behavior.
The `Logger` package contains an interface definition for unstructured logging with built-in `glog` implementation.
The interface provides standard logging methods: `Debug`, `Info`, `Warn`, `Error`, and `Fatal`.
The `glog` implementation is based on `github.com/golang/glog` package and serves as the concrete implementation for the logging interface.
By default, the package uses the `glog` logger implementation.

## Contributing

We welcome contributions to OpenAds Server in form of issues and PRs in this repository. If your change applies to both Prebid Server as well as OpenAds Server, please submit it to the [Prebid Server Go repository](https://github.com/prebid/prebid-server) as we will pull in relevant upstream changes.
Expand Down
14 changes: 7 additions & 7 deletions analytics/agma/agma_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import (

"github.com/benbjohnson/clock"
"github.com/docker/go-units"
"github.com/golang/glog"
"github.com/prebid/go-gdpr/vendorconsent"
"github.com/prebid/prebid-server/v3/analytics"
"github.com/prebid/prebid-server/v3/config"
"github.com/prebid/prebid-server/v3/logger"
"github.com/prebid/prebid-server/v3/openrtb_ext"
)

Expand Down Expand Up @@ -93,7 +93,7 @@ func (l *AgmaLogger) start() {
for {
select {
case <-l.sigTermCh:
glog.Infof("[AgmaAnalytics] Received Close, trying to flush buffer")
logger.Infof("[AgmaAnalytics] Received Close, trying to flush buffer")
l.flush()
return
case event := <-l.bufferCh:
Expand Down Expand Up @@ -139,7 +139,7 @@ func (l *AgmaLogger) flush() {
if err != nil {
l.reset()
l.mux.Unlock()
glog.Warning("[AgmaAnalytics] fail to copy the buffer")
logger.Warnf("[AgmaAnalytics] fail to copy the buffer")
return
}

Expand Down Expand Up @@ -223,7 +223,7 @@ func (l *AgmaLogger) LogAuctionObject(event *analytics.AuctionObject) {
}
data, err := serializeAnayltics(event.RequestWrapper, EventTypeAuction, code, event.StartTime)
if err != nil {
glog.Errorf("[AgmaAnalytics] Error serializing auction object: %v", err)
logger.Errorf("[AgmaAnalytics] Error serializing auction object: %v", err)
return
}
l.bufferCh <- data
Expand All @@ -239,7 +239,7 @@ func (l *AgmaLogger) LogAmpObject(event *analytics.AmpObject) {
}
data, err := serializeAnayltics(event.RequestWrapper, EventTypeAmp, code, event.StartTime)
if err != nil {
glog.Errorf("[AgmaAnalytics] Error serializing amp object: %v", err)
logger.Errorf("[AgmaAnalytics] Error serializing amp object: %v", err)
return
}
l.bufferCh <- data
Expand All @@ -255,14 +255,14 @@ func (l *AgmaLogger) LogVideoObject(event *analytics.VideoObject) {
}
data, err := serializeAnayltics(event.RequestWrapper, EventTypeVideo, code, event.StartTime)
if err != nil {
glog.Errorf("[AgmaAnalytics] Error serializing video object: %v", err)
logger.Errorf("[AgmaAnalytics] Error serializing video object: %v", err)
return
}
l.bufferCh <- data
}

func (l *AgmaLogger) Shutdown() {
glog.Info("[AgmaAnalytics] Shutdown, trying to flush buffer")
logger.Infof("[AgmaAnalytics] Shutdown, trying to flush buffer")
l.flush() // mutex safe
}

Expand Down
12 changes: 6 additions & 6 deletions analytics/agma/sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"net/url"
"time"

"github.com/golang/glog"
"github.com/prebid/prebid-server/v3/config"
"github.com/prebid/prebid-server/v3/logger"
"github.com/prebid/prebid-server/v3/version"
)

Expand Down Expand Up @@ -51,7 +51,7 @@ func createHttpSender(httpClient *http.Client, endpoint config.AgmaAnalyticsHttp
if endpoint.Gzip {
requestBody, err = compressToGZIP(payload)
if err != nil {
glog.Errorf("[agmaAnalytics] Compressing request failed %v", err)
logger.Errorf("[agmaAnalytics] Compressing request failed %v", err)
return err
}
} else {
Expand All @@ -60,7 +60,7 @@ func createHttpSender(httpClient *http.Client, endpoint config.AgmaAnalyticsHttp

req, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.Url, bytes.NewBuffer(requestBody))
if err != nil {
glog.Errorf("[agmaAnalytics] Creating request failed %v", err)
logger.Errorf("[agmaAnalytics] Creating request failed %v", err)
return err
}

Expand All @@ -72,18 +72,18 @@ func createHttpSender(httpClient *http.Client, endpoint config.AgmaAnalyticsHttp

resp, err := httpClient.Do(req)
if err != nil {
glog.Errorf("[agmaAnalytics] Sending request failed %v", err)
logger.Errorf("[agmaAnalytics] Sending request failed %v", err)
return err
}
defer func() {
if _, err := io.Copy(io.Discard, resp.Body); err != nil {
glog.Errorf("[agmaAnalytics] Draining response body failed: %v", err)
logger.Errorf("[agmaAnalytics] Draining response body failed: %v", err)
}
resp.Body.Close()
}()

if resp.StatusCode != http.StatusOK {
glog.Errorf("[agmaAnalytics] Wrong code received %d instead of %d", resp.StatusCode, http.StatusOK)
logger.Errorf("[agmaAnalytics] Wrong code received %d instead of %d", resp.StatusCode, http.StatusOK)
return fmt.Errorf("wrong code received %d instead of %d", resp.StatusCode, http.StatusOK)
}
return nil
Expand Down
9 changes: 4 additions & 5 deletions analytics/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"encoding/json"

"github.com/benbjohnson/clock"
"github.com/golang/glog"
"github.com/prebid/prebid-server/v3/analytics"
"github.com/prebid/prebid-server/v3/analytics/agma"
"github.com/prebid/prebid-server/v3/analytics/auctionaudit"
Expand All @@ -13,20 +12,20 @@
"github.com/prebid/prebid-server/v3/analytics/pubstack"
"github.com/prebid/prebid-server/v3/analytics/s3"
"github.com/prebid/prebid-server/v3/config"
"github.com/prebid/prebid-server/v3/metrics"
"github.com/prebid/prebid-server/v3/logger"
"github.com/prebid/prebid-server/v3/openrtb_ext"
"github.com/prebid/prebid-server/v3/ortb"
"github.com/prebid/prebid-server/v3/privacy"
)

// Modules that need to be logged to need to be initialized here
func New(analytics *config.Analytics, metricsEngine metrics.MetricsEngine) analytics.Runner {

Check failure on line 22 in analytics/build/build.go

View workflow job for this annotation

GitHub Actions / Test and Validate

undefined: metrics
modules := make(enabledAnalytics, 0)
if len(analytics.File.Filename) > 0 {
if mod, err := filesystem.NewFileLogger(analytics.File.Filename); err == nil {
modules["filelogger"] = mod
} else {
glog.Fatalf("Could not initialize FileLogger for file %v :%v", analytics.File.Filename, err)
logger.Fatalf("Could not initialize FileLogger for file %v :%v", analytics.File.Filename, err)
}
}

Expand All @@ -43,7 +42,7 @@
if err == nil {
modules["pubstack"] = pubstackModule
} else {
glog.Errorf("Could not initialize PubstackModule: %v", err)
logger.Errorf("Could not initialize PubstackModule: %v", err)
}
}

Expand All @@ -55,20 +54,20 @@
if err == nil {
modules["agma"] = agmaModule
} else {
glog.Errorf("Could not initialize Agma Anayltics: %v", err)
logger.Errorf("Could not initialize Agma Anayltics: %v", err)
}
}

if analytics.S3.Enabled {
s3Client, err := s3.NewS3Client(analytics.S3)
if err != nil {
glog.Errorf("Could not create S3 client: %v", err)

Check failure on line 64 in analytics/build/build.go

View workflow job for this annotation

GitHub Actions / Test and Validate

undefined: glog
} else {
s3Module, err := s3.NewModule(analytics.S3, s3Client, clock.New(), metricsEngine)
if err == nil {
modules["s3"] = s3Module
} else {
glog.Errorf("Could not initialize S3 Analytics: %v", err)

Check failure on line 70 in analytics/build/build.go

View workflow job for this annotation

GitHub Actions / Test and Validate

undefined: glog
}
}
}
Expand All @@ -78,8 +77,8 @@
if err == nil {
modules["auctionaudit"] = auditModule
} else {
metricsEngine.RecordAuctionAuditError(metrics.AuctionAuditErrorStartup)

Check failure on line 80 in analytics/build/build.go

View workflow job for this annotation

GitHub Actions / Test and Validate

undefined: metrics
glog.Errorf("Could not initialize Auction Audit Analytics: %v", err)

Check failure on line 81 in analytics/build/build.go

View workflow job for this annotation

GitHub Actions / Test and Validate

undefined: glog
}
}

Expand Down
4 changes: 2 additions & 2 deletions analytics/filesystem/file_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"fmt"

cglog "github.com/chasex/glog"
"github.com/golang/glog"
"github.com/prebid/openrtb/v20/openrtb2"
"github.com/prebid/prebid-server/v3/analytics"
"github.com/prebid/prebid-server/v3/logger"
"github.com/prebid/prebid-server/v3/util/jsonutil"
)

Expand Down Expand Up @@ -94,7 +94,7 @@ func (f *FileLogger) LogNotificationEventObject(ne *analytics.NotificationEvent)
// Shutdown the logger
func (f *FileLogger) Shutdown() {
// clear all pending buffered data in case there is any
glog.Info("[FileLogger] Shutdown, trying to flush buffer")
logger.Infof("[FileLogger] Shutdown, trying to flush buffer")
f.Logger.Flush()
}

Expand Down
4 changes: 2 additions & 2 deletions analytics/pubstack/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"time"

"github.com/docker/go-units"
"github.com/golang/glog"
"github.com/prebid/prebid-server/v3/logger"
)

func fetchConfig(client *http.Client, endpoint *url.URL) (*Configuration, error) {
Expand All @@ -21,7 +21,7 @@ func fetchConfig(client *http.Client, endpoint *url.URL) (*Configuration, error)
// read the entire response body to ensure full connection reuse if there's an
// error while decoding the json
if _, err := io.Copy(io.Discard, res.Body); err != nil {
glog.Errorf("[pubstack] Draining config response body failed: %v", err)
logger.Errorf("[pubstack] Draining config response body failed: %v", err)
}
res.Body.Close()
}()
Expand Down
8 changes: 4 additions & 4 deletions analytics/pubstack/eventchannel/eventchannel.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"time"

"github.com/benbjohnson/clock"
"github.com/golang/glog"
"github.com/prebid/prebid-server/v3/logger"
)

type Metrics struct {
Expand Down Expand Up @@ -66,7 +66,7 @@ func (c *EventChannel) buffer(event []byte) {

_, err := c.gz.Write(event)
if err != nil {
glog.Warning("[pubstack] fail to compress, skip the event")
logger.Warnf("[pubstack] fail to compress, skip the event")
return
}

Expand Down Expand Up @@ -104,15 +104,15 @@ func (c *EventChannel) flush() {
// finish writing gzip header
err := c.gz.Close()
if err != nil {
glog.Warning("[pubstack] fail to close gzipped buffer")
logger.Warnf("[pubstack] fail to close gzipped buffer")
return
}

// copy the current buffer to send the payload in a new thread
payload := make([]byte, c.buff.Len())
_, err = c.buff.Read(payload)
if err != nil {
glog.Warning("[pubstack] fail to copy the buffer")
logger.Warnf("[pubstack] fail to copy the buffer")
return
}

Expand Down
10 changes: 5 additions & 5 deletions analytics/pubstack/eventchannel/sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"net/url"
"path"

"github.com/golang/glog"
"github.com/prebid/prebid-server/v3/logger"
)

type Sender = func(payload []byte) error
Expand All @@ -17,7 +17,7 @@ func NewHttpSender(client *http.Client, endpoint string) Sender {
return func(payload []byte) error {
req, err := http.NewRequest(http.MethodPost, endpoint, bytes.NewReader(payload))
if err != nil {
glog.Error(err)
logger.Errorf("%v", err)
return err
}

Expand All @@ -30,13 +30,13 @@ func NewHttpSender(client *http.Client, endpoint string) Sender {
}
defer func() {
if _, err := io.Copy(io.Discard, resp.Body); err != nil {
glog.Errorf("[pubstack] Draining sender response body failed: %v", err)
logger.Errorf("[pubstack] Draining sender response body failed: %v", err)
}
resp.Body.Close()
}()

if resp.StatusCode != http.StatusOK {
glog.Errorf("[pubstack] Wrong code received %d instead of %d", resp.StatusCode, http.StatusOK)
logger.Errorf("[pubstack] Wrong code received %d instead of %d", resp.StatusCode, http.StatusOK)
return fmt.Errorf("wrong code received %d instead of %d", resp.StatusCode, http.StatusOK)
}
return nil
Expand All @@ -46,7 +46,7 @@ func NewHttpSender(client *http.Client, endpoint string) Sender {
func BuildEndpointSender(client *http.Client, baseUrl string, module string) Sender {
endpoint, err := url.Parse(baseUrl)
if err != nil {
glog.Error(err)
logger.Errorf("%v", err)
}
endpoint.Path = path.Join(endpoint.Path, "intake", module)
return NewHttpSender(client, endpoint.String())
Expand Down
21 changes: 10 additions & 11 deletions analytics/pubstack/pubstack_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ import (
"time"

"github.com/benbjohnson/clock"
"github.com/golang/glog"

"github.com/prebid/prebid-server/v3/analytics"
"github.com/prebid/prebid-server/v3/analytics/pubstack/eventchannel"
"github.com/prebid/prebid-server/v3/analytics/pubstack/helpers"
"github.com/prebid/prebid-server/v3/logger"
)

type Configuration struct {
Expand Down Expand Up @@ -64,7 +63,7 @@ func NewModule(client *http.Client, scope, endpoint, configRefreshDelay string,
}

func NewModuleWithConfigTask(client *http.Client, scope, endpoint string, maxEventCount int, maxByteSize, maxTime string, configTask ConfigUpdateTask, clock clock.Clock) (analytics.Module, error) {
glog.Infof("[pubstack] Initializing module scope=%s endpoint=%s\n", scope, endpoint)
logger.Infof("[pubstack] Initializing module scope=%s endpoint=%s\n", scope, endpoint)

// parse args
bufferCfg, err := newBufferConfig(maxEventCount, maxByteSize, maxTime)
Expand Down Expand Up @@ -103,7 +102,7 @@ func NewModuleWithConfigTask(client *http.Client, scope, endpoint string, maxEve
configChannel := configTask.Start(pb.stopCh)
go pb.start(configChannel)

glog.Info("[pubstack] Pubstack analytics configured and ready")
logger.Infof("[pubstack] Pubstack analytics configured and ready")
return &pb, nil
}

Expand All @@ -118,7 +117,7 @@ func (p *PubstackModule) LogAuctionObject(ao *analytics.AuctionObject) {
// serialize event
payload, err := helpers.JsonifyAuctionObject(ao, p.scope)
if err != nil {
glog.Warning("[pubstack] Cannot serialize auction")
logger.Warnf("[pubstack] Cannot serialize auction")
return
}

Expand All @@ -139,7 +138,7 @@ func (p *PubstackModule) LogVideoObject(vo *analytics.VideoObject) {
// serialize event
payload, err := helpers.JsonifyVideoObject(vo, p.scope)
if err != nil {
glog.Warning("[pubstack] Cannot serialize video")
logger.Warnf("[pubstack] Cannot serialize video")
return
}

Expand All @@ -157,7 +156,7 @@ func (p *PubstackModule) LogSetUIDObject(so *analytics.SetUIDObject) {
// serialize event
payload, err := helpers.JsonifySetUIDObject(so, p.scope)
if err != nil {
glog.Warning("[pubstack] Cannot serialize video")
logger.Warnf("[pubstack] Cannot serialize video")
return
}

Expand All @@ -175,7 +174,7 @@ func (p *PubstackModule) LogCookieSyncObject(cso *analytics.CookieSyncObject) {
// serialize event
payload, err := helpers.JsonifyCookieSync(cso, p.scope)
if err != nil {
glog.Warning("[pubstack] Cannot serialize video")
logger.Warnf("[pubstack] Cannot serialize video")
return
}

Expand All @@ -193,7 +192,7 @@ func (p *PubstackModule) LogAmpObject(ao *analytics.AmpObject) {
// serialize event
payload, err := helpers.JsonifyAmpObject(ao, p.scope)
if err != nil {
glog.Warning("[pubstack] Cannot serialize video")
logger.Warnf("[pubstack] Cannot serialize video")
return
}

Expand All @@ -203,7 +202,7 @@ func (p *PubstackModule) LogAmpObject(ao *analytics.AmpObject) {
// Shutdown - no op since the analytic module already implements system signal handling
// and trying to close a closed channel will cause panic
func (p *PubstackModule) Shutdown() {
glog.Info("[PubstackModule] Shutdown")
logger.Infof("[PubstackModule] Shutdown")
}

func (p *PubstackModule) start(c <-chan *Configuration) {
Expand All @@ -216,7 +215,7 @@ func (p *PubstackModule) start(c <-chan *Configuration) {
return
case config := <-c:
p.updateConfig(config)
glog.Infof("[pubstack] Updating config: %v", p.cfg)
logger.Infof("[pubstack] Updating config: %v", p.cfg)
}
}
}
Expand Down
Loading
Loading