Repository: census-instrumentation/opencensus-service
Pull request #170 (2018-11-07 02:17:25)

interceptor: rename ocinterceptor to octrace.
Updates https://github.com/census-instrumentation/opencensus-service/issues/136.

Rename trace interceptor to differentiate from metrics interceptor.

odeke-em: Thank you @songy23 for working on this! I just have one request, could we instead just name it `octrace`  or `opencensustrace` since it is already a trace interceptor and also preserve the picked package name?
songy23: Thanks!

Patch:
diff --git a/cmd/ocagent/main.go b/cmd/ocagent/main.go
index 71d4fc6..55e0974 100644
--- a/cmd/ocagent/main.go
+++ b/cmd/ocagent/main.go
@@ -28,7 +28,7 @@ import (
 
 	agenttracepb "github.com/census-instrumentation/opencensus-proto/gen-go/agent/trace/v1"
 	"github.com/census-instrumentation/opencensus-service/exporter"
-	"github.com/census-instrumentation/opencensus-service/interceptor/opencensus"
+	"github.com/census-instrumentation/opencensus-service/interceptor/octrace"
 	"github.com/census-instrumentation/opencensus-service/interceptor/zipkin"
 	"github.com/census-instrumentation/opencensus-service/internal"
 	"github.com/census-instrumentation/opencensus-service/spanreceiver"
@@ -133,7 +133,7 @@ func runZPages(port int) func() error {
 }
 
 func runOCInterceptor(addr string, sr spanreceiver.SpanReceiver) (doneFn func() error, err error) {
-	oci, err := ocinterceptor.New(sr, ocinterceptor.WithSpanBufferPeriod(800*time.Millisecond))
+	oci, err := octrace.New(sr, octrace.WithSpanBufferPeriod(800*time.Millisecond))
 	if err != nil {
 		return nil, fmt.Errorf("Failed to create the OpenCensus interceptor: %v", err)
 	}
diff --git a/cmd/occollector/main.go b/cmd/occollector/main.go
index 3e8cbe5..fe76858 100644
--- a/cmd/occollector/main.go
+++ b/cmd/occollector/main.go
@@ -32,7 +32,7 @@ import (
 	commonpb "github.com/census-instrumentation/opencensus-proto/gen-go/agent/common/v1"
 	agenttracepb "github.com/census-instrumentation/opencensus-proto/gen-go/agent/trace/v1"
 	tracepb "github.com/census-instrumentation/opencensus-proto/gen-go/trace/v1"
-	"github.com/census-instrumentation/opencensus-service/interceptor/opencensus"
+	"github.com/census-instrumentation/opencensus-service/interceptor/octrace"
 	"github.com/census-instrumentation/opencensus-service/spanreceiver"
 
 	"go.opencensus.io/plugin/ocgrpc"
@@ -91,7 +91,7 @@ func runOCServerWithInterceptor(addr string, logger *zap.Logger) (func() error,
 		logger: logger,
 	}
 
-	oci, err := ocinterceptor.New(sr, ocinterceptor.WithSpanBufferPeriod(800*time.Millisecond))
+	oci, err := octrace.New(sr, octrace.WithSpanBufferPeriod(800*time.Millisecond))
 	if err != nil {
 		return nil, fmt.Errorf("Failed to create the OpenCensus interceptor: %v", err)
 	}
diff --git a/interceptor/opencensus/doc.go b/interceptor/octrace/doc.go
similarity index 85%
rename from interceptor/opencensus/doc.go
rename to interceptor/octrace/doc.go
index 72b4075..4ea854d 100644
--- a/interceptor/opencensus/doc.go
+++ b/interceptor/octrace/doc.go
@@ -12,6 +12,6 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-// Package ocinterceptor is the logic for receiving OpenCensus trace protobuf defined spans from
+// Package octrace is the logic for receiving OpenCensus trace protobuf defined spans from
 // already instrumented applications and then passing them onto a spanreceiver instance.
-package ocinterceptor
+package octrace
diff --git a/interceptor/opencensus/opencensus.go b/interceptor/octrace/opencensus.go
similarity index 99%
rename from interceptor/opencensus/opencensus.go
rename to interceptor/octrace/opencensus.go
index 4a15999..b9117f8 100644
--- a/interceptor/opencensus/opencensus.go
+++ b/interceptor/octrace/opencensus.go
@@ -12,7 +12,7 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-package ocinterceptor
+package octrace
 
 import (
 	"context"
diff --git a/interceptor/opencensus/options.go b/interceptor/octrace/options.go
similarity index 98%
rename from interceptor/opencensus/options.go
rename to interceptor/octrace/options.go
index 451a311..ceb613b 100644
--- a/interceptor/opencensus/options.go
+++ b/interceptor/octrace/options.go
@@ -12,7 +12,7 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-package ocinterceptor
+package octrace
 
 import "time"
 
diff --git a/interceptor/opencensus/trace_interceptor.go b/interceptor/octrace/trace_interceptor.go
similarity index 99%
rename from interceptor/opencensus/trace_interceptor.go
rename to interceptor/octrace/trace_interceptor.go
index cab8739..fef8cfa 100644
--- a/interceptor/opencensus/trace_interceptor.go
+++ b/interceptor/octrace/trace_interceptor.go
@@ -12,7 +12,7 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-package ocinterceptor
+package octrace
 
 import (
 	"context"


Test patch:
diff --git a/exporter/example_test.go b/exporter/example_test.go
index ea64235..7d6a863 100644
--- a/exporter/example_test.go
+++ b/exporter/example_test.go
@@ -32,7 +32,7 @@ import (
 
 	agenttracepb "github.com/census-instrumentation/opencensus-proto/gen-go/agent/trace/v1"
 	"github.com/census-instrumentation/opencensus-service/exporter"
-	"github.com/census-instrumentation/opencensus-service/interceptor/opencensus"
+	"github.com/census-instrumentation/opencensus-service/interceptor/octrace"
 )
 
 func Example_endToEndExporting() {
@@ -111,7 +111,7 @@ func runServer() (port uint16, closeFn func()) {
 
 	// Now run the OCInterceptor which will receive traces from the client applications
 	// in the various languages instrumented with OpenCensus.
-	oci, err := ocinterceptor.New(commonSpanReceiver, ocinterceptor.WithSpanBufferPeriod(100*time.Millisecond))
+	oci, err := octrace.New(commonSpanReceiver, octrace.WithSpanBufferPeriod(100*time.Millisecond))
 	if err != nil {
 		log.Fatalf("Failed to create the OpenCensus interceptor: %v", err)
 	}
diff --git a/interceptor/end_to_end_test.go b/interceptor/end_to_end_test.go
index 21f6b59..a4403f1 100644
--- a/interceptor/end_to_end_test.go
+++ b/interceptor/end_to_end_test.go
@@ -26,7 +26,7 @@ import (
 	commonpb "github.com/census-instrumentation/opencensus-proto/gen-go/agent/common/v1"
 	tracepb "github.com/census-instrumentation/opencensus-proto/gen-go/trace/v1"
 	"github.com/census-instrumentation/opencensus-service/interceptor"
-	ocinterceptor "github.com/census-instrumentation/opencensus-service/interceptor/opencensus"
+	octrace "github.com/census-instrumentation/opencensus-service/interceptor/octrace"
 	"github.com/census-instrumentation/opencensus-service/spanreceiver"
 )
 
@@ -34,7 +34,7 @@ func Example_endToEnd() {
 	// This is what the cmd/ocagent code would look like this.
 	// A trace interceptor as per the trace interceptor
 	// configs that have been parsed.
-	tin, err := ocinterceptor.NewTraceInterceptorOnDefaultPort()
+	tin, err := octrace.NewTraceInterceptorOnDefaultPort()
 	if err != nil {
 		log.Fatalf("Failed to create trace interceptor: %v", err)
 	}
diff --git a/interceptor/opencensus/observability_test.go b/interceptor/octrace/observability_test.go
similarity index 96%
rename from interceptor/opencensus/observability_test.go
rename to interceptor/octrace/observability_test.go
index dba6ea1..a3e0b14 100644
--- a/interceptor/opencensus/observability_test.go
+++ b/interceptor/octrace/observability_test.go
@@ -12,7 +12,7 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-package ocinterceptor_test
+package octrace_test
 
 import (
 	"bytes"
@@ -32,7 +32,7 @@ import (
 	commonpb "github.com/census-instrumentation/opencensus-proto/gen-go/agent/common/v1"
 	agenttracepb "github.com/census-instrumentation/opencensus-proto/gen-go/agent/trace/v1"
 	tracepb "github.com/census-instrumentation/opencensus-proto/gen-go/trace/v1"
-	"github.com/census-instrumentation/opencensus-service/interceptor/opencensus"
+	"github.com/census-instrumentation/opencensus-service/interceptor/octrace"
 	"github.com/census-instrumentation/opencensus-service/internal"
 )
 
@@ -48,7 +48,7 @@ func TestEnsureRecordedMetrics(t *testing.T) {
 
 	sappender := newSpanAppender()
 
-	_, port, doneFn := ocInterceptorOnGRPCServer(t, sappender, ocinterceptor.WithSpanBufferPeriod(2*time.Millisecond))
+	_, port, doneFn := ocInterceptorOnGRPCServer(t, sappender, octrace.WithSpanBufferPeriod(2*time.Millisecond))
 	defer doneFn()
 
 	// Now the opencensus-agent exporter.
@@ -119,7 +119,7 @@ func TestEnsureRecordedMetrics_zeroLengthSpansSender(t *testing.T) {
 	)
 	sappender := newSpanAppender()
 
-	_, port, doneFn := ocInterceptorOnGRPCServer(t, sappender, ocinterceptor.WithSpanBufferPeriod(2*time.Millisecond))
+	_, port, doneFn := ocInterceptorOnGRPCServer(t, sappender, octrace.WithSpanBufferPeriod(2*time.Millisecond))
 	defer doneFn()
 
 	// Now the opencensus-agent exporter.
@@ -191,7 +191,7 @@ func TestExportSpanLinkingMaintainsParentLink(t *testing.T) {
 
 	spanSink := newSpanAppender()
 	spansBufferPeriod := 10 * time.Millisecond
-	_, port, doneFn := ocInterceptorOnGRPCServer(t, spanSink, ocinterceptor.WithSpanBufferPeriod(spansBufferPeriod))
+	_, port, doneFn := ocInterceptorOnGRPCServer(t, spanSink, octrace.WithSpanBufferPeriod(spansBufferPeriod))
 	defer doneFn()
 
 	traceSvcClient, traceSvcDoneFn, err := makeTraceServiceClient(port)
diff --git a/interceptor/opencensus/opencensus_test.go b/interceptor/octrace/opencensus_test.go
similarity index 96%
rename from interceptor/opencensus/opencensus_test.go
rename to interceptor/octrace/opencensus_test.go
index c771e69..8b6d582 100644
--- a/interceptor/opencensus/opencensus_test.go
+++ b/interceptor/octrace/opencensus_test.go
@@ -12,7 +12,7 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-package ocinterceptor_test
+package octrace_test
 
 import (
 	"bytes"
@@ -36,7 +36,7 @@ import (
 	commonpb "github.com/census-instrumentation/opencensus-proto/gen-go/agent/common/v1"
 	agenttracepb "github.com/census-instrumentation/opencensus-proto/gen-go/agent/trace/v1"
 	tracepb "github.com/census-instrumentation/opencensus-proto/gen-go/trace/v1"
-	"github.com/census-instrumentation/opencensus-service/interceptor/opencensus"
+	"github.com/census-instrumentation/opencensus-service/interceptor/octrace"
 	"github.com/census-instrumentation/opencensus-service/internal"
 	"github.com/census-instrumentation/opencensus-service/spanreceiver"
 	"go.opencensus.io/trace"
@@ -48,7 +48,7 @@ func TestInterceptor_endToEnd(t *testing.T) {
 
 	sappender := newSpanAppender()
 
-	_, port, doneFn := ocInterceptorOnGRPCServer(t, sappender, ocinterceptor.WithSpanBufferPeriod(100*time.Millisecond))
+	_, port, doneFn := ocInterceptorOnGRPCServer(t, sappender, octrace.WithSpanBufferPeriod(100*time.Millisecond))
 	defer doneFn()
 
 	// Now the opencensus-agent exporter.
@@ -171,7 +171,7 @@ func TestInterceptor_endToEnd(t *testing.T) {
 func TestExportMultiplexing(t *testing.T) {
 	spanSink := newSpanAppender()
 
-	_, port, doneFn := ocInterceptorOnGRPCServer(t, spanSink, ocinterceptor.WithSpanBufferPeriod(90*time.Millisecond))
+	_, port, doneFn := ocInterceptorOnGRPCServer(t, spanSink, octrace.WithSpanBufferPeriod(90*time.Millisecond))
 	defer doneFn()
 
 	traceClient, traceClientDoneFn, err := makeTraceServiceClient(port)
@@ -290,7 +290,7 @@ func TestExportMultiplexing(t *testing.T) {
 func TestExportProtocolViolations_nodelessFirstMessage(t *testing.T) {
 	spanSink := newSpanAppender()
 
-	_, port, doneFn := ocInterceptorOnGRPCServer(t, spanSink, ocinterceptor.WithSpanBufferPeriod(90*time.Millisecond))
+	_, port, doneFn := ocInterceptorOnGRPCServer(t, spanSink, octrace.WithSpanBufferPeriod(90*time.Millisecond))
 	defer doneFn()
 
 	traceClient, traceClientDoneFn, err := makeTraceServiceClient(port)
@@ -358,7 +358,7 @@ func TestExportProtocolViolations_nodelessFirstMessage(t *testing.T) {
 func TestExportProtocolConformation_spansInFirstMessage(t *testing.T) {
 	spanSink := newSpanAppender()
 
-	_, port, doneFn := ocInterceptorOnGRPCServer(t, spanSink, ocinterceptor.WithSpanBufferPeriod(70*time.Millisecond))
+	_, port, doneFn := ocInterceptorOnGRPCServer(t, spanSink, octrace.WithSpanBufferPeriod(70*time.Millisecond))
 	defer doneFn()
 
 	traceClient, traceClientDoneFn, err := makeTraceServiceClient(port)
@@ -456,7 +456,7 @@ func (sa *spanAppender) ReceiveSpans(ctx context.Context, node *commonpb.Node, s
 	return &spanreceiver.Acknowledgement{SavedSpans: uint64(len(spans))}, nil
 }
 
-func ocInterceptorOnGRPCServer(t *testing.T, sr spanreceiver.SpanReceiver, opts ...ocinterceptor.Option) (oci *ocinterceptor.Interceptor, port int, done func()) {
+func ocInterceptorOnGRPCServer(t *testing.T, sr spanreceiver.SpanReceiver, opts ...octrace.Option) (oci *octrace.Interceptor, port int, done func()) {
 	ln, err := net.Listen("tcp", ":0")
 	if err != nil {
 		t.Fatalf("Failed to find an available address to run the gRPC server: %v", err)
@@ -480,7 +480,7 @@ func ocInterceptorOnGRPCServer(t *testing.T, sr spanreceiver.SpanReceiver, opts
 		t.Fatalf("Failed to create new agent: %v", err)
 	}
 
-	oci, err = ocinterceptor.New(sr, opts...)
+	oci, err = octrace.New(sr, opts...)
 	if err != nil {
 		t.Fatalf("Failed to create the Interceptor: %v", err)
 	}