grpccorrelation

package
v0.0.0-...-23fd86d Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2020 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Example (Client)
package main

import (
	"log"

	grpccorrelation "gitlab.com/gitlab-org/labkit/correlation/grpc"
	"google.golang.org/grpc"
)

func main() {
	// Add the interceptor to the grpc dialer
	dialer, err := grpc.Dial("https://gitaly-server.internal:9095",
		grpc.WithStreamInterceptor(grpccorrelation.StreamClientCorrelationInterceptor(
			grpccorrelation.WithClientName("my-client"),
		)),
		grpc.WithUnaryInterceptor(grpccorrelation.UnaryClientCorrelationInterceptor(
			grpccorrelation.WithClientName("my-client"),
		)),
	)

	if err != nil {
		log.Fatalf("unable to dial: %v", err)
	}

	// Use the client connection with a protobuf service here...

	defer dialer.Close()
}
Output:

Example (Server)
package main

import (
	"log"
	"net"

	grpccorrelation "gitlab.com/gitlab-org/labkit/correlation/grpc"
	"google.golang.org/grpc"
)

func main() {
	server := grpc.NewServer(
		grpc.StreamInterceptor(grpccorrelation.StreamServerCorrelationInterceptor()),
		grpc.UnaryInterceptor(grpccorrelation.UnaryServerCorrelationInterceptor()),
	)

	listener, err := net.Listen("unix", "/tmp/grpc")
	if err != nil {
		log.Fatalf("unable to listen: %v", err)
	}

	server.Serve(listener)
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func InjectToOutgoingContext

func InjectToOutgoingContext(ctx context.Context, correlationID string) context.Context

InjectToOutgoingContext will inject the correlation ID into the outgoing context metadata. Repeat calls will overwrite any existing correlation IDs.

func StreamClientCorrelationInterceptor

func StreamClientCorrelationInterceptor(opts ...ClientCorrelationInterceptorOption) grpc.StreamClientInterceptor

StreamClientCorrelationInterceptor propagates Correlation-IDs downstream

func StreamServerCorrelationInterceptor

func StreamServerCorrelationInterceptor() grpc.StreamServerInterceptor

StreamServerCorrelationInterceptor propagates Correlation-IDs from incoming upstream services

func UnaryClientCorrelationInterceptor

func UnaryClientCorrelationInterceptor(opts ...ClientCorrelationInterceptorOption) grpc.UnaryClientInterceptor

UnaryClientCorrelationInterceptor propagates Correlation-IDs downstream

func UnaryServerCorrelationInterceptor

func UnaryServerCorrelationInterceptor() grpc.UnaryServerInterceptor

UnaryServerCorrelationInterceptor propagates Correlation-IDs from incoming upstream services

Types

type ClientCorrelationInterceptorOption

type ClientCorrelationInterceptorOption func(*clientInterceptConfig)

ClientCorrelationInterceptorOption will configure a correlation handler currently there are no options, but this gives us the option to extend the interface in a backwards compatible way

func WithClientName

func WithClientName(clientName string) ClientCorrelationInterceptorOption

WithClientName will configure the client name metadata on the GRPC client interceptors

Jump to

Keyboard shortcuts

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