Skip to content
This repository has been archived by the owner on Jul 31, 2023. It is now read-only.

Commit

Permalink
Add NeverSample span around Stackdriver stats upload (#580)
Browse files Browse the repository at this point in the history
Fixes: #573
  • Loading branch information
Ramon Nogueira committed Mar 14, 2018
1 parent fbaec82 commit 137758e
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions exporter/stackdriver/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ import (
"go.opencensus.io/internal"
"go.opencensus.io/stats/view"
"go.opencensus.io/tag"
"go.opencensus.io/trace"

monitoring "cloud.google.com/go/monitoring/apiv3"
timestamp "github.com/golang/protobuf/ptypes/timestamp"
"cloud.google.com/go/monitoring/apiv3"
"github.com/golang/protobuf/ptypes/timestamp"
"google.golang.org/api/option"
"google.golang.org/api/support/bundler"
distributionpb "google.golang.org/genproto/googleapis/api/distribution"
Expand Down Expand Up @@ -143,7 +144,7 @@ func getTaskValue() string {
// handleUpload handles uploading a slice
// of Data, as well as error handling.
func (e *statsExporter) handleUpload(vds ...*view.Data) {
if err := e.upload(vds); err != nil {
if err := e.uploadStats(vds); err != nil {
e.onError(err)
}
}
Expand All @@ -164,16 +165,24 @@ func (e *statsExporter) onError(err error) {
log.Printf("Failed to export to Stackdriver Monitoring: %v", err)
}

func (e *statsExporter) upload(vds []*view.Data) error {
ctx := context.Background()
func (e *statsExporter) uploadStats(vds []*view.Data) error {
span := trace.NewSpan(
"go.opencensus.io/exporter/stackdriver.uploadStats",
nil,
trace.StartOptions{Sampler: trace.NeverSample()},
)
ctx := trace.WithSpan(context.Background(), span)
defer span.End()

for _, vd := range vds {
if err := e.createMeasure(ctx, vd); err != nil {
span.SetStatus(trace.Status{Code: 2, Message: err.Error()})
return err
}
}
for _, req := range e.makeReq(vds, maxTimeSeriesPerUpload) {
if err := e.c.CreateTimeSeries(ctx, req); err != nil {
span.SetStatus(trace.Status{Code: 2, Message: err.Error()})
// TODO(jbd): Don't fail fast here, batch errors?
return err
}
Expand Down

0 comments on commit 137758e

Please sign in to comment.