package grpctraces

Import Path
	go.pact.im/x/traces/grpctraces (on go.dev)

Dependency Relation
	imports 10 packages, and imported by one package

Involved Source Files Package grpctraces provides [stats.Handler] instrumentation for gRPC clients and servers using [traces.Tracer]. handler.go status.go
Code Examples package main import ( "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" "go.pact.im/x/traces" "go.pact.im/x/traces/grpctraces" ) func main() { tr := traces.New(traces.DiscardHandler()) conn, _ := grpc.NewClient("example.com:443", grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithStatsHandler(grpctraces.NewClientHandler(tr)), ) _ = conn } package main import ( "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" "go.pact.im/x/traces" "go.pact.im/x/traces/grpctraces" "go.pact.im/x/traces/traceparent" ) func main() { tr := traces.New(traces.DiscardHandler()) conn, _ := grpc.NewClient("users.internal:9090", grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithStatsHandler(grpctraces.NewClientHandler(tr).WithInject(traceparent.Inject)), ) _ = conn } package main import ( "google.golang.org/grpc" "go.pact.im/x/traces" "go.pact.im/x/traces/grpctraces" "go.pact.im/x/traces/traceparent" ) func main() { tr := traces.New(traces.DiscardHandler()).WithSampler(traces.ParentBased(traces.Ratio(0.1))) srv := grpc.NewServer( grpc.StatsHandler(grpctraces.NewServerHandler(tr).WithExtract(traceparent.Extract)), ) _ = srv } package main import ( "google.golang.org/grpc" "go.pact.im/x/traces" "go.pact.im/x/traces/grpctraces" ) func main() { tr := traces.New(traces.DiscardHandler()).WithSampler(traces.ParentBased(traces.Ratio(0.1))) srv := grpc.NewServer( grpc.StatsHandler(grpctraces.NewServerHandler(tr)), ) _ = srv }
Package-Level Type Names (total 2, in which 1 is exported)
/* sort exporteds by: | */
Handler implements the [stats.Handler] interface for gRPC clients and servers. HandleConn implements the [stats.Handler] interface. HandleRPC implements the [stats.Handler] interface, finishing the span on [stats.End]. TagConn implements the [stats.Handler] interface. TagRPC implements the [stats.Handler] interface. WithAttrs returns a [Handler] using f to attach additional start-time attributes for each RPC. If f is nil, only default attributes are added. WithExtract returns a [Handler] using f to extract the parent [traces.SpanRef] from incoming metadata (for example [traceparent.Extract]). If f is nil, incoming metadata is ignored. WithFilter returns a [Handler] that only traces RPCs for which f returns true. Filtered-out RPCs do not create spans or inject trace metadata. If f is nil, all RPCs are traced. WithInject returns a [Handler] using f to inject [traces.SpanRef] into outgoing metadata (for example [traceparent.Inject]). If f is nil, no trace metadata is injected. WithSpanName returns a [Handler] using f to compute the span name from the RPC tag info. If f is nil, it restores using rpc.method (falling back to "grpc"). *Handler : google.golang.org/grpc/stats.Handler func NewClientHandler(tr *traces.Tracer) *Handler func NewServerHandler(tr *traces.Tracer) *Handler func (*Handler).WithAttrs(f func(ctx context.Context, info *stats.RPCTagInfo) []traces.Attr) *Handler func (*Handler).WithExtract(f func(get func(key string) []string) traces.SpanRef) *Handler func (*Handler).WithFilter(f func(ctx context.Context, info *stats.RPCTagInfo) bool) *Handler func (*Handler).WithInject(f func(ref traces.SpanRef, set func(key, value string))) *Handler func (*Handler).WithSpanName(f func(ctx context.Context, info *stats.RPCTagInfo) string) *Handler
Package-Level Functions (total 5, in which 2 are exported)
NewClientHandler returns a new [Handler] instance for tracing outgoing gRPC RPCs. Outgoing metadata is not modified by default; call [Handler.WithInject] to opt in to trace context injection.
NewServerHandler returns a new [Handler] instance for tracing incoming gRPC RPCs. Incoming metadata is ignored by default; call [Handler.WithExtract] to opt in to trace context extraction.
Package-Level Constants (total 11, none are exported)