Skip to content

Commit

Permalink
Delete unused code (#163)
Browse files Browse the repository at this point in the history
  • Loading branch information
punya authored Mar 25, 2021
1 parent 5d512e6 commit b569e0b
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 67 deletions.
9 changes: 0 additions & 9 deletions exporter/trace/cloudtrace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,6 @@ func TestExporter_Timeout(t *testing.T) {
}
}

type logBuffer struct {
logInputChan chan []byte
}

func (lb *logBuffer) Write(b []byte) (n int, err error) {
lb.logInputChan <- b
return len(b), nil
}

// A mock server we can re-use for different kinds of unit tests against batch-write request.
type mock struct {
tracepb.UnimplementedTraceServiceServer
Expand Down
59 changes: 1 addition & 58 deletions exporter/trace/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,12 @@ package trace
import (
"context"
"fmt"
"log"
"strings"
"sync"
"time"

export "go.opentelemetry.io/otel/sdk/export/trace"

traceclient "cloud.google.com/go/trace/apiv2"
"google.golang.org/api/option"
"google.golang.org/api/support/bundler"
tracepb "google.golang.org/genproto/googleapis/devtools/cloudtrace/v2"
)

Expand All @@ -36,19 +32,12 @@ import (
type traceExporter struct {
o *options
projectID string
bundler *bundler.Bundler
// uploadFn defaults in uploadSpans; it can be replaced for tests.
uploadFn func(ctx context.Context, spans []*tracepb.Span) error
overflowLogger
client *traceclient.Client
}

const defaultBundleDelayThreshold = 2 * time.Second
const defaultBundleCountThreshold = 50
const defaultBundleByteThreshold = 15000
const defaultBundleByteLimit = 0
const defaultBufferedByteLimit = 8 * 1024 * 1024

func newTraceExporter(o *options) (*traceExporter, error) {
clientOps := append(o.TraceClientOptions, option.WithUserAgent(userAgent))
client, err := traceclient.NewClient(o.Context, clientOps...)
Expand Down Expand Up @@ -117,51 +106,5 @@ func (e *traceExporter) uploadSpans(ctx context.Context, spans []*tracepb.Span)
// overflowLogger ensures that at most one overflow error log message is
// written every 5 seconds.
type overflowLogger struct {
mu sync.Mutex
pause bool
delayDur time.Duration
bufferErrs int
oversized int
}

func (o *overflowLogger) log(oversized bool) {
o.mu.Lock()
defer o.mu.Unlock()
if !o.pause {
o.delay()
}

if oversized {
o.oversized++
} else {
o.bufferErrs++
}
}

func (o *overflowLogger) delay() {
o.pause = true
time.AfterFunc(o.delayDur, func() {
o.mu.Lock()
defer o.mu.Unlock()
o.pause = false
logBufferErrors(o.bufferErrs, o.oversized)
o.bufferErrs = 0
o.oversized = 0
})
}

func logBufferErrors(bufferFull, oversized int) {
if bufferFull == 0 && oversized == 0 {
return
}

msgs := make([]string, 0, 2)
if bufferFull > 0 {
msgs = append(msgs, fmt.Sprintf("buffer full: %v", bufferFull))
}
if oversized > 0 {
msgs = append(msgs, fmt.Sprintf("oversized item: %v", oversized))
}

log.Printf("OpenTelemetry Cloud Trace exporter: failed to upload spans: %s\n", strings.Join(msgs, ", "))
delayDur time.Duration
}

0 comments on commit b569e0b

Please sign in to comment.