Source File
trace_common.go
Belonging Package
go.opencensus.io/plugin/ocgrpc
package ocgrpc
import (
)
const traceContextKey = "grpc-trace-bin"
func ( *ClientHandler) ( context.Context, *stats.RPCTagInfo) context.Context {
:= strings.TrimPrefix(.FullMethodName, "/")
= strings.Replace(, "/", ".", -1)
, := trace.StartSpan(, ,
trace.WithSampler(.StartOptions.Sampler),
trace.WithSpanKind(trace.SpanKindClient)) // span is ended by traceHandleRPC
:= propagation.Binary(.SpanContext())
return metadata.AppendToOutgoingContext(, traceContextKey, string())
}
func ( *ServerHandler) ( context.Context, *stats.RPCTagInfo) context.Context {
, := metadata.FromIncomingContext()
:= strings.TrimPrefix(.FullMethodName, "/")
= strings.Replace(, "/", ".", -1)
:= [traceContextKey]
var (
trace.SpanContext
bool
)
:= []byte([0])
, = propagation.FromBinary()
if && !.IsPublicEndpoint {
, := trace.StartSpanWithRemoteParent(, , ,
trace.WithSpanKind(trace.SpanKindServer),
trace.WithSampler(.StartOptions.Sampler),
)
return
}
}
, := trace.StartSpan(, ,
trace.WithSpanKind(trace.SpanKindServer),
trace.WithSampler(.StartOptions.Sampler))
if {
.AddLink(trace.Link{TraceID: .TraceID, SpanID: .SpanID, Type: trace.LinkTypeChild})
}
return
}
func ( context.Context, stats.RPCStats) {
switch rs := .(type) {
case *stats.Begin:
.AddAttributes(
trace.BoolAttribute("Client", .Client),
trace.BoolAttribute("FailFast", .FailFast))
case *stats.InPayload:
.AddMessageReceiveEvent(0 /* TODO: messageID */, int64(.Length), int64(.WireLength))
case *stats.OutPayload:
.AddMessageSendEvent(0, int64(.Length), int64(.WireLength))
case *stats.End:
if .Error != nil {
, := status.FromError(.Error)
if {
.SetStatus(trace.Status{Code: int32(.Code()), Message: .Message()})
} else {
.SetStatus(trace.Status{Code: int32(codes.Internal), Message: .Error.Error()})
}
}
.End()
}
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin 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 @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |