Skip to content

Commit

Permalink
put otel meter for http/grpc behind a FF (#202)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaronoff97 committed Apr 18, 2023
1 parent 8e95d8f commit b654e2b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
6 changes: 5 additions & 1 deletion config/configgrpc/configgrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import (
"go.opentelemetry.io/collector/config/configtls"
"go.opentelemetry.io/collector/config/internal"
"go.opentelemetry.io/collector/extension/auth"
"go.opentelemetry.io/collector/internal/obsreportconfig"
)

var errMetadataNotFound = errors.New("no request metadata found")
Expand Down Expand Up @@ -260,10 +261,13 @@ func (gcs *GRPCClientSettings) toDialOptions(host component.Host, settings compo

otelOpts := []otelgrpc.Option{
otelgrpc.WithTracerProvider(settings.TracerProvider),
otelgrpc.WithMeterProvider(settings.MeterProvider),
otelgrpc.WithPropagators(otel.GetTextMapPropagator()),
}

if obsreportconfig.EnableHighCardinalityMetricsfeatureGate.IsEnabled() {
otelOpts = append(otelOpts, otelgrpc.WithMeterProvider(settings.MeterProvider))
}

// Enable OpenTelemetry observability plugin.
opts = append(opts, grpc.WithUnaryInterceptor(otelgrpc.UnaryClientInterceptor(otelOpts...)))
opts = append(opts, grpc.WithStreamInterceptor(otelgrpc.StreamClientInterceptor(otelOpts...)))
Expand Down
12 changes: 9 additions & 3 deletions config/confighttp/confighttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"go.opentelemetry.io/collector/config/configtls"
"go.opentelemetry.io/collector/config/internal"
"go.opentelemetry.io/collector/extension/auth"
"go.opentelemetry.io/collector/internal/obsreportconfig"
)

const headerContentEncoding = "Content-Encoding"
Expand Down Expand Up @@ -143,11 +144,16 @@ func (hcs *HTTPClientSettings) ToClient(host component.Host, settings component.
}
// wrapping http transport with otelhttp transport to enable otel instrumenetation
if settings.TracerProvider != nil && settings.MeterProvider != nil {
clientTransport = otelhttp.NewTransport(
clientTransport,
otelOpts := []otelhttp.Option{
otelhttp.WithTracerProvider(settings.TracerProvider),
otelhttp.WithMeterProvider(settings.MeterProvider),
otelhttp.WithPropagators(otel.GetTextMapPropagator()),
}
if obsreportconfig.EnableHighCardinalityMetricsfeatureGate.IsEnabled() {
otelOpts = append(otelOpts, otelhttp.WithMeterProvider(settings.MeterProvider))
}
clientTransport = otelhttp.NewTransport(
clientTransport,
otelOpts...,
)
}

Expand Down
8 changes: 8 additions & 0 deletions internal/obsreportconfig/obsreportconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ var UseOtelForInternalMetricsfeatureGate = featuregate.GlobalRegistry().MustRegi
featuregate.StageAlpha,
featuregate.WithRegisterDescription("controls whether the collector uses OpenTelemetry for internal metrics"))

// EnableHighCardinalityMetricsfeatureGate is the feature gate that controls whether the collecor should enable
// potentially high cardinality metrics.
var EnableHighCardinalityMetricsfeatureGate = featuregate.GlobalRegistry().MustRegister(
"telemetry.enableHighCardinalityMetrics",
featuregate.StageAlpha,
featuregate.WithRegisterDescription("controls whether the collecor should enable potentially high"+
"cardinality metrics."))

// AllViews returns all the OpenCensus views requires by obsreport package.
func AllViews(level configtelemetry.Level) []*view.View {
if level == configtelemetry.LevelNone {
Expand Down

0 comments on commit b654e2b

Please sign in to comment.