Skip to content

Commit

Permalink
[chore][configgrpc] Move MetricsLevel check to MeterProvider creation (
Browse files Browse the repository at this point in the history
…#12158)

<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description

<!-- Issue number if applicable -->

Same as #12126, but for `otelgrpc`: drops `otelgrpc` metrics depending
of level with a view instead of passing a noop `MeterProvider`

#### Link to tracking issue

Updates #11061
  • Loading branch information
mx-psi authored Jan 22, 2025
1 parent b844bb7 commit 461a355
Show file tree
Hide file tree
Showing 13 changed files with 29 additions and 25 deletions.
2 changes: 1 addition & 1 deletion cmd/otelcorecol/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ require (
go.opentelemetry.io/collector/service v0.118.0 // indirect
go.opentelemetry.io/contrib/bridges/otelzap v0.9.0 // indirect
go.opentelemetry.io/contrib/config v0.10.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.56.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.59.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.56.0 // indirect
go.opentelemetry.io/contrib/propagators/b3 v1.31.0 // indirect
go.opentelemetry.io/contrib/zpages v0.56.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions cmd/otelcorecol/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 2 additions & 12 deletions config/configgrpc/configgrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ import (
"github.com/mostynb/go-grpc-compression/nonclobbering/zstd"
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/noop"
"google.golang.org/grpc"
"google.golang.org/grpc/balancer"
"google.golang.org/grpc/codes"
Expand All @@ -35,7 +33,6 @@ import (
"go.opentelemetry.io/collector/config/configcompression"
"go.opentelemetry.io/collector/config/confignet"
"go.opentelemetry.io/collector/config/configopaque"
"go.opentelemetry.io/collector/config/configtelemetry"
"go.opentelemetry.io/collector/config/configtls"
"go.opentelemetry.io/collector/extension/auth"
)
Expand Down Expand Up @@ -338,7 +335,7 @@ func (gcs *ClientConfig) getGrpcDialOptions(
otelOpts := []otelgrpc.Option{
otelgrpc.WithTracerProvider(settings.TracerProvider),
otelgrpc.WithPropagators(otel.GetTextMapPropagator()),
otelgrpc.WithMeterProvider(getLeveledMeterProvider(settings)),
otelgrpc.WithMeterProvider(settings.MeterProvider),
}

// Enable OpenTelemetry observability plugin.
Expand Down Expand Up @@ -477,7 +474,7 @@ func (gss *ServerConfig) getGrpcServerOptions(
otelOpts := []otelgrpc.Option{
otelgrpc.WithTracerProvider(settings.TracerProvider),
otelgrpc.WithPropagators(otel.GetTextMapPropagator()),
otelgrpc.WithMeterProvider(getLeveledMeterProvider(settings)),
otelgrpc.WithMeterProvider(settings.MeterProvider),
}

// Enable OpenTelemetry observability plugin.
Expand Down Expand Up @@ -571,10 +568,3 @@ func authStreamServerInterceptor(srv any, stream grpc.ServerStream, _ *grpc.Stre

return handler(srv, wrapServerStream(ctx, stream))
}

func getLeveledMeterProvider(settings component.TelemetrySettings) metric.MeterProvider {
if configtelemetry.LevelDetailed <= settings.MetricsLevel {
return settings.MeterProvider
}
return noop.MeterProvider{}
}
4 changes: 2 additions & 2 deletions config/configgrpc/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@ require (
go.opentelemetry.io/collector/config/configcompression v1.24.0
go.opentelemetry.io/collector/config/confignet v1.24.0
go.opentelemetry.io/collector/config/configopaque v1.24.0
go.opentelemetry.io/collector/config/configtelemetry v0.118.0
go.opentelemetry.io/collector/config/configtls v1.24.0
go.opentelemetry.io/collector/extension/auth v0.118.0
go.opentelemetry.io/collector/extension/auth/authtest v0.118.0
go.opentelemetry.io/collector/pdata v1.24.0
go.opentelemetry.io/collector/pdata/testdata v0.118.0
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.56.0
go.opentelemetry.io/otel v1.34.0
go.opentelemetry.io/otel/metric v1.34.0
go.uber.org/goleak v1.3.0
google.golang.org/grpc v1.69.4
)
Expand All @@ -39,8 +37,10 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
go.opentelemetry.io/collector/config/configtelemetry v0.118.0 // indirect
go.opentelemetry.io/collector/extension v0.118.0 // indirect
go.opentelemetry.io/collector/pdata/pprofile v0.118.0 // indirect
go.opentelemetry.io/otel/metric v1.34.0 // indirect
go.opentelemetry.io/otel/sdk v1.34.0 // indirect
go.opentelemetry.io/otel/sdk/metric v1.34.0 // indirect
go.opentelemetry.io/otel/trace v1.34.0 // indirect
Expand Down
2 changes: 1 addition & 1 deletion internal/e2e/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ require (
go.opentelemetry.io/collector/semconv v0.118.0 // indirect
go.opentelemetry.io/contrib/bridges/otelzap v0.9.0 // indirect
go.opentelemetry.io/contrib/config v0.10.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.56.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.59.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.56.0 // indirect
go.opentelemetry.io/contrib/propagators/b3 v1.31.0 // indirect
go.opentelemetry.io/otel v1.34.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions internal/e2e/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions otelcol/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ require (
go.opentelemetry.io/collector/receiver/xreceiver v0.118.0 // indirect
go.opentelemetry.io/collector/semconv v0.118.0 // indirect
go.opentelemetry.io/contrib/bridges/otelzap v0.9.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.59.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.56.0 // indirect
go.opentelemetry.io/contrib/propagators/b3 v1.31.0 // indirect
go.opentelemetry.io/otel v1.34.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions otelcol/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions otelcol/otelcoltest/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ require (
go.opentelemetry.io/collector/semconv v0.118.0 // indirect
go.opentelemetry.io/contrib/bridges/otelzap v0.9.0 // indirect
go.opentelemetry.io/contrib/config v0.10.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.59.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.56.0 // indirect
go.opentelemetry.io/contrib/propagators/b3 v1.31.0 // indirect
go.opentelemetry.io/otel v1.34.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions otelcol/otelcoltest/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions service/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ require (
go.opentelemetry.io/collector/semconv v0.118.0
go.opentelemetry.io/contrib/bridges/otelzap v0.9.0
go.opentelemetry.io/contrib/config v0.10.0
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.59.0
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.56.0
go.opentelemetry.io/contrib/propagators/b3 v1.31.0
go.opentelemetry.io/otel v1.34.0
Expand Down
2 changes: 2 additions & 0 deletions service/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 10 additions & 5 deletions service/telemetry/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"net/http"
"sync"

"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/noop"
Expand Down Expand Up @@ -68,11 +69,15 @@ func newMeterProvider(set meterProviderSettings, disableHighCardinality bool) (m
}

if set.cfg.Level < configtelemetry.LevelDetailed {
// Drop all otelhttp metrics if the level is not detailed.
opts = append(opts, dropViewOption(sdkmetric.Instrument{
Scope: instrumentation.Scope{Name: otelhttp.ScopeName},
},
))
// Drop all otelhttp and otelgrpc metrics if the level is not detailed.
opts = append(opts,
dropViewOption(sdkmetric.Instrument{
Scope: instrumentation.Scope{Name: otelhttp.ScopeName},
}),
dropViewOption(sdkmetric.Instrument{
Scope: instrumentation.Scope{Name: otelgrpc.ScopeName},
}),
)
}

// otel-arrow library metrics
Expand Down

0 comments on commit 461a355

Please sign in to comment.