grpc

package module
v2.0.0-beta.11 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2024 License: Apache-2.0, BSD-3-Clause Imports: 24 Imported by: 0

Documentation

Overview

Package grpc provides functions to trace the google.golang.org/grpc package v1.2.

Example (Client)
package main

import (
	"log"

	grpctrace "github.com/DataDog/dd-trace-go/contrib/google.golang.org/grpc/v2"

	"google.golang.org/grpc"
)

func main() {
	// Create the client interceptor using the grpc trace package.
	si := grpctrace.StreamClientInterceptor(grpctrace.WithService("my-grpc-client"))
	ui := grpctrace.UnaryClientInterceptor(grpctrace.WithService("my-grpc-client"))

	// Dial in using the created interceptor.
	// Note: To use multiple UnaryInterceptors with grpc.Dial, you must use
	// grpc.WithChainUnaryInterceptor instead (as of google.golang.org/grpc v1.51.0).
	conn, err := grpc.Dial("localhost:50051", grpc.WithInsecure(),
		grpc.WithStreamInterceptor(si), grpc.WithUnaryInterceptor(ui))
	if err != nil {
		log.Fatal(err)
	}
	defer conn.Close()

	// And continue using the connection as normal.
}
Output:

Example (Server)
package main

import (
	"log"
	"net"

	grpctrace "github.com/DataDog/dd-trace-go/contrib/google.golang.org/grpc/v2"

	"google.golang.org/grpc"
)

func main() {
	// Create a listener for the server.
	ln, err := net.Listen("tcp", ":50051")
	if err != nil {
		log.Fatal(err)
	}

	// Create the server interceptor using the grpc trace package.
	si := grpctrace.StreamServerInterceptor(grpctrace.WithService("my-grpc-server"))
	ui := grpctrace.UnaryServerInterceptor(grpctrace.WithService("my-grpc-server"))

	// Initialize the grpc server as normal, using the tracing interceptor.
	s := grpc.NewServer(grpc.StreamInterceptor(si), grpc.UnaryInterceptor(ui))

	// ... register your services

	// Start serving incoming connections.
	if err := s.Serve(ln); err != nil {
		log.Fatalf("failed to serve: %v", err)
	}
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewClientStatsHandler

func NewClientStatsHandler(opts ...Option) stats.Handler

NewClientStatsHandler returns a gRPC client stats.Handler to trace RPC calls.

func NewServerStatsHandler

func NewServerStatsHandler(opts ...Option) stats.Handler

NewServerStatsHandler returns a gRPC server stats.Handler to trace RPC calls.

func StreamClientInterceptor

func StreamClientInterceptor(opts ...Option) grpc.StreamClientInterceptor

StreamClientInterceptor returns a grpc.StreamClientInterceptor which will trace client streams using the given set of options.

func StreamServerInterceptor

func StreamServerInterceptor(opts ...Option) grpc.StreamServerInterceptor

StreamServerInterceptor will trace streaming requests to the given gRPC server.

func UnaryClientInterceptor

func UnaryClientInterceptor(opts ...Option) grpc.UnaryClientInterceptor

UnaryClientInterceptor returns a grpc.UnaryClientInterceptor which will trace requests using the given set of options.

func UnaryServerInterceptor

func UnaryServerInterceptor(opts ...Option) grpc.UnaryServerInterceptor

UnaryServerInterceptor will trace requests to the given grpc server.

Types

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option describes options for the gRPC integration.

type OptionFn

type OptionFn func(*config)

OptionFn represents options applicable to StreamClientInterceptor, UnaryClientInterceptor, StreamServerInterceptor, UnaryServerInterceptor, NewClientStatsHandler and NewServerStatsHandler.

func NoDebugStack

func NoDebugStack() OptionFn

NoDebugStack disables debug stacks for traces with errors. This is useful in situations where errors are frequent, and the overhead of calling debug.Stack may affect performance.

func NonErrorCodes

func NonErrorCodes(cs ...codes.Code) OptionFn

NonErrorCodes determines the list of codes that will not be considered errors in instrumentation. This call overrides the default handling of codes.Canceled as a non-error.

func WithAnalytics

func WithAnalytics(on bool) OptionFn

WithAnalytics enables Trace Analytics for all started spans.

func WithAnalyticsRate

func WithAnalyticsRate(rate float64) OptionFn

WithAnalyticsRate sets the sampling rate for Trace Analytics events correlated to started spans.

func WithCustomTag

func WithCustomTag(key string, value interface{}) OptionFn

WithCustomTag will attach the value to the span tagged by the key.

func WithErrorDetailTags

func WithErrorDetailTags() OptionFn

WithErrorDetailTags specifies whether gRPC responses details contain should be added to spans as tags.

func WithIgnoredMetadata

func WithIgnoredMetadata(ms ...string) OptionFn

WithIgnoredMetadata specifies keys to be ignored while tracing the metadata. Must be used in conjunction with WithMetadataTags.

func WithMetadataTags

func WithMetadataTags() OptionFn

WithMetadataTags specifies whether gRPC metadata should be added to spans as tags.

func WithRequestTags

func WithRequestTags() OptionFn

WithRequestTags specifies whether gRPC requests should be added to spans as tags.

func WithService

func WithService(name string) OptionFn

WithService sets the given service name for the intercepted client.

func WithSpanOptions

func WithSpanOptions(opts ...tracer.StartSpanOption) OptionFn

WithSpanOptions defines a set of additional tracer.StartSpanOption to be added to spans started by the integration.

func WithStreamCalls

func WithStreamCalls(enabled bool) OptionFn

WithStreamCalls enables or disables tracing of streaming calls. This option does not apply to the stats handler.

func WithStreamMessages

func WithStreamMessages(enabled bool) OptionFn

WithStreamMessages enables or disables tracing of streaming messages. This option does not apply to the stats handler.

func WithUntracedMethods

func WithUntracedMethods(ms ...string) OptionFn

WithUntracedMethods specifies full methods to be ignored by the server side and client side interceptors. When a request's full method is in ms, no spans will be created.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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