otelgrpc

package
v0.0.0-...-95754d6 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2021 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func TracingClientInterceptor

func TracingClientInterceptor(optFuncs ...Option) grpc.UnaryClientInterceptor

TracingClientInterceptor returns a grpc.UnaryClientInterceptor suitable for use in a grpc.Dial call.

All gRPC client spans will inject the OpenTracing SpanContext into the gRPC metadata; they will also look in the context.Context for an active in-process parent Span and establish a ChildOf reference if such a parent Span could be found.

Example
package main

import (
	"google.golang.org/grpc"

	otelgrpc "github.com/yeqown/opentelemetry-quake/x/grpc"
)

func main() {
	address := "dns:///xxx"

	conn, err := grpc.Dial(
		address,
		grpc.WithUnaryInterceptor(otelgrpc.TracingClientInterceptor(otelgrpc.LogPayloads())),
	)

	_, _ = conn, err
}
Output:

func TracingServerInterceptor

func TracingServerInterceptor(optFuncs ...Option) grpc.UnaryServerInterceptor

TracingServerInterceptor returns a grpc.UnaryServerInterceptor suitable for use in a grpc.NewServer call.

All gRPC server spans will look for an OpenTracing SpanContext in the gRPC metadata; if found, the server span will act as the ChildOf that RPC SpanContext.

Root or not, the server Span will be embedded in the context.Context for the application-specific gRPC handler(s) to access.

Example
package main

import (
	"google.golang.org/grpc"

	otelgrpc "github.com/yeqown/opentelemetry-quake/x/grpc"
)

func main() {
	s := grpc.NewServer(
		grpc.UnaryInterceptor(otelgrpc.TracingServerInterceptor(
			otelgrpc.LogPayloads(),
		)),
	)

	_ = s
}
Output:

Types

type Class

type Class string

A Class is a set of types of outcomes (including errors) that will often be handled in the same way.

const (
	Unknown Class = "0xx"
	// Success represents outcomes that achieved the desired results.
	Success Class = "2xx"
	// ClientError represents errors that were the client's fault.
	ClientError Class = "4xx"
	// ServerError represents errors that were the server's fault.
	ServerError Class = "5xx"
)

func ErrorClass

func ErrorClass(err error) Class

ErrorClass returns the class of the given error

type Option

type Option func(o *options)

Option instances may be used in OpenTracing(Server|Client)Interceptor initialization.

See this post about the "functional options" pattern: http://dave.cheney.net/2014/10/17/functional-options-for-friendly-apis

func LogPayloads

func LogPayloads() Option

LogPayloads returns an Option that tells the OpenTracing instrumentation to try to log application payloads in both directions.

Jump to

Keyboard shortcuts

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