go.opencensus.iogo.opencensus.io/plugin/grpc/grpctrace Index | Examples | Files

package grpctrace

import "go.opencensus.io/plugin/grpc/grpctrace"

Package grpctrace is a package to assist with tracing incoming and outgoing gRPC requests.

Index

Examples

Types

type ClientStatsHandler

type ClientStatsHandler struct{}

ClientStatsHandler is a an implementation of grpc.StatsHandler that can be passed to grpc.Dial using grpc.WithStatsHandler to enable trace context propagation and automatic span creation for outgoing gRPC requests.

func NewClientStatsHandler

func NewClientStatsHandler() *ClientStatsHandler

NewClientStatsHandler returns a StatsHandler that can be passed to grpc.Dial using grpc.WithStatsHandler to enable trace context propagation and automatic span creation for outgoing gRPC requests.

Example

Code:play 

package main

import (
	"log"

	"go.opencensus.io/plugin/grpc/grpctrace"
	"google.golang.org/grpc"
)

func main() {
	// Set up a new client connection with the OpenCensus
	// stats handler to enable tracing for the outgoing requests.
	conn, err := grpc.Dial("address", grpc.WithStatsHandler(grpctrace.NewClientStatsHandler()))
	if err != nil {
		log.Fatalf("did not connect: %v", err)
	}
	defer conn.Close()
}

func (*ClientStatsHandler) HandleConn

func (c *ClientStatsHandler) HandleConn(ctx context.Context, cs stats.ConnStats)

HandleConn is a no-op for this StatsHandler.

func (*ClientStatsHandler) HandleRPC

func (c *ClientStatsHandler) HandleRPC(ctx context.Context, rs stats.RPCStats)

HandleRPC processes the RPC stats, adding information to the current trace span.

func (*ClientStatsHandler) TagConn

TagConn is a no-op for this StatsHandler.

func (*ClientStatsHandler) TagRPC

TagRPC creates a new trace span for the client side of the RPC.

It returns ctx with the new trace span added and a serialization of the SpanContext added to the outgoing gRPC metadata.

type ServerStatsHandler

type ServerStatsHandler struct{}

ServerStatsHandler is a an implementation of grpc.StatsHandler that can be passed to grpc.NewServer using grpc.StatsHandler to enable trace context propagation and automatic span creation for incoming gRPC requests..

func NewServerStatsHandler

func NewServerStatsHandler() *ServerStatsHandler

NewServerStatsHandler returns a StatsHandler that can be passed to grpc.NewServer using grpc.StatsHandler to enable trace context propagation and automatic span creation for incoming gRPC requests.

Example

Code:play 

package main

import (
	"go.opencensus.io/plugin/grpc/grpctrace"
	"google.golang.org/grpc"
)

func main() {
	// Set up a new client connection with the OpenCensus
	// stats handler to enable tracing for the incoming requests.
	s := grpc.NewServer(grpc.StatsHandler(grpctrace.NewServerStatsHandler()))
	_ = s // use s
}

func (*ServerStatsHandler) HandleConn

func (s *ServerStatsHandler) HandleConn(ctx context.Context, cs stats.ConnStats)

HandleConn is a no-op for this StatsHandler.

func (*ServerStatsHandler) HandleRPC

func (s *ServerStatsHandler) HandleRPC(ctx context.Context, rs stats.RPCStats)

HandleRPC processes the RPC stats, adding information to the current trace span.

func (*ServerStatsHandler) TagConn

TagConn is a no-op for this StatsHandler.

func (*ServerStatsHandler) TagRPC

TagRPC creates a new trace span for the server side of the RPC.

It checks the incoming gRPC metadata in ctx for a SpanContext, and if it finds one, uses that SpanContext as the parent context of the new span.

It returns ctx, with the new trace span added.

Source Files

grpc.go

Version
v0.1.0
Published
Dec 15, 2017
Platform
js/wasm
Imports
7 packages
Last checked
4 hours ago

Tools for package owners.