diff --git a/config/configgrpc/configgrpc.go b/config/configgrpc/configgrpc.go index 00d6897fabc..a79b8da353d 100644 --- a/config/configgrpc/configgrpc.go +++ b/config/configgrpc/configgrpc.go @@ -20,6 +20,7 @@ import ( "strings" "time" + "go.opencensus.io/plugin/ocgrpc" "google.golang.org/grpc" "google.golang.org/grpc/balancer/roundrobin" "google.golang.org/grpc/credentials" @@ -307,6 +308,10 @@ func (gss *GRPCServerSettings) ToServerOption(ext map[config.ComponentID]compone ) } + // Enable OpenCensus observability plugin. + // TODO: Change to OpenTelemetry when collector is changed. + opts = append(opts, grpc.StatsHandler(&ocgrpc.ServerHandler{})) + return opts, nil } diff --git a/config/configgrpc/configgrpc_test.go b/config/configgrpc/configgrpc_test.go index bcab6164f36..2b056b4f97a 100644 --- a/config/configgrpc/configgrpc_test.go +++ b/config/configgrpc/configgrpc_test.go @@ -76,7 +76,7 @@ func TestDefaultGrpcServerSettings(t *testing.T) { gss := &GRPCServerSettings{} opts, err := gss.ToServerOption(map[config.ComponentID]component.Extension{}) assert.NoError(t, err) - assert.Len(t, opts, 0) + assert.Len(t, opts, 1) } func TestAllGrpcServerSettingsExceptAuth(t *testing.T) { @@ -109,7 +109,7 @@ func TestAllGrpcServerSettingsExceptAuth(t *testing.T) { } opts, err := gss.ToServerOption(map[config.ComponentID]component.Extension{}) assert.NoError(t, err) - assert.Len(t, opts, 7) + assert.Len(t, opts, 8) } func TestGrpcServerAuthSettings(t *testing.T) { diff --git a/exporter/otlpexporter/otlp_test.go b/exporter/otlpexporter/otlp_test.go index 446904ebea2..5cbc9d61196 100644 --- a/exporter/otlpexporter/otlp_test.go +++ b/exporter/otlpexporter/otlp_test.go @@ -35,7 +35,6 @@ import ( "go.opentelemetry.io/collector/consumer/pdata" "go.opentelemetry.io/collector/internal/pdatagrpc" "go.opentelemetry.io/collector/internal/testdata" - "go.opentelemetry.io/collector/obsreport" ) type mockReceiver struct { @@ -76,7 +75,7 @@ func (r *mockTracesReceiver) GetLastRequest() pdata.Traces { func otlpTracesReceiverOnGRPCServer(ln net.Listener) *mockTracesReceiver { rcv := &mockTracesReceiver{ mockReceiver: mockReceiver{ - srv: obsreport.GRPCServerWithObservabilityEnabled(), + srv: grpc.NewServer(), }, } @@ -113,7 +112,7 @@ func (r *mockLogsReceiver) GetLastRequest() pdata.Logs { func otlpLogsReceiverOnGRPCServer(ln net.Listener) *mockLogsReceiver { rcv := &mockLogsReceiver{ mockReceiver: mockReceiver{ - srv: obsreport.GRPCServerWithObservabilityEnabled(), + srv: grpc.NewServer(), }, } @@ -151,7 +150,7 @@ func (r *mockMetricsReceiver) GetLastRequest() pdata.Metrics { func otlpMetricsReceiverOnGRPCServer(ln net.Listener) *mockMetricsReceiver { rcv := &mockMetricsReceiver{ mockReceiver: mockReceiver{ - srv: obsreport.GRPCServerWithObservabilityEnabled(), + srv: grpc.NewServer(), }, } diff --git a/obsreport/observability.go b/obsreport/observability.go deleted file mode 100644 index 323d6494e5e..00000000000 --- a/obsreport/observability.go +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// 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 obsreport - -// This file contains helpers that are useful to add observability -// with metrics and tracing using OpenCensus to the various pieces -// of the service. - -import ( - "go.opencensus.io/plugin/ocgrpc" - "google.golang.org/grpc" -) - -// GRPCServerWithObservabilityEnabled creates a gRPC server that at a bare minimum has -// the OpenCensus ocgrpc server stats handler enabled for tracing and stats. -// Use it instead of invoking grpc.NewServer directly. -func GRPCServerWithObservabilityEnabled(extraOpts ...grpc.ServerOption) *grpc.Server { - return grpc.NewServer(append(extraOpts, grpc.StatsHandler(&ocgrpc.ServerHandler{}))...) -} diff --git a/receiver/opencensusreceiver/ocmetrics/opencensus_test.go b/receiver/opencensusreceiver/ocmetrics/opencensus_test.go index 1e795152461..3663da2b8c0 100644 --- a/receiver/opencensusreceiver/ocmetrics/opencensus_test.go +++ b/receiver/opencensusreceiver/ocmetrics/opencensus_test.go @@ -43,7 +43,6 @@ import ( "go.opentelemetry.io/collector/consumer/consumertest" "go.opentelemetry.io/collector/exporter/opencensusexporter" "go.opentelemetry.io/collector/internal/testdata" - "go.opentelemetry.io/collector/obsreport" "go.opentelemetry.io/collector/translator/internaldata" ) @@ -365,7 +364,7 @@ func ocReceiverOnGRPCServer(t *testing.T, sr consumer.Metrics) (net.Addr, func() require.NoError(t, err, "Failed to create the Receiver: %v", err) // Now run it as a gRPC server - srv := obsreport.GRPCServerWithObservabilityEnabled() + srv := grpc.NewServer() agentmetricspb.RegisterMetricsServiceServer(srv, oci) go func() { _ = srv.Serve(ln) diff --git a/receiver/opencensusreceiver/octrace/opencensus_test.go b/receiver/opencensusreceiver/octrace/opencensus_test.go index f989cf2d06f..831bf467d62 100644 --- a/receiver/opencensusreceiver/octrace/opencensus_test.go +++ b/receiver/opencensusreceiver/octrace/opencensus_test.go @@ -29,6 +29,7 @@ import ( tracepb "github.com/census-instrumentation/opencensus-proto/gen-go/trace/v1" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.opencensus.io/plugin/ocgrpc" "go.uber.org/zap" "google.golang.org/grpc" "google.golang.org/protobuf/proto" @@ -40,7 +41,6 @@ import ( "go.opentelemetry.io/collector/consumer/consumertest" "go.opentelemetry.io/collector/exporter/opencensusexporter" "go.opentelemetry.io/collector/internal/testdata" - "go.opentelemetry.io/collector/obsreport" "go.opentelemetry.io/collector/translator/internaldata" ) @@ -378,7 +378,7 @@ func ocReceiverOnGRPCServer(t *testing.T, sr consumer.Traces) (net.Addr, func()) require.NoError(t, err, "Failed to create the Receiver: %v", err) // Now run it as a gRPC server - srv := obsreport.GRPCServerWithObservabilityEnabled() + srv := grpc.NewServer(grpc.StatsHandler(&ocgrpc.ServerHandler{})) agenttracepb.RegisterTraceServiceServer(srv, oci) go func() { _ = srv.Serve(ln) diff --git a/receiver/opencensusreceiver/opencensus.go b/receiver/opencensusreceiver/opencensus.go index 1b8ff8c5b5f..805fdd52e10 100644 --- a/receiver/opencensusreceiver/opencensus.go +++ b/receiver/opencensusreceiver/opencensus.go @@ -33,7 +33,6 @@ import ( "go.opentelemetry.io/collector/config" "go.opentelemetry.io/collector/config/configgrpc" "go.opentelemetry.io/collector/consumer" - "go.opentelemetry.io/collector/obsreport" "go.opentelemetry.io/collector/receiver/opencensusreceiver/ocmetrics" "go.opentelemetry.io/collector/receiver/opencensusreceiver/octrace" ) @@ -177,7 +176,7 @@ func (ocr *ocReceiver) grpcServer(host component.Host) (*grpc.Server, error) { if err != nil { return nil, err } - ocr.serverGRPC = obsreport.GRPCServerWithObservabilityEnabled(opts...) + ocr.serverGRPC = grpc.NewServer(opts...) } return ocr.serverGRPC, nil diff --git a/receiver/otlpreceiver/logs/otlp_test.go b/receiver/otlpreceiver/logs/otlp_test.go index 93a21837903..811f427bb61 100644 --- a/receiver/otlpreceiver/logs/otlp_test.go +++ b/receiver/otlpreceiver/logs/otlp_test.go @@ -30,7 +30,6 @@ import ( collectorlog "go.opentelemetry.io/collector/internal/data/protogen/collector/logs/v1" "go.opentelemetry.io/collector/internal/pdatagrpc" "go.opentelemetry.io/collector/internal/testdata" - "go.opentelemetry.io/collector/obsreport" ) func TestExport(t *testing.T) { @@ -116,7 +115,7 @@ func otlpReceiverOnGRPCServer(t *testing.T, tc consumer.Logs) (net.Addr, func()) require.NoError(t, err) // Now run it as a gRPC server - srv := obsreport.GRPCServerWithObservabilityEnabled() + srv := grpc.NewServer() collectorlog.RegisterLogsServiceServer(srv, r) go func() { _ = srv.Serve(ln) diff --git a/receiver/otlpreceiver/metrics/otlp_test.go b/receiver/otlpreceiver/metrics/otlp_test.go index 896f4a52620..59247c95065 100644 --- a/receiver/otlpreceiver/metrics/otlp_test.go +++ b/receiver/otlpreceiver/metrics/otlp_test.go @@ -30,7 +30,6 @@ import ( collectormetrics "go.opentelemetry.io/collector/internal/data/protogen/collector/metrics/v1" "go.opentelemetry.io/collector/internal/pdatagrpc" "go.opentelemetry.io/collector/internal/testdata" - "go.opentelemetry.io/collector/obsreport" ) func TestExport(t *testing.T) { @@ -123,7 +122,7 @@ func otlpReceiverOnGRPCServer(t *testing.T, mc consumer.Metrics) (net.Addr, func r := New(receiverID, mc) // Now run it as a gRPC server - srv := obsreport.GRPCServerWithObservabilityEnabled() + srv := grpc.NewServer() collectormetrics.RegisterMetricsServiceServer(srv, r) go func() { _ = srv.Serve(ln) diff --git a/receiver/otlpreceiver/trace/otlp_test.go b/receiver/otlpreceiver/trace/otlp_test.go index a40cfabddfd..ba2590d5b02 100644 --- a/receiver/otlpreceiver/trace/otlp_test.go +++ b/receiver/otlpreceiver/trace/otlp_test.go @@ -30,7 +30,6 @@ import ( collectortrace "go.opentelemetry.io/collector/internal/data/protogen/collector/trace/v1" "go.opentelemetry.io/collector/internal/pdatagrpc" "go.opentelemetry.io/collector/internal/testdata" - "go.opentelemetry.io/collector/obsreport" ) func TestExport(t *testing.T) { @@ -118,7 +117,7 @@ func otlpReceiverOnGRPCServer(t *testing.T, tc consumer.Traces) (net.Addr, func( require.NoError(t, err) // Now run it as a gRPC server - srv := obsreport.GRPCServerWithObservabilityEnabled() + srv := grpc.NewServer() collectortrace.RegisterTraceServiceServer(srv, r) go func() { _ = srv.Serve(ln)