/* * * Copyright 2015 gRPC authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */package grpcimport ()// EnableTracing controls whether to trace RPCs using the golang.org/x/net/trace package.// This should only be set before any RPCs are sent or received by this program.varEnableTracingbool// methodFamily returns the trace family for the given method.// It turns "/pkg.Service/GetFoo" into "pkg.Service".func methodFamily( string) string { = strings.TrimPrefix(, "/") // remove leading slashif := strings.Index(, "/"); >= 0 { = [:] // remove everything from second slash }return}// traceEventLog mirrors golang.org/x/net/trace.EventLog.//// It exists in order to avoid importing x/net/trace on grpcnotrace builds.type traceEventLog interface { Printf(format string, a ...any) Errorf(format string, a ...any) Finish()}// traceLog mirrors golang.org/x/net/trace.Trace.//// It exists in order to avoid importing x/net/trace on grpcnotrace builds.type traceLog interface { LazyLog(x fmt.Stringer, sensitive bool) LazyPrintf(format string, a ...any) SetError() SetRecycler(f func(any)) SetTraceInfo(traceID, spanID uint64) SetMaxEvents(m int) Finish()}// traceInfo contains tracing information for an RPC.type traceInfo struct { tr traceLog firstLine firstLine}// firstLine is the first line of an RPC trace.// It may be mutated after construction; remoteAddr specifically may change// during client-side use.type firstLine struct { mu sync.Mutex client bool// whether this is a client (outgoing) RPC remoteAddr net.Addr deadline time.Duration// may be zero}func ( *firstLine) ( net.Addr) { .mu.Lock() .remoteAddr = .mu.Unlock()}func ( *firstLine) () string { .mu.Lock()defer .mu.Unlock()varbytes.Bufferio.WriteString(&, "RPC: ")if .client {io.WriteString(&, "to") } else {io.WriteString(&, "from") }fmt.Fprintf(&, " %v deadline:", .remoteAddr)if .deadline != 0 {fmt.Fprint(&, .deadline) } else {io.WriteString(&, "none") }return .String()}const truncateSize = 100func truncate( string, int) string {if > len() {return }return [:]}// payload represents an RPC request or response payload.type payload struct { sent bool// whether this is an outgoing payload msg any// e.g. a proto.Message// TODO(dsymonds): add stringifying info to codec, and limit how much we hold here?}func ( payload) () string {if .sent {returntruncate(fmt.Sprintf("sent: %v", .msg), truncateSize) }returntruncate(fmt.Sprintf("recv: %v", .msg), truncateSize)}type fmtStringer struct { format string a []any}func ( *fmtStringer) () string {returnfmt.Sprintf(.format, .a...)}type stringer stringfunc ( stringer) () string { returnstring() }
The pages are generated with Goldsv0.8.2. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.