interceptors

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 22, 2025 License: MIT Imports: 5 Imported by: 0

README

interceptors: Goa Interceptors

Build Status Go Reference

Overview

Package interceptors provides a set of Goa interceptors that are helpful when writing microservices.

The following interceptor families are available:

  • Trace Stream: these interceptor structs and functions allow OpenTelemetry tracing of individual messages of a Goa stream whether it is bidirectional, client to server, or server to client. There are interceptor structs and functions for use both as client and server interceptors.

Trace Stream

The Trace Stream family of interceptor structs and functions can be used to trace the individual messages of a Goa stream. This differs from the OpenTelemetry HTTP middleware and gRPC stats handler in that it traces the individual messages of a stream rather than the entire stream which could be long running.

The available Trace Stream interceptor structs are:

  • TraceBidirectionalStreamClientInterceptor: intercepts a bidirectional stream when used as a client interceptor.
  • TraceServerToClientStreamClientInterceptor: intercepts a server to client stream when used as a client interceptor.
  • TraceClientToServerStreamClientInterceptor: intercepts a client to server stream when used as a client interceptor.
  • TraceBidirectionalStreamServerInterceptor: intercepts a bidirectional stream when used as a server interceptor.
  • TraceServerToClientStreamServerInterceptor: intercepts a server to client stream when used as a server interceptor.
  • TraceClientToServerStreamServerInterceptor: intercepts a client to server stream when used as a server interceptor.

The available Trace Stream interceptor functions are:

  • TraceBidirectionalStreamClient: traces a bidirectional stream when used as a client interceptor.
  • TraceServerToClientStreamClient: traces a server to client stream when used as a client interceptor.
  • TraceClientToServerStreamClient: traces a client to server stream when used as a client interceptor.
  • TraceBidirectionalStreamServer: traces a bidirectional stream when used as a server interceptor.
  • TraceServerToClientStreamServer: traces a server to client stream when used as a server interceptor.
  • TraceClientToServerStreamServer: traces a client to server stream when used as a server interceptor.

There are also a set of helper functions that should be used within Goa service method implementations in order to enable propagation of trace metadata received from streams to a context:

  • SetupTraceStreamRecvContext: returns a context to be used with the receive method of a stream.
  • GetTraceStreamRecvContext: returns a context with trace metadata after calling the receive method of a stream.

As a convenience, there are also functions that wrap streams with an interface that handles the work of calling the SetupTraceStreamRecvContext and GetTraceStreamRecvContext helper functions:

  • WrapTraceBidirectionalStreamClientStream: wraps a client stream for a bidirectional stream.
  • WrapTraceServerToClientStreamClientStream: wraps a client stream for a server to client stream.
  • WrapTraceClientToServerStreamWithResultClientStream: wraps a client stream for a client to server stream with a result.
  • WrapTraceBidirectionalStreamServerStream: wraps a server stream for a bidirectional stream.
  • WrapTraceServerToClientStreamServerStream: wraps a server stream for a server to client stream.
  • WrapTraceClientToServerStreamWithResultServerStream: wraps a server stream for a client to server stream with a result.

These interceptor functions will work best if you also set up OpenTelemetry instrumentation for your service using the clue package.

Usage

In your Goa design, you can define the bidirectional, client to server, and/or server to client Trace Stream interceptors as follows:

var TraceBidirectionalStream = Interceptor("TraceBidirectionalStream", func() {
    WriteStreamingPayload(func() {
        Attribute("TraceMetadata", MapOf(String, String))
    })
    ReadStreamingPayload(func() {
        Attribute("TraceMetadata", MapOf(String, String))
    })
    WriteStreamingResult(func() {
        Attribute("TraceMetadata", MapOf(String, String))
    })
    ReadStreamingResult(func() {
        Attribute("TraceMetadata", MapOf(String, String))
    })
})

var TraceServerToClientStream = Interceptor("TraceServerToClientStream", func() {
    WriteStreamingResult(func() {
        Attribute("TraceMetadata", MapOf(String, String))
    })
    ReadStreamingResult(func() {
        Attribute("TraceMetadata", MapOf(String, String))
    })
})

var TraceClientToServerStream = Interceptor("TraceClientToServerStream", func() {
    WriteStreamingPayload(func() {
        Attribute("TraceMetadata", MapOf(String, String))
    })
    ReadStreamingPayload(func() {
        Attribute("TraceMetadata", MapOf(String, String))
    })
})

In the Goa service method definitions where you want to use one of the interceptors, you should specify it as both a client and server interceptor:

    Method("MyBidirectionalStreamMethod", func() {
        ClientInterceptor(TraceBidirectionalStream)
        ServerInterceptor(TraceBidirectionalStream)

        ...
    })

    Method("MyServerToClientStreamMethod", func() {
        ClientInterceptor(TraceServerToClientStream)
        ServerInterceptor(TraceServerToClientStream)

        ...
    })

    Method("MyClientToServerStreamMethod", func() {
        ClientInterceptor(TraceClientToServerStream)
        ServerInterceptor(TraceClientToServerStream)

        ...
    })

In the streaming payload and/or result definitions, you should define the TraceMetadata attribute or field:

        Attribute("TraceMetadata", MapOf(String, String))  // for HTTP
        Field(101, "TraceMetadata", MapOf(String, String)) // for gRPC

You should generate code from your Goa design as usual using goa gen. If you are starting a new service, you can also use goa example to bootstrap it along with examples of the service client and server interceptors.

In your implementation of the service client and server interceptors interfaces, you can call the provided interceptor functions:

import (
    ...
    "goa.design/clue/interceptors"
)

...

func (i *MyServiceClientInterceptors) TraceBidirectionalStream(ctx context.Context, info *genmyservice.TraceBidirectionalStream, next goa.InterceptorEndpoint) (any, context.Context, error) {
    return interceptors.TraceBidirectionalStreamClient(ctx, info, next)
}

func (i *MyServiceClientInterceptors) TraceServerToClientStream(ctx context.Context, info *genmyservice.TraceServerToClientStream, next goa.InterceptorEndpoint) (any, context.Context, error) {
    return interceptors.TraceServerToClientStreamClient(ctx, info, next)
}

func (i *MyServiceClientInterceptors) TraceClientToServerStream(ctx context.Context, info *genmyservice.TraceClientToServerStream, next goa.InterceptorEndpoint) (any, context.Context, error) {
    return interceptors.TraceClientToServerStreamClient(ctx, info, next)
}

func (i *MyServerServiceInterceptors) TraceBidirectionalStream(ctx context.Context, info *genmyservice.TraceBidirectionalStreamInfo, next goa.InterceptorEndpoint) (any, context.Context, error) {
    return interceptors.TraceBidirectionalStreamServer(ctx, info, next)
}

func (i *MyServerServiceInterceptors) TraceServerToClientStream(ctx context.Context, info *genmyservice.TraceServerToClientStreamInfo, next goa.InterceptorEndpoint) (any, context.Context, error) {
    return interceptors.TraceServerToClientStreamServer(ctx, info, next)
}

func (i *MyServerServiceInterceptors) TraceClientToServerStream(ctx context.Context, info *genmyservice.TraceClientToServerStreamInfo, next goa.InterceptorEndpoint) (any, context.Context, error) {
    return interceptors.TraceClientToServerStreamServer(ctx, info, next)
}

The interceptor functions take advantage of Go generics to work out of the box with the generated types of your service as long as you define your interceptors as above.

Alternatively, you can embed the interceptor structs in your interceptor implementations:

import (
    ...
    "goa.design/clue/interceptors"
)

...

type MyServiceClientInterceptors struct {
    interceptors.TraceBidirectionalStreamClientInterceptor[*genmyservice.TraceBidirectionalStreamInfo, genmyservice.MyBidirectionalStreamPayload, genmyservice.MyBidirectionalStreamResult]
    interceptors.TraceServerToClientStreamClientInterceptor[*genmyservice.TraceServerToClientStreamInfo, genmyservice.MyServerToClientStreamResult]
    interceptors.TraceClientToServerStreamClientInterceptor[*genmyservice.TraceClientToServerStreamInfo, genmyservice.MyClientToServerStreamPayload]
}

type MyServerServiceInterceptors struct {
    interceptors.TraceBidirectionalStreamServerInterceptor[*genmyservice.TraceBidirectionalStreamInfo, genmyservice.MyBidirectionalStreamPayload, genmyservice.MyBidirectionalStreamResult]
    interceptors.TraceServerToClientStreamServerInterceptor[*genmyservice.TraceServerToClientStreamInfo, genmyservice.MyServerToClientStreamResult]
    interceptors.TraceClientToServerStreamServerInterceptor[*genmyservice.TraceClientToServerStreamInfo, genmyservice.MyClientToServerStreamPayload]
}

Since generated Goa client and server interfaces do not return a context from their receive methods, you will need to use the helper functions to get the context with the extracted trace metadata after calling the receive method of the stream:

    ctx = interceptors.SetupTraceStreamRecvContext(ctx, stream)
    result, err := stream.RecvWithContext(ctx)
    ctx = interceptors.GetTraceStreamRecvContext(ctx)

Alternatively, you can wrap the stream with an interface that handles the work of calling the SetupTraceStreamRecvContext and GetTraceStreamRecvContext helper functions:

    ws := interceptors.WrapTraceBidirectionalStreamClientStream(stream)
    err := ws.Send(ctx, &genmyservice.MyBidirectionalStreamPayload{
        ...
    })
    ...
    ctx, result, err := ws.RecvAndReturnContext(ctx)
    ...
    err = ws.Close()

The wrapper functions and interfaces take advantage of Go generics to work out of the box with the generated types of your service.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetTraceStreamRecvContext

func GetTraceStreamRecvContext(ctx context.Context) context.Context

GetTraceStreamRecvContext returns the context with the extracted trace metadata after calling the receive method of a stream. The context must have been set up using the SetupTraceStreamRecvContext function.

func SetupTraceStreamRecvContext

func SetupTraceStreamRecvContext(ctx context.Context) context.Context

SetupTraceStreamRecvContext returns a copy of the context that is set up for use with the receive method of a stream so that the trace metadata can be extracted from the streaming payload or result. After the receive method of the stream returns, the GetTraceStreamRecvContext function can be used to retrieve the context with the extracted trace metadata.

func TraceBidirectionalStreamClient

func TraceBidirectionalStreamClient[Payload TraceStreamStreamingSendMessage, Result TraceStreamStreamingRecvMessage](
	ctx context.Context,
	info TraceBidirectionalStreamClientInfo[Payload, Result],
	next goa.Endpoint,
) (any, error)

TraceBidirectionalStreamClient is a client-side interceptor that traces a bidirectional stream by injecting the trace metadata into the streaming payload and extracting it from the streaming result. The injected trace metadata comes from the context passed to the send method of the client stream. The receive method of the client stream returns the extracted trace metadata in its context.

func TraceBidirectionalStreamServer

func TraceBidirectionalStreamServer[Payload TraceStreamStreamingRecvMessage, Result TraceStreamStreamingSendMessage](
	ctx context.Context,
	info TraceBidirectionalStreamServerInfo[Payload, Result],
	next goa.Endpoint,
) (any, error)

TraceBidirectionalStreamServer is a server-side interceptor that traces a bidirectional stream by injecting the trace metadata into the streaming result and extracting it from the streaming payload. The injected trace metadata comes from the context passed to the send method of the server stream. The receive method of the server stream returns the extracted trace metadata in its context.

func TraceClientToServerStreamClient

func TraceClientToServerStreamClient[Payload TraceStreamStreamingSendMessage](
	ctx context.Context,
	info ClientTraceStreamClientToServerInfo[Payload],
	next goa.Endpoint,
) (any, error)

TraceClientToServerStreamClient is a client-side interceptor that traces a client to server stream by injecting the trace metadata into the streaming payload. The injected trace metadata is returned in the context of the send method of the client stream.

func TraceClientToServerStreamServer

func TraceClientToServerStreamServer[Result TraceStreamStreamingRecvMessage](
	ctx context.Context,
	info ServerTraceStreamClientToServerInfo[Result],
	next goa.Endpoint,
) (any, error)

TraceClientToServerStreamServer is a server-side interceptor that traces a client to server stream by extracting the trace metadata from the streaming payload. The extracted trace metadata is returned in the context of the receive method of the server stream.

func TraceServerToClientStreamClient

func TraceServerToClientStreamClient[Result TraceStreamStreamingRecvMessage](
	ctx context.Context,
	info ClientTraceStreamServerToClientInfo[Result],
	next goa.Endpoint,
) (any, error)

TraceServerToClientStreamClient is a client-side interceptor that traces a server to client stream by extracting the trace metadata from the streaming result. The extracted trace metadata is returned in the context of the receive method of the client stream.

func TraceServerToClientStreamServer

func TraceServerToClientStreamServer[Result TraceStreamStreamingSendMessage](
	ctx context.Context,
	info ServerTraceStreamServerToClientInfo[Result],
	next goa.Endpoint,
) (any, error)

TraceServerToClientStreamServer is a server-side interceptor that traces a server to client stream by injecting the trace metadata into the streaming result. The injected trace metadata is returned in the context of the send method of the server stream.

Types

type ClientBidirectionalStream

type ClientBidirectionalStream[Payload any, Result any] interface {
	SendWithContext(ctx context.Context, payload Payload) error
	RecvWithContext(ctx context.Context) (Result, error)
	Close() error
}

ClientBidirectionalStream is an interface that matches the client stream for a bidirectional stream that can be wrapped with WrapTraceBidirectionalStreamClientStream.

type ClientClientToServerStreamWithResult

type ClientClientToServerStreamWithResult[Payload any, Result any] interface {
	SendWithContext(ctx context.Context, payload Payload) error
	CloseAndRecvWithContext(ctx context.Context) (Result, error)
}

ClientClientToServerStreamWithResult is an interface that matches the client stream for a client to server stream that can be wrapped with WrapTraceClientToServerStreamWithResultClientStream.

type ClientServerToClientStream

type ClientServerToClientStream[Result any] interface {
	RecvWithContext(ctx context.Context) (Result, error)
}

ClientServerToClientStream is an interface that matches the client stream for a server to client stream that can be wrapped with WrapTraceServerToClientStreamClientStream.

type ClientTraceStreamClientToServerInfo

type ClientTraceStreamClientToServerInfo[Payload TraceStreamStreamingSendMessage] interface {
	goa.InterceptorInfo

	ClientStreamingPayload() Payload
}

ClientTraceStreamClientToServerInfo is an interface that matches the interceptor info for a client to server stream that can be traced using TraceClientToServerStreamClient.

type ClientTraceStreamServerToClientInfo

type ClientTraceStreamServerToClientInfo[Result TraceStreamStreamingRecvMessage] interface {
	goa.InterceptorInfo

	ClientStreamingResult(res any) Result
}

ClientTraceStreamServerToClientInfo is an interface that matches the interceptor info for a server to client stream that can be traced using TraceServerToClientStreamClient.

type ServerBidirectionalStream

type ServerBidirectionalStream[Payload any, Result any] interface {
	SendWithContext(ctx context.Context, result Result) error
	RecvWithContext(ctx context.Context) (Payload, error)
	Close() error
}

ServerBidirectionalStream is an interface that matches the server stream for a bidirectional stream that can be wrapped with WrapTraceBidirectionalStreamServerStream.

type ServerClientToServerStream

type ServerClientToServerStream[Payload any] interface {
	RecvWithContext(ctx context.Context) (Payload, error)
	Close() error
}

ServerClientToServerStream is an interface that matches the server stream for a client to server stream that can be wrapped with WrapTraceClientToServerStreamServerStream.

type ServerClientToServerStreamWithResult

type ServerClientToServerStreamWithResult[Payload any, Result any] interface {
	CloseAndSendWithContext(ctx context.Context, result Result) error
	RecvWithContext(ctx context.Context) (Payload, error)
}

ServerClientToServerStreamWithResult is an interface that matches the server stream for a client to server stream that can be wrapped with WrapTraceClientToServerStreamWithResultServerStream.

type ServerTraceStreamClientToServerInfo

type ServerTraceStreamClientToServerInfo[Payload TraceStreamStreamingRecvMessage] interface {
	goa.InterceptorInfo

	ServerStreamingPayload(pay any) Payload
}

ServerTraceStreamClientToServerInfo is an interface that matches the interceptor info for a client to server stream that can be traced using TraceClientToServerStreamServer.

type ServerTraceStreamServerToClientInfo

type ServerTraceStreamServerToClientInfo[Result TraceStreamStreamingSendMessage] interface {
	goa.InterceptorInfo

	ServerStreamingResult() Result
}

ServerTraceStreamServerToClientInfo is an interface that matches the interceptor info for a server to client stream that can be traced using TraceServerToClientStreamServer.

type TraceBidirectionalStreamClientInfo

type TraceBidirectionalStreamClientInfo[Payload TraceStreamStreamingSendMessage, Result TraceStreamStreamingRecvMessage] interface {
	goa.InterceptorInfo

	ClientStreamingPayload() Payload
	ClientStreamingResult(res any) Result
}

TraceBidirectionalStreamClientInfo is an interface that matches the interceptor info for a bidirectional stream that can be traced using TraceBidirectionalStreamClient.

type TraceBidirectionalStreamClientInterceptor

type TraceBidirectionalStreamClientInterceptor[Info TraceBidirectionalStreamClientInfo[Payload, Result], Payload TraceStreamStreamingSendMessage, Result TraceStreamStreamingRecvMessage] struct{}

TraceBidirectionalStreamClientInterceptor is a client-side interceptor that traces a bidirectional stream by injecting the trace metadata into the streaming payload and extracting it from the streaming result. The injected trace metadata comes from the context passed to the send method of the client stream. The receive method of the client stream returns the extracted trace metadata in its context.

func (*TraceBidirectionalStreamClientInterceptor[Info, Payload, Result]) TraceBidirectionalStream

func (i *TraceBidirectionalStreamClientInterceptor[Info, Payload, Result]) TraceBidirectionalStream(ctx context.Context, info Info, next goa.Endpoint) (any, error)

TraceBidirectionalStream intercepts a bidirectional stream by injecting the trace metadata into the streaming payload and extracting it from the streaming result. The injected trace metadata comes from the context passed to the send method of the client stream. The receive method of the client stream returns the extracted trace metadata in its context.

type TraceBidirectionalStreamServerInfo

type TraceBidirectionalStreamServerInfo[Payload TraceStreamStreamingRecvMessage, Result TraceStreamStreamingSendMessage] interface {
	goa.InterceptorInfo

	ServerStreamingPayload(pay any) Payload
	ServerStreamingResult() Result
}

TraceBidirectionalStreamServerInfo is an interface that matches the interceptor info for a bidirectional stream that can be traced using TraceBidirectionalStreamServer.

type TraceBidirectionalStreamServerInterceptor

type TraceBidirectionalStreamServerInterceptor[Info TraceBidirectionalStreamServerInfo[Payload, Result], Payload TraceStreamStreamingRecvMessage, Result TraceStreamStreamingSendMessage] struct{}

TraceBidirectionalStreamServerInterceptor is a server-side interceptor that traces a bidirectional stream by injecting the trace metadata into the streaming payload and extracting it from the streaming result. The injected trace metadata comes from the context passed to the send method of the server stream. The receive method of the server stream returns the extracted trace metadata in its context.

func (*TraceBidirectionalStreamServerInterceptor[Info, Payload, Result]) TraceBidirectionalStream

func (i *TraceBidirectionalStreamServerInterceptor[Info, Payload, Result]) TraceBidirectionalStream(ctx context.Context, info Info, next goa.Endpoint) (any, error)

TraceBidirectionalStream intercepts a bidirectional stream by injecting the trace metadata into the streaming payload and extracting it from the streaming result. The injected trace metadata comes from the context passed to the send method of the server stream. The receive method of the server stream returns the extracted trace metadata in its context.

type TraceClientToServerStreamClientInterceptor

type TraceClientToServerStreamClientInterceptor[Info ClientTraceStreamClientToServerInfo[Payload], Payload TraceStreamStreamingSendMessage] struct{}

TraceClientToServerStreamClientInterceptor is a client-side interceptor that traces a client to server stream by injecting the trace metadata into the streaming payload. The injected trace metadata is returned in the context of the send method of the client stream.

func (*TraceClientToServerStreamClientInterceptor[Info, Payload]) TraceClientToServerStream

func (i *TraceClientToServerStreamClientInterceptor[Info, Payload]) TraceClientToServerStream(ctx context.Context, info Info, next goa.Endpoint) (any, error)

TraceClientToServerStream intercepts a client to server stream by injecting the trace metadata into the streaming payload. The injected trace metadata is returned in the context of the send method of the client stream.

type TraceClientToServerStreamServerInterceptor

type TraceClientToServerStreamServerInterceptor[Info ServerTraceStreamClientToServerInfo[Payload], Payload TraceStreamStreamingRecvMessage] struct{}

TraceClientToServerStreamServerInterceptor is a server-side interceptor that traces a client to server stream by extracting the trace metadata from the streaming payload. The extracted trace metadata is returned in the context of the receive method of the server stream.

func (*TraceClientToServerStreamServerInterceptor[Info, Payload]) TraceClientToServerStream

func (i *TraceClientToServerStreamServerInterceptor[Info, Payload]) TraceClientToServerStream(ctx context.Context, info Info, next goa.Endpoint) (any, error)

TraceClientToServerStream intercepts a client to server stream by extracting the trace metadata from the streaming payload. The extracted trace metadata is returned in the context of the receive method of the server stream.

type TraceServerToClientStreamClientInterceptor

type TraceServerToClientStreamClientInterceptor[Info ClientTraceStreamServerToClientInfo[Result], Result TraceStreamStreamingRecvMessage] struct{}

TraceServerToClientStreamClientInterceptor is a client-side interceptor that traces a server to client stream by extracting the trace metadata from the streaming result. The extracted trace metadata is returned in the context of the receive method of the client stream.

func (*TraceServerToClientStreamClientInterceptor[Info, Result]) TraceServerToClientStream

func (i *TraceServerToClientStreamClientInterceptor[Info, Result]) TraceServerToClientStream(ctx context.Context, info Info, next goa.Endpoint) (any, error)

TraceServerToClientStream intercepts a server to client stream by extracting the trace metadata from the streaming result. The extracted trace metadata is returned in the context of the receive method of the client stream.

type TraceServerToClientStreamServerInterceptor

type TraceServerToClientStreamServerInterceptor[Info ServerTraceStreamServerToClientInfo[Result], Result TraceStreamStreamingSendMessage] struct{}

TraceServerToClientStreamServerInterceptor is a server-side interceptor that traces a server to client stream by injecting the trace metadata into the streaming result. The injected trace metadata is returned in the context of the send method of the server stream.

func (*TraceServerToClientStreamServerInterceptor[Info, Result]) TraceServerToClientStream

func (i *TraceServerToClientStreamServerInterceptor[Info, Result]) TraceServerToClientStream(ctx context.Context, info Info, next goa.Endpoint) (any, error)

TraceServerToClientStream intercepts a server to client stream by injecting the trace metadata into the streaming result. The injected trace metadata is returned in the context of the send method of the server stream.

type TraceStreamStreamingRecvMessage

type TraceStreamStreamingRecvMessage interface {
	TraceMetadata() map[string]string
}

TraceStreamStreamingRecvMessage is an interface that matches the streaming receive payload or result for a stream that can be traced using TraceBidirectionalStreamClient, TraceServerToClientStreamClient, TraceBidirectionalStreamServer, or TraceClientToServerStreamServer.

type TraceStreamStreamingSendMessage

type TraceStreamStreamingSendMessage interface {
	SetTraceMetadata(map[string]string)
}

TraceStreamStreamingSendMessage is an interface that matches the streaming send payload or result for a stream that can be traced using TraceBidirectionalStreamClient, TraceClientToServerStreamClient, TraceBidirectionalStreamServer, or TraceServerToClientStreamServer.

type WrappedTraceStreamClientBidirectionalStream

type WrappedTraceStreamClientBidirectionalStream[Payload any, Result any] interface {
	// Send sends a payload on the wrapped client stream.
	Send(ctx context.Context, payload Payload) error
	// RecvAndReturnContext returns the context with the extracted trace metadata, payload or result, and error after
	// calling the receive method of the wrapped client stream.
	RecvAndReturnContext(ctx context.Context) (context.Context, Result, error)
	// Close closes the wrapped client stream.
	Close() error
}

WrappedTraceStreamClientBidirectionalStream is a wrapper around a client stream for a bidirectional stream that returns the context with the extracted trace metadata, payload or result, and error after calling the receive method of the stream.

func WrapTraceBidirectionalStreamClientStream

func WrapTraceBidirectionalStreamClientStream[Payload any, Result any](
	stream ClientBidirectionalStream[Payload, Result],
) WrappedTraceStreamClientBidirectionalStream[Payload, Result]

WrapTraceBidirectionalStreamClientStream wraps a client stream for a bidirectional stream with an interface that returns the context with the extracted trace metadata, payload or result, and error after calling the receive method of the stream.

type WrappedTraceStreamClientClientToServerStreamWithResult

type WrappedTraceStreamClientClientToServerStreamWithResult[Payload any, Result any] interface {
	// Send sends a payload on the wrapped client stream.
	Send(ctx context.Context, payload Payload) error
	// CloseAndRecvAndReturnContext returns the context with the extracted trace metadata, and result after
	// calling the close and receive methods of the wrapped client stream.
	CloseAndRecvAndReturnContext(ctx context.Context) (context.Context, Result, error)
}

WrappedTraceStreamClientClientToServerStreamWithResult is a wrapper around a client stream for a client to server stream that returns the context with the extracted trace metadata, and result after calling the close and receive methods of the stream.

func WrapTraceClientToServerStreamWithResultClientStream

func WrapTraceClientToServerStreamWithResultClientStream[Payload any, Result any](
	stream ClientClientToServerStreamWithResult[Payload, Result],
) WrappedTraceStreamClientClientToServerStreamWithResult[Payload, Result]

WrapTraceClientToServerStreamWithResultClientStream wraps a client stream for a client to server stream with an interface that returns the context with the extracted trace metadata, and result after calling the close and receive methods of the stream.

type WrappedTraceStreamClientServerToClientStream

type WrappedTraceStreamClientServerToClientStream[Result any] interface {
	// RecvAndReturnContext returns the context with the extracted trace metadata, and result after
	// calling the receive method of the wrapped client stream.
	RecvAndReturnContext(ctx context.Context) (context.Context, Result, error)
}

WrappedTraceStreamClientServerToClientStream is a wrapper around a client stream for a server to client stream that returns the context with the extracted trace metadata, and result after calling the receive method of the stream.

func WrapTraceServerToClientStreamClientStream

func WrapTraceServerToClientStreamClientStream[Result any](
	stream ClientServerToClientStream[Result],
) WrappedTraceStreamClientServerToClientStream[Result]

WrapTraceServerToClientStreamClientStream wraps a client stream for a server to client stream with an interface that returns the context with the extracted trace metadata, and result after calling the receive method of the stream.

type WrappedTraceStreamServerBidirectionalStream

type WrappedTraceStreamServerBidirectionalStream[Payload any, Result any] interface {
	// Send sends a payload on the wrapped server stream.
	Send(ctx context.Context, result Result) error
	// RecvAndReturnContext returns the context with the extracted trace metadata, payload or result, and error after
	// calling the receive method of the wrapped server stream.
	RecvAndReturnContext(ctx context.Context) (context.Context, Payload, error)
	// Close closes the wrapped server stream.
	Close() error
}

WrappedTraceStreamServerBidirectionalStream is a wrapper around a server stream for a bidirectional stream that returns the context with the extracted trace metadata, payload or result, and error after calling the receive method of the stream.

func WrapTraceBidirectionalStreamServerStream

func WrapTraceBidirectionalStreamServerStream[Payload any, Result any](
	stream ServerBidirectionalStream[Payload, Result],
) WrappedTraceStreamServerBidirectionalStream[Payload, Result]

WrapTraceBidirectionalStreamServerStream wraps a server stream for a bidirectional stream with an interface that returns the context with the extracted trace metadata, payload or result, and error after calling the receive method of the stream.

type WrappedTraceStreamServerClientToServerStream

type WrappedTraceStreamServerClientToServerStream[Payload any] interface {
	// RecvAndReturnContext returns the context with the extracted trace metadata, and payload after
	// calling the receive method of the wrapped server stream.
	RecvAndReturnContext(ctx context.Context) (context.Context, Payload, error)
	// Close closes the wrapped server stream.
	Close() error
}

WrappedTraceStreamServerClientToServerStream is a wrapper around a server stream for a client to server stream that returns the context with the extracted trace metadata, and payload after calling the receive method of the stream.

func WrapTraceClientToServerStreamServerStream

func WrapTraceClientToServerStreamServerStream[Payload any](
	stream ServerClientToServerStream[Payload],
) WrappedTraceStreamServerClientToServerStream[Payload]

WrapTraceClientToServerStreamServerStream wraps a server stream for a client to server stream with an interface that returns the context with the extracted trace metadata, and payload after calling the receive method of the stream.

type WrappedTraceStreamServerClientToServerStreamWithResult

type WrappedTraceStreamServerClientToServerStreamWithResult[Payload any, Result any] interface {
	// CloseAndSend closes the wrapped server stream and sends a result.
	CloseAndSend(ctx context.Context, result Result) error
	// RecvAndReturnContext returns the context with the extracted trace metadata, and payload after
	// calling the receive method of the wrapped server stream.
	RecvAndReturnContext(ctx context.Context) (context.Context, Payload, error)
}

WrappedTraceStreamServerClientToServerStreamWithResult is a wrapper around a server stream for a client to server stream that returns the context with the extracted trace metadata, and payload after calling the close and send methods of the stream.

func WrapTraceClientToServerStreamWithResultServerStream

func WrapTraceClientToServerStreamWithResultServerStream[Payload any, Result any](
	stream ServerClientToServerStreamWithResult[Payload, Result],
) WrappedTraceStreamServerClientToServerStreamWithResult[Payload, Result]

WrapTraceClientToServerStreamWithResultServerStream wraps a server stream for a client to server stream with an interface that returns the context with the extracted trace metadata, and payload after calling the close and send methods of the stream.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL