Skip to content

server: ClientSupportedCompressors and SetSendCompressor break when using Opentelemetry metrics plugin #9047

@arjan-bal

Description

@arjan-bal

Both SetSendCompressor and downcast the the ServerTransport to a concrete struct (*transport.ServerStream) to call methods which are not available on the ServerTransport interface.

grpc-go/server.go

Lines 2153 to 2157 in 5fdb6d0

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")
}

grpc-go/server.go

Lines 2175 to 2179 in 5fdb6d0

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area: ServerIncludes Server, Streams and Server Options.Type: Bug

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions