grpccorrelation

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: May 20, 2021 License: MIT Imports: 5 Imported by: 11

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(opts ...ServerCorrelationInterceptorOption) 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(opts ...ServerCorrelationInterceptorOption) grpc.UnaryServerInterceptor

UnaryServerCorrelationInterceptor propagates Correlation-IDs from incoming upstream services.

Types

type ClientCorrelationInterceptorOption

type ClientCorrelationInterceptorOption func(*clientInterceptConfig)

ClientCorrelationInterceptorOption configures client correlation interceptors.

func WithClientName

func WithClientName(clientName string) ClientCorrelationInterceptorOption

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

type ServerCorrelationInterceptorOption

type ServerCorrelationInterceptorOption func(*serverInterceptConfig)

ServerCorrelationInterceptorOption configures server correlation interceptor.

func WithoutPropagation

func WithoutPropagation() ServerCorrelationInterceptorOption

WithoutPropagation disables correlation id propagation from incoming request metadata. If the id is missing or the interceptor is configured to not propagate it, a new id is generated and injected into the request context.

Jump to

Keyboard shortcuts

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