Documentation
¶
Overview ¶
Package requestid is a grpc middleware for keeping track of chained requests and calls within a transaction.
The package is using on github.com/grpc-ecosystem/go-grpc-middleware/tags
Example ¶
package main
import (
grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
grpc_ctxtags "github.com/grpc-ecosystem/go-grpc-middleware/tags"
"google.golang.org/grpc"
"github.com/SKF/go-utility/grpc-interceptor/requestid"
)
func main() {
_ = grpc.NewServer(
grpc.StreamInterceptor(grpc_middleware.ChainStreamServer(
grpc_ctxtags.StreamServerInterceptor(),
requestid.StreamServerInterceptor("LOG_NAME"),
)),
grpc.UnaryInterceptor(grpc_middleware.ChainUnaryServer(
grpc_ctxtags.UnaryServerInterceptor(),
requestid.UnaryServerInterceptor("LOG_NAME"),
)),
)
}
Index ¶
- Constants
- func ExtendContext(ctx context.Context, serviceName string) context.Context
- func StreamClientInterceptor(serviceName string) grpc.StreamClientInterceptor
- func StreamServerInterceptor(serviceName string) grpc.StreamServerInterceptor
- func UnaryClientInterceptor(serviceName string) grpc.UnaryClientInterceptor
- func UnaryServerInterceptor(serviceName string) grpc.UnaryServerInterceptor
- type Request
Examples ¶
Constants ¶
const REQUEST_CHAIN_KEY = "request.chain"
const REQUEST_ID_KEY = "request.id"
const REQUEST_TRANSACTION_ID_KEY = "request.transaction.id"
Variables ¶
This section is empty.
Functions ¶
func ExtendContext ¶ added in v1.1.0
ExtendContext extends the context with a Request ID Metadata.
Example ¶
package main
import (
"context"
"github.com/SKF/go-utility/grpc-interceptor/requestid"
)
func main() {
outgoingGrpcCallContext := context.Background()
requestid.ExtendContext(outgoingGrpcCallContext, "Example")
}
func StreamClientInterceptor ¶ added in v1.1.0
func StreamClientInterceptor(serviceName string) grpc.StreamClientInterceptor
StreamClientInterceptor returns a new streaming client interceptor that adds the Request ID Metadata to the call.
func StreamServerInterceptor ¶
func StreamServerInterceptor(serviceName string) grpc.StreamServerInterceptor
StreamServerInterceptor returns a new streaming server interceptor that adds the Request ID Metadata to the call.
func UnaryClientInterceptor ¶ added in v1.1.0
func UnaryClientInterceptor(serviceName string) grpc.UnaryClientInterceptor
UnaryClientInterceptor returns a new unary client interceptor that adds the Request ID Metadata to the call.
func UnaryServerInterceptor ¶
func UnaryServerInterceptor(serviceName string) grpc.UnaryServerInterceptor
UnaryServerInterceptor returns a new unary server interceptor that adds the Request ID Metadata to the call.
Types ¶
type Request ¶
type Request struct {
ID uuid.UUID `json:"id"`
Chain []string `json:"chain"`
TransactionID uuid.UUID `json:"transactionId"`
}
Request is a data holder for the different Request ID Metadata
func Extract ¶
Extract will get the Request ID Metadata out of the context.
Example ¶
package main
import (
"context"
"github.com/SKF/go-utility/grpc-interceptor/requestid"
"github.com/SKF/go-utility/log"
)
func main() {
var grpcCallContext context.Context
log.WithField("request", requestid.Extract(grpcCallContext)).
Infof("Request ID Metadata")
}