Repository: grpc/grpc-go
File: stats/opentelemetry/opentelemetry.go (Go)

Code before:

	// OptionalLabels specifies a list of optional labels to enable on any
	// metrics that support them.
	OptionalLabels []string

	// pluginOption is used to get labels to attach to certain metrics, if set.
	pluginOption otelinternal.PluginOption
}

// DialOption returns a dial option which enables OpenTelemetry instrumentation
// code for a grpc.ClientConn.
//
// Client applications interested in instrumenting their grpc.ClientConn should
// pass the dial option returned from this function as a dial option to
// grpc.NewClient().
//
// For the metrics supported by this instrumentation code, specify the client
// metrics to record in metrics options. Also provide an implementation of a
// MeterProvider. If the passed in Meter Provider does not have the view
// configured for an individual metric turned on, the API call in this component
// will create a default view for that metric.
func DialOption(o Options) grpc.DialOption {
	var do []grpc.DialOption

	if o.isMetricsEnabled() {
		metricsHandler := &clientStatsHandler{
			MetricsRecorder: &registryMetrics{optionalLabels: o.MetricsOptions.OptionalLabels},
			options:         o,
			clientMetrics:   clientMetrics{},
		}
		metricsHandler.initializeMetrics()
		do = append(do,
			grpc.WithChainUnaryInterceptor(metricsHandler.unaryInterceptor),
			grpc.WithChainStreamInterceptor(metricsHandler.streamInterceptor),
			grpc.WithStatsHandler(metricsHandler),
		)
	}
	if o.isTracingEnabled() {
		tracingHandler := &clientTracingHandler{
			options: o,
		}
		tracingHandler.initializeTraces()
		do = append(do,
			grpc.WithChainUnaryInterceptor(tracingHandler.unaryInterceptor),
			grpc.WithChainStreamInterceptor(tracingHandler.streamInterceptor),
			grpc.WithStatsHandler(tracingHandler),
		)
	}
	return joinDialOptions(do...)
}


Review comment (refactor):
why are we adding these new changes? We should keep the current part as is and only add the tracing part. Please revert the refactor changes done for clientStatsHandler here 

```
csh := &clientStatsHandler{options: o}
	csh.initializeMetrics()
	do := joinDialOptions(grpc.WithChainUnaryInterceptor(csh.unaryInterceptor), grpc.WithChainStreamInterceptor(csh.streamInterceptor), grpc.WithStatsHandler(csh))

if o.isTracingEnabled(){
...
do := joinDialOptions(grpc.WithChainUnaryInterceptor(th.unaryInterceptor),.....)
}

return do
```

Code after:
	MethodAttributeFilter func(string) bool

	// OptionalLabels specifies a list of optional labels to enable on any
	// metrics that support them.
	OptionalLabels []string

	// pluginOption is used to get labels to attach to certain metrics, if set.
	pluginOption otelinternal.PluginOption
}

// DialOption returns a dial option which enables OpenTelemetry instrumentation
// code for a grpc.ClientConn.
//
// Client applications interested in instrumenting their grpc.ClientConn should
// pass the dial option returned from this function as a dial option to
// grpc.NewClient().
//
// For the metrics supported by this instrumentation code, specify the client
// metrics to record in metrics options. Also provide an implementation of a
// MeterProvider. If the passed in Meter Provider does not have the view
// configured for an individual metric turned on, the API call in this component
// will create a default view for that metric.
//
// For the traces supported by this instrumentation code, provide an
// implementation of a TextMapPropagator and OpenTelemetry TracerProvider.
func DialOption(o Options) grpc.DialOption {
	var metricsOpts, tracingOpts []grpc.DialOption

	if o.isMetricsEnabled() {
		metricsHandler := &clientMetricsHandler{options: o}
		metricsHandler.initializeMetrics()
		metricsOpts = append(metricsOpts, grpc.WithChainUnaryInterceptor(metricsHandler.unaryInterceptor), grpc.WithChainStreamInterceptor(metricsHandler.streamInterceptor), grpc.WithStatsHandler(metricsHandler))
	}
	if o.isTracingEnabled() {
		tracingHandler := &clientTracingHandler{options: o}
		tracingHandler.initializeTraces()
		tracingOpts = append(tracingOpts, grpc.WithChainUnaryInterceptor(tracingHandler.unaryInterceptor), grpc.WithChainStreamInterceptor(tracingHandler.streamInterceptor), grpc.WithStatsHandler(tracingHandler))
	}
	return joinDialOptions(append(metricsOpts, tracingOpts...)...)
}

var joinServerOptions = internal.JoinServerOptions.(func(...grpc.ServerOption) grpc.ServerOption)

// ServerOption returns a server option which enables OpenTelemetry
// instrumentation code for a grpc.Server.
//
// Server applications interested in instrumenting their grpc.Server should pass
// the server option returned from this function as an argument to
// grpc.NewServer().
//
// For the metrics supported by this instrumentation code, specify the server