Repository: GoogleCloudPlatform/opentelemetry-operations-go
Pull request #163 (2021-03-25 03:50:34)

Delete unused code


Patch:
diff --git a/.github/header-checker-lint.yml b/.github/header-checker-lint.yml
index e82385b..2fb3633 100644
--- a/.github/header-checker-lint.yml
+++ b/.github/header-checker-lint.yml
@@ -1,3 +1,6 @@
+allowedCopyrightHolders:
+  - Google LLC
+  - OpenTelemetry Authors
 allowedLicenses:
   - Apache-2.0
 sourceFileExtensions:
diff --git a/exporter/trace/go.mod b/exporter/trace/go.mod
index 9a92ba3..148cbdb 100644
--- a/exporter/trace/go.mod
+++ b/exporter/trace/go.mod
@@ -7,6 +7,7 @@ require (
 	github.com/golang/protobuf v1.4.2
 	github.com/googleinterns/cloud-operations-api-mock v0.0.0-20200709193332-a1e58c29bdd3
 	github.com/stretchr/testify v1.7.0
+	go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.19.0
 	go.opentelemetry.io/otel v0.19.0
 	go.opentelemetry.io/otel/sdk v0.19.0
 	go.opentelemetry.io/otel/trace v0.19.0
diff --git a/exporter/trace/go.sum b/exporter/trace/go.sum
index e427959..f6f738e 100644
--- a/exporter/trace/go.sum
+++ b/exporter/trace/go.sum
@@ -45,6 +45,8 @@ github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymF
 github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
 github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
 github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
+github.com/felixge/httpsnoop v1.0.1 h1:lvB5Jl89CsZtGIWuTcDM1E/vkVs49/Ml7JJe07l8SPQ=
+github.com/felixge/httpsnoop v1.0.1/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
 github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
 github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
 github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
@@ -126,6 +128,10 @@ go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
 go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
 go.opencensus.io v0.22.4 h1:LYy1Hy3MJdrCdMwwzxA/dRok4ejH+RwNGbuoD9fCjto=
 go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
+go.opentelemetry.io/contrib v0.19.0 h1:x6Josyb/V+aDHg6IozzmZMaOhE+0Jb2NvEAM4/0Gftc=
+go.opentelemetry.io/contrib v0.19.0/go.mod h1:G/EtFaa6qaN7+LxqfIAT3GiZa7Wv5DTBUzl5H4LY0Kc=
+go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.19.0 h1:HOKafMKQkF8/+m57PrGDgV2OAbWKFKhbb1wbgLZ0+J4=
+go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.19.0/go.mod h1:7RDsakVbjb124lYDEjKuHTuzdqf04hLMEvPv/ufmqMs=
 go.opentelemetry.io/otel v0.19.0 h1:Lenfy7QHRXPZVsw/12CWpxX6d/JkrX8wrx2vO8G80Ng=
 go.opentelemetry.io/otel v0.19.0/go.mod h1:j9bF567N9EfomkSidSfmMwIwIBuP37AMAIzVW85OxSg=
 go.opentelemetry.io/otel/metric v0.19.0 h1:dtZ1Ju44gkJkYvo+3qGqVXmf88tc+a42edOywypengg=
diff --git a/exporter/trace/trace.go b/exporter/trace/trace.go
index f63a5da..bda8c9c 100644
--- a/exporter/trace/trace.go
+++ b/exporter/trace/trace.go
@@ -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"
 )
 
@@ -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...)
@@ -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
 }


Test patch:
diff --git a/exporter/trace/cloudtrace_test.go b/exporter/trace/cloudtrace_test.go
index 0080f56..62f2295 100644
--- a/exporter/trace/cloudtrace_test.go
+++ b/exporter/trace/cloudtrace_test.go
@@ -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
diff --git a/exporter/trace/example_test.go b/exporter/trace/example_test.go
new file mode 100644
index 0000000..08591a0
--- /dev/null
+++ b/exporter/trace/example_test.go
@@ -0,0 +1,48 @@
+// Copyright 2021 Google LLC
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package trace_test
+
+import (
+	"log"
+
+	"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
+
+	cloudtrace "github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/trace"
+)
+
+// For most programs, it's enough to install a tracing pipeline globally.
+func Example_globalPipeline() {
+	_, shutdown, err := cloudtrace.InstallNewPipeline(nil)
+	if err != nil {
+		log.Fatalf("unable to set up tracing: %v", err)
+	}
+	defer shutdown()
+
+	// use global tracer, for example...
+	_ = otelhttp.NewHandler(nil, "op")
+}
+
+// In some cases (e.g. multi-tenancy), it can be useful to have multiple tracers
+// defined in the program and pick one explicitly.
+func Example_explicitPipeline() {
+	tp, shutdown, err := cloudtrace.NewExportPipeline(nil)
+	if err != nil {
+		log.Fatalf("unable to set up tracing: %v", err)
+	}
+	defer shutdown()
+
+	// use tp explicitly, for example...
+	_ = otelhttp.NewHandler(nil, "op", otelhttp.WithTracerProvider(tp))
+}