Both SetSendCompressor and downcast the the ServerTransport to a concrete struct (*transport.ServerStream) to call methods which are not available on the ServerTransport interface.
|
func SetSendCompressor(ctx context.Context, name string) error { |
|
stream, ok := ServerTransportStreamFromContext(ctx).(*transport.ServerStream) |
|
if !ok || stream == nil { |
|
return fmt.Errorf("failed to fetch the stream from the given context") |
|
} |
|
func ClientSupportedCompressors(ctx context.Context) ([]string, error) { |
|
stream, ok := ServerTransportStreamFromContext(ctx).(*transport.ServerStream) |
|
if !ok || stream == nil { |
|
return nil, fmt.Errorf("failed to fetch the stream from the given context %v", ctx) |
|
} |
The Opentelemetry plugin wraps the ServerTransport type for unary calls, which causes the downcasts to fail:
|
func (h *serverMetricsHandler) unaryInterceptor(ctx context.Context, req any, _ *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (any, error) { |
|
var metadataExchangeLabels metadata.MD |
|
if h.options.MetricsOptions.pluginOption != nil { |
|
metadataExchangeLabels = h.options.MetricsOptions.pluginOption.GetMetadata() |
|
} |
|
|
|
sts := grpc.ServerTransportStreamFromContext(ctx) |
|
|
|
alts := &attachLabelsTransportStream{ |
|
ServerTransportStream: sts, |
|
metadataExchangeLabels: metadataExchangeLabels, |
|
} |
|
ctx = grpc.NewContextWithServerTransportStream(ctx, alts) |
Both
SetSendCompressorand downcast the theServerTransportto a concrete struct (*transport.ServerStream) to call methods which are not available on theServerTransportinterface.grpc-go/server.go
Lines 2153 to 2157 in 5fdb6d0
grpc-go/server.go
Lines 2175 to 2179 in 5fdb6d0
The Opentelemetry plugin wraps the
ServerTransporttype for unary calls, which causes the downcasts to fail:grpc-go/stats/opentelemetry/server_metrics.go
Lines 93 to 105 in 5fdb6d0