rkgrpcctx

package
v1.2.11 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2021 License: Apache-2.0 Imports: 13 Imported by: 1

Documentation

Overview

Package rkgrpcctx provides utility functions deal with metadata in RPC context

Index

Constants

View Source
const (
	// RequestIdKey request id key in response header
	RequestIdKey = "X-Request-Id"
	// TraceIdKey trace id key in response header
	TraceIdKey = "X-Trace-Id"
)

Variables

This section is empty.

Functions

func AddHeaderToClient added in v1.2.0

func AddHeaderToClient(ctx context.Context, key, value string)

AddHeaderToClient Headers that would be sent to client.

func AddHeaderToServer added in v1.2.0

func AddHeaderToServer(ctx context.Context, key, value string)

AddHeaderToServer Headers that would be sent to server.

func EndTraceSpan added in v1.2.0

func EndTraceSpan(ctx context.Context, span trace.Span, success bool)

EndTraceSpan End span

func FinishClientStream added in v1.2.0

func FinishClientStream(ctx context.Context, stream grpc.ClientStream)

FinishClientStream This function is mainly used for client stream.

Streaming client is a little bit tricky. It is not an easy work to get headers sent from server while receiving message since client stream interceptor will finish before client start receiving message.

As a result, what event will log is the time before Recv() start to be called. No request id nor trace id would be logged since we are unable to call stream.Header() function which would be blocked until stream.Recv() has been called.

We believe it is not a good idea to wrap client stream or do anything tricky with stream.

If user hope to log request id and trace id into event, user need to call bellow function as soon as stream.Header() is ready. The downside is you will get multiple event logs with same event id.

func GetEntryName added in v1.2.0

func GetEntryName(ctx context.Context) string

GetEntryName Extract the call-scoped entry name.

func GetError added in v1.2.0

func GetError(ctx context.Context) error

GetError Extract the call-scoped error.

func GetEvent

func GetEvent(ctx context.Context) rkquery.Event

GetEvent Extract the call-scoped EventData from context.

func GetIncomingHeaders added in v1.2.0

func GetIncomingHeaders(ctx context.Context) metadata.MD

GetIncomingHeaders Extract call-scoped incoming headers

func GetLogger

func GetLogger(ctx context.Context) *zap.Logger

GetLogger Extract the call-scoped zap logger from context.

func GetMethodName added in v1.2.0

func GetMethodName(ctx context.Context) string

GetMethodName Extract the call-scoped method name.

func GetRequestId added in v1.2.0

func GetRequestId(ctx context.Context) string

GetRequestId Get request id in outgoing metadata.

func GetRpcType added in v1.2.0

func GetRpcType(ctx context.Context) string

GetRpcType Extract the call-scoped rpc type.

func GetTraceId added in v1.2.0

func GetTraceId(ctx context.Context) string

GetTraceId Get trace id in context.

func GetTraceSpan added in v1.2.0

func GetTraceSpan(ctx context.Context) trace.Span

GetTraceSpan Extract the call-scoped span from context.

func GetTracer added in v1.2.0

func GetTracer(ctx context.Context) trace.Tracer

GetTracer Extract the call-scoped tracer from context.

func GetTracerPropagator added in v1.2.0

func GetTracerPropagator(ctx context.Context) propagation.TextMapPropagator

GetTracerPropagator Extract the call-scoped span processor from middleware.

func GetTracerProvider added in v1.2.0

func GetTracerProvider(ctx context.Context) trace.TracerProvider

GetTracerProvider Extract the call-scoped tracer provider from context.

func InjectSpanToHttpRequest added in v1.2.0

func InjectSpanToHttpRequest(ctx context.Context, req *http.Request)

InjectSpanToHttpRequest Inject current trace information into http request

func InjectSpanToNewContext added in v1.2.0

func InjectSpanToNewContext(ctx context.Context) context.Context

InjectSpanToNewContext Inject current trace information into context

func NewTraceSpan added in v1.2.0

func NewTraceSpan(ctx context.Context, name string) trace.Span

NewTraceSpan Start a new span

func WrapContext added in v1.2.0

func WrapContext(ctx context.Context) context.Context

WrapContext We will add payload into context for further usage. Used for client side only.

Types

type GrpcMetadataCarrier added in v1.2.0

type GrpcMetadataCarrier struct {
	Md *metadata.MD
}

GrpcMetadataCarrier Grpc metadata carrier which will carries tracing info into grpc metadata to server side.

func (*GrpcMetadataCarrier) Get added in v1.2.0

func (carrier *GrpcMetadataCarrier) Get(key string) string

Get value with key from grpc metadata.

func (*GrpcMetadataCarrier) Keys added in v1.2.0

func (carrier *GrpcMetadataCarrier) Keys() []string

Keys List keys in grpc metadata.

func (*GrpcMetadataCarrier) Set added in v1.2.0

func (carrier *GrpcMetadataCarrier) Set(key string, value string)

Set value with key into grpc metadata.

type WrappedServerStream added in v1.2.0

type WrappedServerStream struct {
	grpc.ServerStream
	// WrappedContext is the wrapper's own Context. You can assign it.
	WrappedContext context.Context
}

WrappedServerStream is a thin wrapper around grpc.ServerStream that allows modifying context.

func WrapServerStream added in v1.2.0

func WrapServerStream(stream grpc.ServerStream) *WrappedServerStream

WrapServerStream returns a ServerStream that has the ability to overwrite context.

func (*WrappedServerStream) Context added in v1.2.0

func (w *WrappedServerStream) Context() context.Context

Context returns the wrapper's WrappedContext, overwriting the nested grpc.ServerStream.Context()

Jump to

Keyboard shortcuts

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