@@ -54,7 +54,8 @@ type Sink struct {
5454 extractor ExtractLabelsFn
5555 taskInfo * taskInfo
5656
57- mu sync.Mutex
57+ mu sync.Mutex
58+ debugLogs bool
5859}
5960
6061// Config options for the stackdriver Sink.
@@ -94,6 +95,11 @@ type Config struct {
9495 // https://cloud.google.com/monitoring/api/resources#tag_generic_task
9596 // Optional. Defaults to a combination of hostname+pid.
9697 TaskID string
98+
99+ // Debug logging. Errors will be logged to stderr, but setting this to true
100+ // will log additional information that is helpful when debugging errors.
101+ // Optional. Defaults to false.
102+ DebugLogs bool
97103}
98104
99105type taskInfo struct {
@@ -150,6 +156,7 @@ func NewSink(client *monitoring.MetricClient, config *Config) *Sink {
150156 Job : config .Job ,
151157 TaskID : config .TaskID ,
152158 },
159+ debugLogs : config .DebugLogs ,
153160 }
154161
155162 // apply defaults if not configured explicitly
@@ -285,6 +292,9 @@ func (s *Sink) report(ctx context.Context) {
285292 log .Printf ("Could not extract labels from %s: %v" , v .name .hash , err )
286293 continue
287294 }
295+ if s .debugLogs {
296+ log .Printf ("%v is now %s + (%v)\n " , v .name .key , name , labels )
297+ }
288298 ts = append (ts , & monitoringpb.TimeSeries {
289299 Metric : & metricpb.Metric {
290300 Type : path .Join ("custom.googleapis.com" , "go-metrics" , name ),
@@ -315,6 +325,9 @@ func (s *Sink) report(ctx context.Context) {
315325 log .Printf ("Could not extract labels from %s: %v" , v .name .hash , err )
316326 continue
317327 }
328+ if s .debugLogs {
329+ log .Printf ("%v is now %s + (%v)\n " , v .name .key , name , labels )
330+ }
318331 ts = append (ts , & monitoringpb.TimeSeries {
319332 Metric : & metricpb.Metric {
320333 Type : path .Join ("custom.googleapis.com" , "go-metrics" , name ),
@@ -345,6 +358,10 @@ func (s *Sink) report(ctx context.Context) {
345358 log .Printf ("Could not extract labels from %s: %v" , v .name .hash , err )
346359 continue
347360 }
361+ if s .debugLogs {
362+ log .Printf ("%v is now %s + (%v)\n " , v .name .key , name , labels )
363+ }
364+
348365 var count int64
349366 count = 0
350367 for _ , i := range v .counts {
@@ -407,8 +424,10 @@ func (s *Sink) report(ctx context.Context) {
407424
408425 if err != nil {
409426 log .Printf ("Failed to write time series data: %v" , err )
410- for i , a := range req .TimeSeries {
411- log .Printf ("request timeseries[%d]: %v" , i , a )
427+ if s .debugLogs {
428+ for i , a := range req .TimeSeries {
429+ log .Printf ("request timeseries[%d]: %v" , i , a )
430+ }
412431 }
413432 }
414433 }
0 commit comments